Frustum corner troubles.

Started by
1 comment, last by sirob 18 years, 6 months ago
*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! :).
Sirob Yes.» - status: Work-O-Rama.
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);

?
Arg, it was that simple :(. Thanks a bunch!
Sirob Yes.» - status: Work-O-Rama.

This topic is closed to new replies.

Advertisement