Results 1 to 4 of 4

Thread: Clipping despite translation

  1. #1
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    20

    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
    - glBegin quads
    - glBindTexture
    - glTexCoord2d & glVertex3d
    - glEnd
    - glPopMatrix
    * Clear the 4 clipping planes.

    Thanks.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    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. #3
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    20
    Quote Originally Posted by GClements View Post
    ....
    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. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by question2 View Post
    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).

Similar Threads

  1. Translation
    By Kurtishome in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-16-2013, 10:18 PM
  2. Replies: 1
    Last Post: 09-02-2003, 01:45 PM
  3. clipping plane translation
    By andrewt in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-20-2002, 05:10 PM
  4. Clipping (not clipping) in opengl
    By FunkyLovin in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 06-04-2001, 05:08 AM
  5. translation
    By lee in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-23-2000, 09:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean