Jump to content
  • Advertisement


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


Frustum woes...

This topic is 5487 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 all, The following 2 functions update the frustum and check if a point is inside the view frustum:
void CCamera::UpdateFrustum()
	D3DXMATRIX matClip;
	D3DXMatrixMultiply(&matClip, &matView, &matProjection);


	mFrustum[FS_RIGHT].a = matClip._14 - matClip._11;
	mFrustum[FS_RIGHT].b = matClip._24 - matClip._21;
	mFrustum[FS_RIGHT].c = matClip._34 - matClip._31;
	mFrustum[FS_RIGHT].d = matClip._44 - matClip._41;
	D3DXPlaneNormalize(&mFrustum[FS_RIGHT], &mFrustum[FS_RIGHT]);


	mFrustum[FS_LEFT].a = matClip._14 + matClip._11;
	mFrustum[FS_LEFT].b = matClip._24 + matClip._21;
	mFrustum[FS_LEFT].c = matClip._34 + matClip._31;
	mFrustum[FS_LEFT].d = matClip._44 + matClip._41;
	D3DXPlaneNormalize(&mFrustum[FS_LEFT], &mFrustum[FS_LEFT]);


	mFrustum[FS_BOTTOM].a = matClip._14 + matClip._12;
	mFrustum[FS_BOTTOM].b = matClip._24 + matClip._22;
	mFrustum[FS_BOTTOM].c = matClip._34 + matClip._32;
	mFrustum[FS_BOTTOM].d = matClip._44 + matClip._42;
	D3DXPlaneNormalize(&mFrustum[FS_BOTTOM], &mFrustum[FS_BOTTOM]);


	mFrustum[FS_TOP].a = matClip._14 - matClip._12;
	mFrustum[FS_TOP].b = matClip._24 - matClip._22;
	mFrustum[FS_TOP].c = matClip._34 - matClip._32;
	mFrustum[FS_TOP].d = matClip._44 - matClip._42;
	D3DXPlaneNormalize(&mFrustum[FS_TOP], &mFrustum[FS_TOP]);


	mFrustum[FS_BACK].a = matClip._14 - matClip._13;
	mFrustum[FS_BACK].b = matClip._24 - matClip._23;
	mFrustum[FS_BACK].c = matClip._34 - matClip._33;
	mFrustum[FS_BACK].d = matClip._44 - matClip._43;
	D3DXPlaneNormalize(&mFrustum[FS_BACK], &mFrustum[FS_BACK]);


	mFrustum[FS_FRONT].a = matClip._14 + matClip._13;
	mFrustum[FS_FRONT].b = matClip._24 + matClip._23;
	mFrustum[FS_FRONT].c = matClip._34 + matClip._33;
	mFrustum[FS_FRONT].d = matClip._44 + matClip._43;
	D3DXPlaneNormalize(&mFrustum[FS_FRONT], &mFrustum[FS_FRONT]);

bool CCamera::PointInFrustum(D3DXVECTOR3* Vertex)
	for (int p = 0; p < 6; p++) {
		if (mFrustum[p].a * Vertex->x + mFrustum[p].b * Vertex->y + mFrustum[p].c * Vertex->z + mFrustum[p].d <= 0)
			return false;

	return true;
But the result on loading is this: http://www.axiomsoftech.com/temp1.jpg Am I missing something?? Thanks, Ivan

Share this post

Link to post
Share on other sites
I think that extracting your clipping plane for your front should be this:

mFrustum[FS_FRONT].a = matClip._13;
mFrustum[FS_FRONT].b = matClip._23;
mFrustum[FS_FRONT].c = matClip._33;
mFrustum[FS_FRONT].d = matClip._43;

And make sure that the points you are testing are in the same space as your planes (World space).

Hope this helps!

Share this post

Link to post
Share on other sites

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