Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been grappling with the Hartmann/Gribbs method of extracting the Frustum planes for some time now, with little success. There doesn't appear to be a "definitive" topic or tutorial which combines all the necessary information, so perhaps this can be it

First of all, I am attempting to do this in C# (For Playstation Mobile), using OpenGL style Column-Major matrices in a Right-Handed coordinate system but obviously the math will work in any language.

My projection matrix has a Near plane at 1.0, Far plane at 1000, FOV of 45.0 and Aspect of 1.7647.

I want to get my planes in World-Space, so I build my frustum from the View-Projection Matrix (that's projectionMatrix * viewMatrix). The view Matrix is the inverse of the camera's World-Transform.

The problem is; regardless of what I tweak, I can't seem to get a correct frustum. I think that I may be missing something obvious.

Focusing on the Near and Far planes for the moment (since they have the most obvious normals when correct), when my camera is positioned looking down the negative z-axis, I get two planes facing in the same direction, rather than opposite directions. If i strafe my camera left and right (while still looking along the z axis) the x value of the normal vector changes.

Obviously, something is fundamentally wrong here; I just can't figure out what - maybe someone here can?

EDIT: Applying the algorithm to just the Projection matrix (i.e. model and view matrices are identity) I get the Near and Far planes returned as the following; Far: normal[0,0-1], distance 1 Near: normal[0,0,-1], distance -0.3328891

Can someone tell me if these seem correct? Using the algorithm with just the Projection Matrix should return the planes in View Space (camera space)

share|improve this question
    
I respect that you bring this question here, since it raises the tone on this site, and accordingly I hope someone will answer it, but I suspect it's the kind of question that may be better off moved to cstheory.stackexchange.com. They're more involved with advanced and rather academic algorithms over there. –  Nick Wiggill Oct 10 '12 at 22:45
    
I'm not sure that this qualifies as Theoretical Computing Science, but thanks for the reply - it seems to be the same method found here; lighthouse3d.com/tutorials/view-frustum-culling/… except this emphasises the fixed-function pipeline, which I am not using (although I think that, in the case of the fixed-function pipeline, the Model part of the ModelView matrix would be an identity matrix anyway?) –  DAVco Oct 11 '12 at 10:39
    
I definitely agree with you, but answers may be slow in coming, here. It's a matter of what tends to get answered here. I would also suggest either the OpenGL forums or gamedev.net if you need an answer quickly. Wish I could help but I'm using simple arc / planar culling in my project, as it's "good enough" when vertical complexity remains fairly low. –  Nick Wiggill Oct 11 '12 at 11:29
    
Answers seem slow in coming everywhere ;) I've posted to GameDev.net and StackOverflow without any response. Apparently this is a common method of plane extraction, but evidently nobody else has had a problem with it before :) If I do ever find a solution I'll be sure to post it here. –  DAVco Oct 11 '12 at 12:24
    
There might be better explanations in some of these books (the GPU Gems series in particular comes to mind, since they generally cover all the best 3D graphics algorithms). PS that is a great site in general, I have found the intersections page useful time after time. Best of luck. –  Nick Wiggill Oct 11 '12 at 13:20
add comment

1 Answer 1

Firstly, extracting from just the projection matrix is a good place to start debugging.

To answer your question:

In this case, your near and far plane values should be <0, 0, 1, -1> and <0, 0, -1, 1000> respectively. In practice, it might be off by a little due to floating point rounding errors.

Now to help you solve your larger problem:

  1. You say you are getting a near and far plane of <0, 0, -1, -0.3328891> and <0, 0, -1, 1> respectively. These values comes directly from summing/subtracting rows or columns from your projection matrix, so writing out the projection matrix values on paper and eyeballing it might make it obvious.

  2. Make sure your projection matrix is correct.

  3. Make sure your plane normalization routine is correct (<a / |n|, b / |n|, c / |n|, d / |n|>, where |n| is the length of <a, b, c> ONLY).

  4. Make sure you are not getting your rows and columns mixed up.

You are basically going to need to comb through your code step-by-step and make sure everything has been done correctly.

I recently did this (for Direct3D though) and had to go through the same steps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.