Question

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:

  1. How do I get the coordinates for each corner of the near clipping plane? (or the plane equation coefficients)
  2. How do I go back to object space?

Test:

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:

V1 = IMVM * ( IPM * V1 );

V2 = IMVM * ( IPM * V2 );

V3 = IMVM * ( IPM * V3 );

V4 = IMVM * ( IPM * V4 );

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!!

Was it helpful?

Solution

Well it seems that all my questions on this forum is going to be answered by myself! First of all after thinking about it I realized we do not need the inverse of projection matrix. We designate the points in camera space and to take them back to object space we just need the inverse of the modelview matrix.

As always with errors that kill you, there was a logical error in my vector-matrix multiplication calculation. When I double checked with an online matrix calculator I realized my first element is correct but the rest of the elements are incorrect. That's when it hit me that I am storing the results in the same matrix that I am multiplying and I am just altering the original matrix consequently. So I just added a new matrix for the results and everything worked fine. Basically I designated a point and I multiplied it by the inverse of the model-view matrix to get the points in the object space coordinate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top