quick way to get view frustum corner
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
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
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
then I can just create a cube with corner 1,1,1 and -1,-1,-1 and transform them with view projection matrix?
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.
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.
Almost, I just double checked my code and I got it slightly wrong - sorry [oh]
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
//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
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?
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement