Help with glClipPlane needed

Edit: Any help, even just sites to visit or better ways of getting the plane equation would be appreciated. I am getting quite desperate as this has held me up for three days! Tia

Hi all,

I am struggling like crazy here to get the glClipPlane working.I have been trawling the net for the last 3 days looking for help.

I think I understand all the maths behind the plane equation. (Check out http://nate.scuzzy.net/docs/normals/ and http://mathworld.wolfram.com if you are looking for help on this)

This is what I have. I create two GL_QUAD_STRIPS to make a cube. The vertices of this cube are as follows.

First strip

<code>
(1,1,1) (1,1,-1) (-1,1,1) (-1,1,-1)
(-1,-1,1) (-1,-1,-1)
(1,-1,1) (1,-1,-1)
</code>

Second Strip
<code>
(-1,1,1) (-1,-1,1) (1,1,1) (1,-1,1)
(1,1,-1) (1,-1,-1)
(-1,1,-1) (-1,-1,-1)
</code>

I then placed a point inside the cube at 0.5,0.5,0.5

I would like to clip the six panes to see this point. I have done the following for the top pane.

Let A=(1,1,1) Let B=(1,1,-1) Let C=(-1,1,-1)

Then A-B = (0,0,-2) C-B=(-2,0,0)
Then AxB = 0i + 4j + 0k
0i+4j+0k+D = 0 (plane equation)
To normalise this vector I divide by its legnth which is 4 Thus the normalised vector is (0,1,0)
Substitute in point C
D = -1

Thus I use the following point to pass to glClipRegion. (0,1,0,-1). I just can’t see this clipregion working. Below is my code as it may be something wrong with it as well. Note I have raise the top quad (red) 0.5 pixels just in case it was falling into the region that is visible. If you look carefully while rotating the object you can see the litle yellow dot inside. There is also a second clip region which also doesn’t work.
<code>
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
gluLookAt(0,0,0,0,0,1,0,1,0);
glPushMatrix();
glTranslatef(GLfloat(0.0f),GLfloat(0.0f),GLfloat(5.0));
glRotatef(rotatey,1,0,0);
glRotatef(rotatex,0,1,0);
glBegin(GL_QUAD_STRIP);

  //top strip
  GLdouble plane0 [] ={0,1,0,-1};
  glClipPlane(GL_CLIP_PLANE0,plane0);
  glEnable (GL_CLIP_PLANE0);
  glColor3f(1.0f,0.0f,0.0f);
  glVertex3f(1.0f,1.5f,1.0f);
  glVertex3f(1.0f,1.5f,-1.0f);      
  glVertex3f(-1.0f,1.5f,1.0f);
  glVertex3f(-1.0f,1.5f,-1.0f);
  glDisable(GL_CLIP_PLANE0);

  GLdouble plane1[]={-1,0,0,1};
  glClipPlane(GL_CLIP_PLANE1,plane1);
  glEnable(GL_CLIP_PLANE1);
  glColor3f(0.0,1.0,0);   
  glVertex3f(-1.0f,-1.0f,1.0f);
  glVertex3f(-1.0f,-1.0f,-1.0f);

   glColor3f(0.0f,0.0f,1.0f);
  glVertex3f(1.0f,-1.0f,1.0f);
  glVertex3f(1.0f,-1.0f,-1.0f);
         
  glDisable(GL_CLIP_PLANE1);
  glEnd();
  glPopMatrix();


   glPushMatrix();
   glTranslatef(GLfloat(0.0f),GLfloat(0.0f),GLfloat(5.0));
   glRotatef(rotatey,1,0,0);
   glRotatef(rotatex,0,1,0);
   glBegin(GL_QUAD_STRIP);

  glColor3f(0.26f,0.23f,0.0f);
  glVertex3f(-1.0f,1.0f,1.0f);
  glVertex3f(-1.0f,-1.0f,1.0f);
  glVertex3f(1.0f,1.0f,1.0f);      
  glVertex3f(1.0f,-1.0f,1.0f);

  glColor3f(0.23,1.0,23);   
  glVertex3f(1.0f,1.0f,-1.0f);
  glVertex3f(1.0f,-1.0f,-1.0f);


   glColor3f(0.5f,0.5f,1.0f);
  glVertex3f(-1.0f,1.0f,-1.0f);
  glVertex3f(-1.0f,-1.0f,-1.0f);
         
  glEnd();
  glPopMatrix();
  
   glPushMatrix();
   glTranslatef(GLfloat(0.0f),GLfloat(0.0f),GLfloat(5.0));
   glRotatef(rotatey,1,0,0);
   glRotatef(rotatex,0,1,0);
   glPointSize(2);
  glBegin(GL_POINTS);
  glColor3f(1.0f,1.0f,0.0f);
  glVertex3f(0.5f,0.5f,0.5f);
    glEnd();
  glPopMatrix();
  
  glutSwapBuffers();
   glFlush();

</code>

[This message has been edited by mxc (edited 06-11-2003).]

It may happen, that your plane clip the wrong side.
Try to negate your plane vector.