title: how to get the near clipping plane coordinates in object space coordinate in OpenGL
body: <p>I am rendering a cube with 8 vertices. As I rotate or get closer to the cube, some vertices might be clipped by the near clipping plane. However, for some reason in my problem I need to find the intersection points on the edges of the cube with the near clipping plane. I know the number of points may vary. So what I thought was to get the near clipping plane (probably in eye space - but HOW?) and do some inverse calculation of matrices to get the coordinates in my cube's object space, then I can find the intersections and solve my problem. But the problem here is:</p>
  
  <ol>
  <li>How do I get the coordinates for each corner of the near clipping plane? (or the plane equation coefficients)</li>
  <li>How do I go back to object space?</li>
  </ol>
  
  <p>Test:</p>
  
  <p>As a test to see if I can get the coordinates correctly I tried this:
  What I tried to do was to get the inverse of MVM (ModelView Matrix) and PM (Projection Matrix). And tried to imagine the near clipping plane having V1 = (-1,-1,-1,1), V2 = (1, -1, -1, 1), V3 = (1, 1, -1, 1), and V4 = (-1, 1, -1, 1) coordinates. So I was thinking if I do this for each of the four vertices:</p>
  
  <p>V1 = IMVM * ( IPM * V1 );</p>
  
  <p>V2 = IMVM * ( IPM * V2 );</p>
  
  <p>V3 = IMVM * ( IPM * V3 );</p>
  
  <p>V4 = IMVM * ( IPM * V4 );</p>
  
  <p>where IMVM is the Inverse of Model-View Matrix and IPM is the Inverse of Projection Matrix.
  Then I when I render these four points with currently loaded matrices (that I just used the inverse of), I should get a standing sill square in front of my screen since my inverse multiplications should have been cancelled by the multiplication with openGL's currently loaded matrices. But for some reason it does not work and I tried transposed and normal. I paid attention to being column major, etc. But it seems that it does not work and instead of getting a still suqare (representing my near clipping plane) I get a plane that constantly moves and jumps around!!</p>