Jump to content
  • Advertisement
Sign in to follow this  
sirob

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 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!