Advertisement Jump to content
Sign in to follow this  

Problems getting correct Viewing frustrum planes

This topic is 4873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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...

Share this post

Link to post
Share on other sites
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;

Share this post

Link to post
Share on other sites
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...

Share this post

Link to post
Share on other sites
I had problems with this but as soon as I normalised the planes it worked fine.

I hope that sorts out your problem


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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!