additional clip planes

Started by
-1 comments, last by coordz 16 years, 9 months ago
I'd like to add an additional clip plane for debugging purposes. This is how I'm going things now:

//
// set up my camera as per usual here
//
// .......

//
// set up clipping plane
//
GLdouble eqn[4] = {0.0f, 0.0f, 1.0f, 0.0f};
glPushMatrix();
glTranslatef(objPos[0], objPos[1], objPos[2]);
glRotatef(objAngle[0], 1, 0, 0);
glRotatef(objAngle[1], 0, 1, 0);
glRotatef(objAngle[2], 0, 0, 1);
glClipPlane(GL_CLIP_PLANE0, eqn);
glPopMatrix();
glEnable(GL_CLIP_PLANE0);

// draw the scene
glPushMatrix();
glRotatef(myAngle, 1, 0, 0);
drawCube();
glPopMatrix();

// done with clipping plane
glDisable(GL_CLIP_PLANE0);

//
// draw the clipping plane so I can see where it is
//
glPushMatrix();
glTranslatef(objPos[0], objPos[1], objPos[2]);
glRotatef(objAngle[0], 1, 0, 0);
glRotatef(objAngle[1], 0, 1, 0);
glRotatef(objAngle[2], 0, 0, 1);
glColor4f( 0.0, 1.0, 0.0, 1.0);
glBegin(GL_LINE_LOOP);
  glVertex3f(1.0, -1.0, 0.0);
  glVertex3f(-1.0, -1.0, 0.0);			
  glVertex3f(-1.0, 1.0, 0.0);
  glVertex3f(1.0, 1.0, 0.0);		
glEnd();
glBegin(GL_LINES);
  glVertex3f(1.0, -1.0, 0.0);
  glVertex3f(-1.0, 1.0, 0.0);
  glVertex3f(-1.0, -1.0, 0.0);			
  glVertex3f(1.0, 1.0, 0.0);		
glEnd();
glPopMatrix();

For testing purposes drawScene() just draws a rotating cube. Glancing at my Red book I see that the clipping plane coeffs are multiplied by the inverse of the "current modelview matrix at the time glClipPlane() is called". So I reckon the clipping plane should stay still as my cube rotates and that the plane (okay, square) that I draw in green matches the position of the clipping plane. This doesn't seem to be the case. While fiddling around with objPos and objAngle changes the position of the clip plane, so does the rotation applied to the cube, i.e. the clip plane rotates with the cube. So what's wrong? Where do I put the call to glClipPlane() for the desired result? TIA

This topic is closed to new replies.

Advertisement