Archived

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

cryo75

Frustum woes...

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);

	//Right

	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]);

	//Left

	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]);

	//Bottom

	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]);

	//Top

	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]);

	//Back

	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]);

	//Front

	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!
/jk

Share this post


Link to post
Share on other sites