Archived

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

Frustum planes

This topic is 5142 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

this is the correct way ?

	D3DXMATRIX Matrix;
	D3DXMatrixMultiply(&Matrix, pMatView, pMatProj);


	m_FrustumPlanes[0].a = Matrix._14 + Matrix._11;
	m_FrustumPlanes[0].b = Matrix._24 + Matrix._21;
	m_FrustumPlanes[0].c = Matrix._34 + Matrix._31;
	m_FrustumPlanes[0].d = Matrix._44 + Matrix._41;
	// Right clipping plane

	m_FrustumPlanes[1].a = Matrix._14 - Matrix._11;
	m_FrustumPlanes[1].b = Matrix._24 - Matrix._21;
	m_FrustumPlanes[1].c = Matrix._34 - Matrix._31;
	m_FrustumPlanes[1].d = Matrix._44 - Matrix._41;
	// Top clipping plane

	m_FrustumPlanes[2].a = Matrix._14 - Matrix._12;
	m_FrustumPlanes[2].b = Matrix._24 - Matrix._22;
	m_FrustumPlanes[2].c = Matrix._34 - Matrix._32;
	m_FrustumPlanes[2].d = Matrix._44 - Matrix._42;
	// Bottom clipping plane

	m_FrustumPlanes[3].a = Matrix._14 + Matrix._12;
	m_FrustumPlanes[3].b = Matrix._24 + Matrix._22;
	m_FrustumPlanes[3].c = Matrix._34 + Matrix._32;
	m_FrustumPlanes[3].d = Matrix._44 + Matrix._42;
	// Near clipping plane

	m_FrustumPlanes[4].a = Matrix._13;
	m_FrustumPlanes[4].b = Matrix._23;
	m_FrustumPlanes[4].c = Matrix._33;
	m_FrustumPlanes[4].d = Matrix._43;
	// Far clipping plane

	m_FrustumPlanes[5].a = Matrix._14 - Matrix._13;
	m_FrustumPlanes[5].b = Matrix._24 - Matrix._23;
	m_FrustumPlanes[5].c = Matrix._34 - Matrix._33;
	m_FrustumPlanes[5].d = Matrix._44 - Matrix._43;
	// Normalize the plane equations, if requested

	
D3DXPlaneNormalize(&m_FrustumPlanes[0], &m_FrustumPlanes[0]);
		D3DXPlaneNormalize(&m_FrustumPlanes[1], &m_FrustumPlanes[1]);
		D3DXPlaneNormalize(&m_FrustumPlanes[2], &m_FrustumPlanes[2]);
		D3DXPlaneNormalize(&m_FrustumPlanes[3], &m_FrustumPlanes[3]);
		D3DXPlaneNormalize(&m_FrustumPlanes[4], &m_FrustumPlanes[4]);
		D3DXPlaneNormalize(&m_FrustumPlanes[5], &m_FrustumPlanes[5]);

 
[edited by - psicor on November 9, 2003 3:09:44 AM]

Share this post


Link to post
Share on other sites
Your code looks to be correct; the only difference that I can spot is in the calculation of the near clipping plane. The following is what I have for the near clipping plane:


// Near clipping plane

m_FrustumPlanes[4].a = Matrix._14 + Matrix._13;
m_FrustumPlanes[4].b = Matrix._24 + Matrix._23;
m_FrustumPlanes[4].c = Matrix._34 + Matrix._33;
m_FrustumPlanes[4].d = Matrix._44 + Matrix._43;


_______________________________________
Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
And how do you think about this ?

int CFrustum::BoxInFrustum( float x, float y, float z, float x2, float y2, float z2)
{


BYTE mode=0; // set IN and OUT bit to 0

for(int i = 0; i < 6; i++ )
{
mode &= V_OUT; // clear the IN bit to 0

if(m_FrustumPlanes[i].a * x + m_FrustumPlanes[i].b * y + m_FrustumPlanes[i].c * z + m_FrustumPlanes[i].d >= 0) mode |= V_IN; // set IN bit to 1

else mode |= V_OUT; // set OUT bit to 1

if (mode == V_INTERSECT) continue; // if we found a vertex IN for THIS plane and

// a vertex OUT of ANY plane continue ( we have enough information to say:

// INTERSECT! IF there is not vertex missing from the FRONT of the remaining planes)


if(m_FrustumPlanes[i].a * x2 + m_FrustumPlanes[i].b * y + m_FrustumPlanes[i].c * z + m_FrustumPlanes[i].d >= 0) mode |= V_IN; else mode |= V_OUT;
if (mode == V_INTERSECT) continue;

if(m_FrustumPlanes[i].a * x + m_FrustumPlanes[i].b * y2 + m_FrustumPlanes[i].c * z + m_FrustumPlanes[i].d >= 0) mode |= V_IN; else mode |= V_OUT;
if (mode == V_INTERSECT) continue;

if(m_FrustumPlanes[i].a * x2 + m_FrustumPlanes[i].b * y2 + m_FrustumPlanes[i].c * z + m_FrustumPlanes[i].d >= 0) mode |= V_IN; else mode |= V_OUT;
if (mode == V_INTERSECT) continue;

if(m_FrustumPlanes[i].a * x + m_FrustumPlanes[i].b * y + m_FrustumPlanes[i].c * z2 + m_FrustumPlanes[i].d >= 0) mode |= V_IN; else mode |= V_OUT;
if (mode == V_INTERSECT) continue;

if(m_FrustumPlanes[i].a * x2 + m_FrustumPlanes[i].b * y + m_FrustumPlanes[i].c * z2 + m_FrustumPlanes[i].d >= 0) mode |= V_IN; else mode |= V_OUT;
if (mode == V_INTERSECT) continue;

if(m_FrustumPlanes[i].a * x + m_FrustumPlanes[i].b * y2 + m_FrustumPlanes[i].c * z2 + m_FrustumPlanes[i].d >= 0) mode |= V_IN; else mode |= V_OUT;
if (mode == V_INTERSECT) continue;

if(m_FrustumPlanes[i].a * x2 + m_FrustumPlanes[i].b * y2 + m_FrustumPlanes[i].c * z2 + m_FrustumPlanes[i].d >= 0) mode |= V_IN; else mode |= V_OUT;
if (mode == V_INTERSECT) continue;

// if we arrive to this point, then there are two possibilities:

// there is not vertices in or there is not intersection till know, if

// there is a vertice in, continue (we are not over!)

if (mode == V_IN) continue;

// there is not vertex IN front of this plane, so the box is COMPLETE_OUT

return COMPLETE_OUT;
}

// All planes has a vertex IN FRONT so or the box is intersecting or complete IN

if (mode == V_INTERSECT) return INTERSECT;
else return COMPLETE_IN;
}


[edited by - psicor on November 17, 2003 12:43:56 AM]

Share this post


Link to post
Share on other sites