1. ## Clipping despite translation

Hi all,

I've got some rectangles that appear just in front of a bigger rectangle, so their Z values are very slightly more negative.
When I positioning each rectangle that is in front of the bigger rectangle, I use a translation. I may also do a rotation in future.
What I'm trying to figure out how to do is how can I clip in 3-D the smaller rectangles so that no part of than ever appears outside of the bigger rectangle that is behind them?

This is how things are now:
rect.jpg

This is how I want to clip:
rect2.jpg

I've tried using glClipPlane but so far, no luck. What I'm doing:
* Draw larger rectangle.
* Set 4 clipping planes based on corners of larger rectangle for top/bottom/left/right.
* Draw each smaller rectangle using
- glPushMatrix
- glTranslate
- glRotate optionally
- glBindTexture
- glTexCoord2d & glVertex3d
- glEnd
- glPopMatrix
* Clear the 4 clipping planes.

Thanks.

2. Depending upon what you want to do, scissoring (glScissor) may be preferable to geometric clipping. Or stencilling.

Regarding geometric clipping:

* The clip planes are specified in object coordinates but transformed using the current model-view matrix (current at the time of the glClipPlane() call) and stored in eye coordinates.

* As well as specifying the plane coefficients, each plane must be enabled with glEnable(GL_CLIP_PLANE0) etc.

Points inside the clipping region are those for which
Code :
`p1*x + p2*y + p3*z + p4*w >= 0`

Thus, the planes should probably be:
Code :
```GLdouble planes[4][4] = {
{ 1,  0, 0, -x_left},
{-1,  0, 0,  x_right},
{ 0,  1, 0, -y_bottom},
{ 0, -1, 0,  y_top}
};```

where x_left, x_right, y_bottom and y_top are the actual values used for the rectangle's vertices, and the model-view matrix is unchanged between the drawing of the rectangle and the glClipPlane() calls.

3. Originally Posted by GClements
....
where x_left, x_right, y_bottom and y_top are the actual values used for the rectangle's vertices, and the model-view matrix is unchanged between the drawing of the rectangle and the glClipPlane() calls.
Thanks, that works now for x and y directions.

However there is a glitch. When I rotate the containing (clipping) rectangle, the clipping planes don't also rotate.
This is not a big deal since I don't plan to rotate them but I wonder how that could be accomplished...

4. Originally Posted by question2
When I rotate the containing (clipping) rectangle, the clipping planes don't also rotate.
Assuming that you're rotating the rectangle via the model-view matrix (e.g. glRotate), you should just need to call glClipPlane() while that transformation is still in effect (e.g. before calling glPopMatrix).

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•