Problems getting correct Viewing frustrum planes

Started by
23 comments, last by Zakwayda 18 years, 6 months ago
Hi, I found a paper on "fast extaction of viewing frustrum planes from the Wolrd-View-Proj matrix", with all the code to implement this. I tested it this way : I extracted the planes of the viewing frustrum when standing at (0,3,0) When trying to test if a point is on plane with the near clipping plane, I got the point (0,3,8). My projection matrix is a "normal" one for a first person camera ans it is set to see at 100 units of distance. I would have expected something like (0,3,100) to be on plane with the near clipping plane. Or maybe is it the far clipping plane ? Any explanations would be welcome. My knowledge in this field equals something near zero Thnks
Advertisement
I don't have an answer, but you might post the following information:

1. Which API (OpenGL, D3D, etc.)
2. What direction your camera is facing, and what direction is up
3. What your field of view is (horizontal or vertical)
4. What your near and far values are
5. Anything else relevant that you can think of
the clipping planes positive/front side is into the frustrum

make sure you take care about the matrix order in memory

opengl uses column major order
d3d no idead

http://www.8ung.at/basiror/theironcross.html
as far as I know, Direct3D uses row-major matrices
More information :
Using D3D

D3DXMatrixPerspectiveFovLH (&matProjection, D3DX_PI/4, 800/600,
1.0f, 100.0f);

When I extract my planes here are the values of projection and view matrix :

Proj :

1.82 0 0 0
0 2.42 0 0
0 0 1.02 0
0 0 -1.01 0


View :

1 0 0 0
0 1 0 0
0 0 1 0
0 0 -3 1


I set the proj. matrix once at initialisation, and never touch it again.

My view transform is always before world transformations.

Hope this help !
The paper included 2 implementations, one with OpenGL and the other for D3D.
Only difference is about that row column major order.
Quote:Only difference is about that row column major order.
You might double check that. OpenGL clips z to [-1,1], while D3D clips to [0,1]. So the near plane extraction is probably different.

Also, if you're using single-index accessing in your code (i.e. m[0], m[1], m[2]), you might double check the mapping from the indexing in your code to the double indexing in the .pdf.
I agree with you jyk

It's probably a mismatch between what's written on the pdf and my code.

Maybe I copy/pasted the wrong implementation

I'll check this...
Ok. It's my fault. I used the OpenGL method to extract my planes..

I checked to see when I hit the near and far planes and results were bad news.

I was on plane at the point where i'm standing, for these planes.

I extracted the planes at this point (0,3,0) and was on plane with the near and far planes at the same point (0,3,0 )

Did the same with (0,3,10) : on plane at (0,3,10)

So now I'm lost. I'm starting to wonder if my code that is bad, or the extraction is not working (It should be)



need help !

Here is the code to test if i'm on plane :

HALFSPACE classifyPoint (const D3DXPLANE& plane, const D3DXVECTOR3& point){

float d;



d = plane.a*point.x + plane.b*point.y + plane.c*point.z + plane.d;




if (d < 0) return NEGATIVE;
if (d > 0) return POSITIVE;
return ON_PLANE;
}


Here is the code of the extraction :

// Left clipping plane
plans[0].a = comboMatrix._14 + comboMatrix._11;
plans[0].b = comboMatrix._24 + comboMatrix._21;
plans[0].c = comboMatrix._34 + comboMatrix._31;
plans[0].d = comboMatrix._44 + comboMatrix._41;
// Right clipping plane
plans[1].a = comboMatrix._14 - comboMatrix._11;
plans[1].b = comboMatrix._24 - comboMatrix._21;
plans[1].c = comboMatrix._34 - comboMatrix._31;
plans[1].d = comboMatrix._44 - comboMatrix._41;
// Top clipping plane
plans[2].a = comboMatrix._14 - comboMatrix._12;
plans[2].b = comboMatrix._24 - comboMatrix._22;
plans[2].c = comboMatrix._34 - comboMatrix._32;
plans[2].d = comboMatrix._44 - comboMatrix._42;
// Bottom clipping plane
plans[3].a = comboMatrix._14 + comboMatrix._12;
plans[3].b = comboMatrix._24 + comboMatrix._22;
plans[3].c = comboMatrix._34 + comboMatrix._32;
plans[3].d = comboMatrix._44 + comboMatrix._42;
// Near clipping plane
plans[4].a = comboMatrix._13;
plans[4].b = comboMatrix._23;
plans[4].c = comboMatrix._33;
plans[4].d = comboMatrix._43;
// Far clipping plane
plans[5].a = comboMatrix._14 - comboMatrix._13;
plans[5].b = comboMatrix._24 - comboMatrix._23;
plans[5].c = comboMatrix._34 - comboMatrix._33;
plans[5].d = comboMatrix._44 - comboMatrix._43;


Hm, I'm not sure. Your code looks correct. Actually, I have one suggestion; try normalizing your planes after extraction. That may be what's throwing off your results...
I had problems with this but as soon as I normalised the planes it worked fine.

I hope that sorts out your problem

Matt

Juksosah - I thought I could help Juksosah out there but you beat me to it. lol

This topic is closed to new replies.

Advertisement