Jump to content
  • Advertisement
Sign in to follow this  
robydx

quick way to get view frustum corner

This topic is 4823 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

I need to calculate the 8 point that define the trapezoid of the view frustum. In pratictal from view and projection matrix I need to create a poligon that contain the scene that I see from the camera. Anyone know a way? thank you

Share this post


Link to post
Share on other sites
Advertisement
You can compute the values by transforming the 8 corners of a cube created about the origin by the projection matrix if I remember correctly.

I'll look up the code fragment in a second (I posted it a while back), but basically, create 8 D3DXVECTOR3's defining your cube between -1.0f and +1.0f, then use D3DXVec3TransformCoord() with the projection matrix as the transform...

hth
Jack

Share this post


Link to post
Share on other sites
then I can just create a cube with corner 1,1,1 and -1,-1,-1 and transform them with view projection matrix?

Share this post


Link to post
Share on other sites
Hi there robydx,
How are you doing?

[The Problem]
Retrieving the View Frustum from the view matrix?

[The Solution]
Refer to this post about View Frustum planes

My reply on that post has a link to a pdf that describes you can extract the view frustum planes from a view matrix.

But here is a direct link to the view frustum extraction pdf

View Frustum Extraction

I hope this helps a bit
Keep cool.

Share this post


Link to post
Share on other sites
Almost, I just double checked my code and I got it slightly wrong - sorry [oh]

//0. Variables:
D3DXMATRIXA16 mat;
D3DXVECTOR3 vecFrustum[8];

//1. multiply the matrices together
D3DXMatrixMultiply( &mat, matView, matProj );
D3DXMatrixInverse( &mat, NULL, &mat );

//2. create the 8 points of a cube in unit-space
vecFrustum[0] = D3DXVECTOR3(-1.0f, -1.0f, 0.0f); // xyz
vecFrustum[1] = D3DXVECTOR3( 1.0f, -1.0f, 0.0f); // Xyz
vecFrustum[2] = D3DXVECTOR3(-1.0f, 1.0f, 0.0f); // xYz
vecFrustum[3] = D3DXVECTOR3( 1.0f, 1.0f, 0.0f); // XYz
vecFrustum[4] = D3DXVECTOR3(-1.0f, -1.0f, 1.0f); // xyZ
vecFrustum[5] = D3DXVECTOR3( 1.0f, -1.0f, 1.0f); // XyZ
vecFrustum[6] = D3DXVECTOR3(-1.0f, 1.0f, 1.0f); // xYZ
vecFrustum[7] = D3DXVECTOR3( 1.0f, 1.0f, 1.0f); // XYZ

//3. transform all 8 points by the view/proj matrix. Doing this
// gives us that ACTUAL 8 corners of the frustum area.
for( int i = 0; i < 8; i++ )
D3DXVec3TransformCoord( &vecFrustum, &vecFrustum, &mat );

//4. generate and store the 6 planes that make up the frustum
D3DXPlaneFromPoints( &FrustumPlanes[0], &vecFrustum[0],
&vecFrustum[1], &vecFrustum[2] ); // Near

D3DXPlaneFromPoints( &FrustumPlanes[1], &vecFrustum[6],
&vecFrustum[7], &vecFrustum[5] ); // Far

D3DXPlaneFromPoints( &FrustumPlanes[2], &vecFrustum[2],
&vecFrustum[6], &vecFrustum[4] ); // Left

D3DXPlaneFromPoints( &FrustumPlanes[3], &vecFrustum[7],
&vecFrustum[3], &vecFrustum[5] ); // Right

D3DXPlaneFromPoints( &FrustumPlanes[4], &vecFrustum[2],
&vecFrustum[3], &vecFrustum[6] ); // Top

D3DXPlaneFromPoints( &FrustumPlanes[5], &vecFrustum[1],
&vecFrustum[0], &vecFrustum[4] ); // Bottom



Is the code I posted in this thread. You can ignore the last parts about constructing the 6 planes if you want, but the first 3 steps will give you the actual 8 coordinates of the frustum trapezoid.

hth
Jack

Share this post


Link to post
Share on other sites
Will this method return the actual trapazoid points, or frustum-bounding cube points? If the latter, is there a way to calculate the specific trapazoid frustum points?

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
You can compute the values by transforming the 8 corners of a cube created about the origin by the projection matrix if I remember correctly.

... but basically, create 8 D3DXVECTOR3's defining your cube between -1.0f and +1.0f, then use D3DXVec3TransformCoord() with the projection matrix as the transform...


Actually, it is the inverse of the projection transformation. That will give you the locations in view space. If you want the points in world space, you also multiply by the inverse view transformation (which is usually your camera's orientation/position).

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!