We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Obtaining the View Frustum
Page Index Toggle Pages: 1
Obtaining the View Frustum (Read 887 times)
Obtaining the View Frustum
Feb 19th, 2006, 4:54am
 
I'm trying to obtain the view frustum from the projection and modelview matrices, but don't seem to be getting it right. Can anyone with a better understanding of these matrices and how p5 implements them help me out?

My planes use the form ax + by + cz + d = 0 and I've been using the following code:


public Frustum(PGraphics3 g) {

PMatrix mvMat = g.modelview;
PMatrix projMat = g.projection;

PMatrix combo = new PMatrix(mvMat);
combo.apply(projMat);

Plane leftPlane = new Plane(
combo.m30 + combo.m00,
combo.m31 + combo.m01,
combo.m32 + combo.m02,
combo.m33 + combo.m03);

Plane rightPlane = new Plane(
combo.m30 - combo.m00,
combo.m31 - combo.m01,
combo.m32 - combo.m02,
combo.m33 - combo.m03);

Plane topPlane = new Plane(
combo.m30 - combo.m10,
combo.m31 - combo.m11,
combo.m32 - combo.m12,
combo.m33 - combo.m13);

Plane bottomPlane = new Plane(
combo.m30 + combo.m10,
combo.m31 + combo.m11,
combo.m32 + combo.m12,
combo.m33 + combo.m13);

Plane nearPlane = new Plane(
combo.m30 + combo.m20,
combo.m31 + combo.m21,
combo.m32 + combo.m22,
combo.m33 + combo.m23);

Plane farPlane = new Plane(
combo.m30 - combo.m20,
combo.m31 - combo.m21,
combo.m32 - combo.m22,
combo.m33 - combo.m23);

This is based on the info I found in http://www2.ravensoft.com/users/ggribb/plane%20extraction.pdf

Any help is much appreciated. Thanks!
Re: Obtaining the View Frustum
Reply #1 - Feb 19th, 2006, 3:14pm
 
why not just set the viewing frustum yourself? this is the doc for it:
http://dev.processing.org/reference/core/javadoc/processing/core/PGraphics3.html#frustum(float,%20float,%20float,%20float,%20float,%20float)

you can look through the source of PGraphics3 to see how it's used. i assume the example you're looking at is based on opengl or something like that, but we don't set things up exactly the way gl does.
Re: Obtaining the View Frustum
Reply #2 - Feb 20th, 2006, 12:14am
 
I'm trying to obtain the frustum plane equations so that I can do my own view-dependent culling before sending geometry through the pipeline. I have a terrain I've divided up with a quad-tree and need to be able to zoom in and add detail to only the portions in view, while not rendering those outside the view.

I realize its asking a lot, but I'm stuck here on these transformations. Can you or someone take a look and suggest the correct solution?

Thanks again.

Re: Obtaining the View Frustum
Reply #3 - Feb 21st, 2006, 7:43am
 
I figured out what was going wrong.

Changing the combined projection and modelview matrices to be:

PMatrix combo = new PMatrix(projMat);
combo.apply(mvMat);

works fine.

I picked this up by looking at how the undocumented and uncommented functions screenX/Y/Z() in PGraphics3 work. I guess that's what you get for working with beta software. sigh.
Page Index Toggle Pages: 1