# quick way to get view frustum corner

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

## 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 on other sites
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 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 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 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 togetherD3DXMatrixMultiply( &mat, matView, matProj );D3DXMatrixInverse( &mat, NULL, &mat );//2. create the 8 points of a cube in unit-spacevecFrustum[0] = D3DXVECTOR3(-1.0f, -1.0f,  0.0f); // xyzvecFrustum[1] = D3DXVECTOR3( 1.0f, -1.0f,  0.0f); // XyzvecFrustum[2] = D3DXVECTOR3(-1.0f,  1.0f,  0.0f); // xYzvecFrustum[3] = D3DXVECTOR3( 1.0f,  1.0f,  0.0f); // XYzvecFrustum[4] = D3DXVECTOR3(-1.0f, -1.0f,  1.0f); // xyZvecFrustum[5] = D3DXVECTOR3( 1.0f, -1.0f,  1.0f); // XyZvecFrustum[6] = D3DXVECTOR3(-1.0f,  1.0f,  1.0f); // xYZvecFrustum[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 frustumD3DXPlaneFromPoints( &FrustumPlanes[0], &vecFrustum[0], 			&vecFrustum[1], &vecFrustum[2] ); // NearD3DXPlaneFromPoints( &FrustumPlanes[1], &vecFrustum[6], 			&vecFrustum[7], &vecFrustum[5] ); // FarD3DXPlaneFromPoints( &FrustumPlanes[2], &vecFrustum[2], 			&vecFrustum[6], &vecFrustum[4] ); // LeftD3DXPlaneFromPoints( &FrustumPlanes[3], &vecFrustum[7], 			&vecFrustum[3], &vecFrustum[5] ); // RightD3DXPlaneFromPoints( &FrustumPlanes[4], &vecFrustum[2], 			&vecFrustum[3], &vecFrustum[6] ); // TopD3DXPlaneFromPoints( &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 on other sites
thank you so much to everybody

##### 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 on other sites
Quote:
 Original post by jollyjeffersYou 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).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634123
• Total Posts
3015658
×