# Frustum corner troubles.

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

## Recommended Posts

*sigh* I'm lost again. This time, I'm trying to extract the frustum's 8 corners, and I'm just not quite there. What's especially irritating me, is I've copied this code from a previous project, where it worked, and here - zilch. Here's what I'm doing: 1) Extract the View and Projection matrices, and send them to my building class:
	m_Device->SetTransform(D3DTS_VIEW, &MatView);
D3DXMATRIX MatProj;
m_Device->GetTransform(D3DTS_VIEW, &MatProj);
D3DXMatrixMultiply(&MatProj, &MatView, &MatProj);

m_Frustum.Create(MatProj);


2) Build the actual frustum: - Now, what I'm doing is transforming 8 points with the [-1.0f 1.0f] range by the inverse of the combined View Projection matrix. This *Should* give me the 8 frustum corners (I think!). Heres the code:
bool cFrustum::Create(D3DXMATRIX CombMat)
{
D3DXMATRIX InvCombMat;
D3DXMatrixInverse(&InvCombMat, 0, &CombMat);

D3DXVECTOR3 vec = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB = cAABB(vec);

vec = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB.Expand(vec);

vec = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB.Expand(vec);

vec = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB.Expand(vec);

vec = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB.Expand(vec);

vec = D3DXVECTOR3(-1.0f, 1.0f, -1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB.Expand(vec);

vec = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB.Expand(vec);

vec = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
D3DXVec3TransformCoord(&vec, &vec, &InvCombMat );
m_AABB.Expand(vec);

return false;
}


Now, the vaules being spit out of these transformations are, I think, wrong. My camera is set up at a height (Y) of about 40.0f. The view depth is 100.0f, and it's looking about 45 degrees down (3D RTS style camera). Now, I'm getting Y values of around 58.0f - 60.5f for my corners. All 8. This isn't right... Any ideas on this? Is the basic math correct? Thanks a bunch guys! :).

##### Share on other sites
I'm not advanced enough in 3D programming and maths to help you with those things, but the first source seems wrong :

m_Device->SetTransform(D3DTS_VIEW, &MatView);D3DXMATRIX MatProj;m_Device->GetTransform(D3DTS_VIEW, &MatProj);

Shouldn't it be :
m_Device->GetTransform(D3DTS_VIEW, &MatView);D3DXMATRIX MatProj;m_Device->GetTransform(D3DTS_PROJECTION, &MatProj);

?

##### Share on other sites
Arg, it was that simple :(. Thanks a bunch!

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

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

• Total Topics
633269
• Total Posts
3011152
• ### Who's Online (See full list)

There are no registered users currently online

×