Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# Problem with calculating the coordinates of the 8 vertices that define a view-frustum

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

Hi, A question about View-Frustums. "Not again !" I hear you all think, but this is something else I think, because I can't find anything about it using the "search" function on this forum ! I have implemented a working quad-tree and View-Frustum class but now i'd like to "draw" the box that defines my frustum so I can use this to do some debugging. I keep failing at this though. The frustum is, as you all know, defined by 6 planes, so I thought about defining the 8 intersection points between de planes (for example the intersection of front/left/top planes) and connecting those points with lines, so I get the frustum box. I found some techniques about intersecting planes, but it gives me some strange values. Here is my code :
D3DVERTEX CFrustrum::GetPlaneIntersection(float Frustrum[6][4], int side1, int side2, int side3)
{
D3DXMATRIX tempMatrix;
D3DXMATRIX inverse;
D3DVERTEX intersection;

//Here I make a 4x4 matrix containing the a,b,c,d coëfficients that define the 3 intersecting planes :

tempMatrix._11 = Frustrum[side1][A];
tempMatrix._12 = Frustrum[side1][B];
tempMatrix._13 = Frustrum[side1][C];
tempMatrix._14 = Frustrum[side1][D];

tempMatrix._21 = Frustrum[side2][A];
tempMatrix._22 = Frustrum[side2][B];
tempMatrix._23 = Frustrum[side2][C];
tempMatrix._24 = Frustrum[side2][D];

tempMatrix._31 = Frustrum[side3][A];
tempMatrix._32 = Frustrum[side3][B];
tempMatrix._33 = Frustrum[side3][C];
tempMatrix._34 = Frustrum[side3][D];

tempMatrix._41 = 0;
tempMatrix._42 = 0;
tempMatrix._43 = 0;
tempMatrix._44 = 1;

//Inverse the matrix (the values in the last column should be the coordinates of the intersection point, right ?)

D3DXMatrixInverse(&inverse, NULL, &tempMatrix);

intersection.fX = inverse._14;
intersection.fY = inverse._24;
intersection.fZ = inverse._34;

return intersection;

}

These are the values I get for the intersection point of the back/top/right planes with the camera in the origin : (10737476.0, 10737476.0, 10737476.0) this CAN'T be true What am I doing wrong here ? I believe my frustrum is defined correct, so the problems are situated in the calculation of the intersection point... Thanks in advance! [edited by - HolyFish on March 5, 2004 12:13:27 PM]

#### Share this post

##### Share on other sites
Advertisement
After projection all valid vertices lie between -1 < x < 1, -1 < y < 1, and 0 < z < 1.

Take the 8 combinations of points (-1,-1,0), (-1,-1,1), (-1,1,0), etc...

Take your view*proj matrix. Inverse it. Run the 8 points through your new inverse matrix. Voila, you should now have the points you wanted... I think.

#### Share this post

##### Share on other sites
Thanks for your reply ! But why are all the coordinates between -1 and 1 or 0 and 1 ? I've tried your technique but now I get (really) small values. With "run your points through your inverse matrix" you mean multiply each vertex with the inverse matrix, right ?

I've made a quick sketch of what I mean :
http://users.skynet.be/bk324186/frustum.JPG (how do I make this clicky btw ?)

The black lines define my frustum, the orange dot is the view position and the orange vector is the view direction.
I want to calculate the real world (important!) coordinates of the red vertices.
I want to use these coordinates to draw my frustum in my 3D world at a certain point to do some debugging and to check if my quadtree succesfully culls the right triangles..

thanks a lot in advance.

[edited by - HolyFish on March 6, 2004 9:09:48 AM]

#### Share this post

##### Share on other sites
Ok, I found it

Here is my code for those who are interested :
void CFrustrum::CalculateFrustum(){	D3DXMATRIX mInverse, mView, mProjection, mMat;	m_pD3DDevice->GetTransform(D3DTS_PROJECTION, &mProjection);	m_pD3DDevice->GetTransform(D3DTS_VIEW, &mView);	D3DXMatrixMultiply(&mMat, &mView, &mProjection);	D3DXMatrixInverse(&mInverse, NULL, &mMat);    m_FrustumVectors[0] = D3DXVECTOR3(-1.0f, -1.0f,  0.0f);     m_FrustumVectors[1] = D3DXVECTOR3( 1.0f, -1.0f,  0.0f);     m_FrustumVectors[2] = D3DXVECTOR3(-1.0f,  1.0f,  0.0f);     m_FrustumVectors[3] = D3DXVECTOR3( 1.0f,  1.0f,  0.0f);     m_FrustumVectors[4] = D3DXVECTOR3(-1.0f, -1.0f,  1.0f);     m_FrustumVectors[5] = D3DXVECTOR3( 1.0f, -1.0f,  1.0f);    m_FrustumVectors[6] = D3DXVECTOR3(-1.0f,  1.0f,  1.0f);     m_FrustumVectors[7] = D3DXVECTOR3( 1.0f,  1.0f,  1.0f);    for(unsigned int i = 0; i < 8; i++ )        D3DXVec3TransformCoord( &m_FrustumVectors[i], &m_FrustumVectors[i], &mInverse);    	D3DXPlaneFromPoints(&m_FrustumPlanes[0], &m_FrustumVectors[0],         &m_FrustumVectors[1], &m_FrustumVectors[2] ); // Near    D3DXPlaneFromPoints( &m_FrustumPlanes[1], &m_FrustumVectors[6],         &m_FrustumVectors[7], &m_FrustumVectors[5] ); // Far    D3DXPlaneFromPoints( &m_FrustumPlanes[2], &m_FrustumVectors[2],         &m_FrustumVectors[6], &m_FrustumVectors[4] ); // Left    D3DXPlaneFromPoints( &m_FrustumPlanes[3], &m_FrustumVectors[7],         &m_FrustumVectors[3], &m_FrustumVectors[5] ); // Right    D3DXPlaneFromPoints( &m_FrustumPlanes[4], &m_FrustumVectors[2],         &m_FrustumVectors[3], &m_FrustumVectors[6] ); // Top    D3DXPlaneFromPoints( &m_FrustumPlanes[5], &m_FrustumVectors[1],         &m_FrustumVectors[0], &m_FrustumVectors[4] ); // Bottom}

Thanks for the help!

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
• Advertisement

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633294
• Total Posts
3011242
• ### Who's Online (See full list)

There are no registered users currently online

×

## 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!