Skip to main content
gamedev.net
🔒 Locked

Direct3D View

Started by nick-- Feb 21, 2007 at 3:07 AM 1 replies 850+ views
Original Post
nick--
nick--
Hi, Suppose I setup my view in Direct3D and I want to know the bounds of my scene. For example, the left side of the screen ends at -5.0f, right side at 2.0f and the top/bottom. Is there any function that returns this information?
Evil Steve
Evil Steve
It's relitively easy to get the frustum planes from the view-projection matrix, and from there it's just a case of using the planes themselfs to determine the extents of the scene.

From my code:
const Matrix& CCamera::GetViewMatrix(){	if(!m_bDirty)		return m_matView;	// Create view matrix	m_matView.SetToLookat(m_vPos, m_vPos+m_vDir, m_vUp);	// Create billboard matrix	m_matBillboard = m_matView.GetInverse();	m_matBillboard.m_elements._41 = 0.0f;	m_matBillboard.m_elements._42 = 0.0f;	m_matBillboard.m_elements._43 = 0.0f;	// Create frustum	Matrix mat(m_matView*m_matProj);	// Left clipping plane	m_frustum[0].vNormal.x = mat.m_elements._14 + mat.m_elements._11;	m_frustum[0].vNormal.y = mat.m_elements._24 + mat.m_elements._21;	m_frustum[0].vNormal.z = mat.m_elements._34 + mat.m_elements._31;	m_frustum[0].fDist = mat.m_elements._44 + mat.m_elements._41;	// Right clipping plane	m_frustum[1].vNormal.x = mat.m_elements._14 - mat.m_elements._11;	m_frustum[1].vNormal.y = mat.m_elements._24 - mat.m_elements._21;	m_frustum[1].vNormal.z = mat.m_elements._34 - mat.m_elements._31;	m_frustum[1].fDist = mat.m_elements._44 - mat.m_elements._41;	// Top clipping plane	m_frustum[2].vNormal.x = mat.m_elements._14 - mat.m_elements._12;	m_frustum[2].vNormal.y = mat.m_elements._24 - mat.m_elements._22;	m_frustum[2].vNormal.z = mat.m_elements._34 - mat.m_elements._32;	m_frustum[2].fDist = mat.m_elements._44 - mat.m_elements._42;	// Bottom clipping plane	m_frustum[3].vNormal.x = mat.m_elements._14 + mat.m_elements._12;	m_frustum[3].vNormal.y = mat.m_elements._24 + mat.m_elements._22;	m_frustum[3].vNormal.z = mat.m_elements._34 + mat.m_elements._32;	m_frustum[3].fDist = mat.m_elements._44 + mat.m_elements._42;	// Near clipping plane	m_frustum[4].vNormal.x = mat.m_elements._13;	m_frustum[4].vNormal.y = mat.m_elements._23;	m_frustum[4].vNormal.z = mat.m_elements._33;	m_frustum[4].fDist = mat.m_elements._43;	// Far clipping plane	m_frustum[5].vNormal.x = mat.m_elements._14 - mat.m_elements._13;	m_frustum[5].vNormal.y = mat.m_elements._24 - mat.m_elements._23;	m_frustum[5].vNormal.z = mat.m_elements._34 - mat.m_elements._33;	m_frustum[5].fDist = mat.m_elements._44 - mat.m_elements._43;	m_bDirty = false;	return m_matView;}
nick--
nick--
Thanks for the quick answer.

I can use what you gave me for this purpose..
But I would like to actually understand the math logic behind it.

Do you have a good tutorial/text that explains the subject (Matrix math / Projection / View / Transformation etc)?
Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.