Example #1
0
File: map.c Project: dommul/super8
/*
===============
FindPlane

Returns a global plane number and the side that will be the front
===============
*/
int	FindPlane( plane_t *dplane, int *side )
{
	int			i;
	plane_t		*dp, pl;
	vec_t		dot;

	pl = *dplane;
	NormalizePlane( &pl );

	if( DotProduct( pl.normal, dplane->normal ) > 0 )
		*side = 0;
	else
		*side = 1;

	for( i = 0, dp = mapplanes; i < nummapplanes; i++, dp++ ) {
		if( DotProduct( dp->normal, pl.normal ) > 1.0 - ANGLE_EPSILON && fabs( dp->dist - pl.dist ) < DIST_EPSILON )
			return i; // regular match
	}

	if( nummapplanes == MAX_MAP_PLANES )
		Error( "FindPlane: nummapplanes == MAX_MAP_PLANES" );

	dot = VectorLength( dplane->normal );
	if( dot < 1.0 - ANGLE_EPSILON || dot > 1.0 + ANGLE_EPSILON )
		Error( "FindPlane: normalization error (%f %f %f, length %f)", dplane->normal[0], dplane->normal[1], dplane->normal[2], dot );

	mapplanes[nummapplanes] = pl;

	return nummapplanes++;
}
Example #2
0
bool SpaceGameEngine::IfIntersect(const AxisAlignedBoundingBox & aabb, const Triangle & triangle)
{
	Vector3D point[8];
	point[0] = Vector3D(aabb.m_MinPosition.x, aabb.m_MaxPosition.y, aabb.m_MinPosition.z);
	point[1] = Vector3D(aabb.m_MaxPosition.x, aabb.m_MaxPosition.y, aabb.m_MinPosition.z);
	point[2] = Vector3D(aabb.m_MaxPosition.x, aabb.m_MinPosition.y, aabb.m_MinPosition.z);
	point[3] = Vector3D(aabb.m_MinPosition);
	point[4] = Vector3D(aabb.m_MinPosition.x, aabb.m_MaxPosition.y, aabb.m_MaxPosition.z);
	point[5] = Vector3D(aabb.m_MaxPosition);
	point[6] = Vector3D(aabb.m_MaxPosition.x, aabb.m_MinPosition.y, aabb.m_MaxPosition.z);
	point[7] = Vector3D(aabb.m_MinPosition.x, aabb.m_MinPosition.y, aabb.m_MaxPosition.z);
	Plane plane[6] = {
		NormalizePlane(Plane(point[0],point[1],point[2])),	//front
		NormalizePlane(Plane(point[5],point[4],point[7])),	//back
		NormalizePlane(Plane(point[4],point[5],point[1])),	//top
		NormalizePlane(Plane(point[3],point[2],point[6])),	//back
		NormalizePlane(Plane(point[4],point[0],point[3])),	//left
		NormalizePlane(Plane(point[1],point[5],point[6]))	//right
	};//面都对外
	for (int i = 0; i < 6; i++)
	{
		int fa_cot = 0;
		for (int j = 0; j < 3; j++)
		{
			if (IfBeFrontOfPlane(plane[i], triangle.m_Positions[j]))
				fa_cot += 1;
		}
		if (fa_cot == 3)
			return false;
	}
	return true;
}
Example #3
0
	void Frustum::RecalculatePlanesEx(glm::mat4x4& p_view, glm::mat4x4& p_proj)
	{
		glm::mat4 matrix;

		float a = -(m_far + m_near) / (m_far - m_near);
		float b = -(2 * m_far * m_near) / (m_far - m_near);

		float c = p_proj[2][2];
		float d = p_proj[3][2];

		matrix = p_proj * p_view;

		m_planesEx[NEARP].a = matrix[0][3] + matrix[0][2];
		m_planesEx[NEARP].b = matrix[1][3] + matrix[1][2];
		m_planesEx[NEARP].c = matrix[2][3] + matrix[2][2];
		m_planesEx[NEARP].d = matrix[3][3] + matrix[3][2];
		NormalizePlane(m_planesEx[NEARP]);

		m_planesEx[FARP].a = matrix[0][3] - matrix[0][2];
		m_planesEx[FARP].b = matrix[1][3] - matrix[1][2];
		m_planesEx[FARP].c = matrix[2][3] - matrix[2][2];
		m_planesEx[FARP].d = matrix[3][3] - matrix[3][2];
		NormalizePlane(m_planesEx[FARP]);

		m_planesEx[LEFT].a = matrix[0][3] + matrix[0][0];
		m_planesEx[LEFT].b = matrix[1][3] + matrix[1][0];
		m_planesEx[LEFT].c = matrix[2][3] + matrix[2][0];
		m_planesEx[LEFT].d = matrix[3][3] + matrix[3][0];
		NormalizePlane(m_planesEx[LEFT]);

		m_planesEx[RIGHT].a = matrix[0][3] - matrix[0][0];
		m_planesEx[RIGHT].b = matrix[1][3] - matrix[1][0];
		m_planesEx[RIGHT].c = matrix[2][3] - matrix[2][0];
		m_planesEx[RIGHT].d = matrix[3][3] - matrix[3][0];
		NormalizePlane(m_planesEx[RIGHT]);

		m_planesEx[TOP].a = matrix[0][3] - matrix[0][1];
		m_planesEx[TOP].b = matrix[1][3] - matrix[1][1];
		m_planesEx[TOP].c = matrix[2][3] - matrix[2][1];
		m_planesEx[TOP].d = matrix[3][3] - matrix[3][1];
		NormalizePlane(m_planesEx[TOP]);
		
		m_planesEx[BOTTOM].a = matrix[0][3] + matrix[0][1];
		m_planesEx[BOTTOM].b = matrix[1][3] + matrix[1][1];
		m_planesEx[BOTTOM].c = matrix[2][3] + matrix[2][1];
		m_planesEx[BOTTOM].d = matrix[3][3] + matrix[3][1];
		NormalizePlane(m_planesEx[BOTTOM]);

		ftl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[TOP], m_planesEx[FARP]);
		fbl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[BOTTOM], m_planesEx[FARP]);

		fbr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[BOTTOM], m_planesEx[FARP]);
		ftr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[TOP], m_planesEx[FARP]);

		ntl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[TOP], m_planesEx[NEARP]);
		nbl = Intersect3Planes(m_planesEx[LEFT], m_planesEx[BOTTOM], m_planesEx[NEARP]);

		nbr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[BOTTOM], m_planesEx[NEARP]);
		ntr = Intersect3Planes(m_planesEx[RIGHT], m_planesEx[TOP], m_planesEx[NEARP]);
	}
void Frustum::Extract(const vec3& eye,const mat4x4& camMatrix,const mat4x4& projMatrix)
{
	m_pos = eye;

	m_modView = camMatrix;
	m_projMatrix = projMatrix;
	mat4x4 MVPMatrix =  m_projMatrix *  m_modView;

	MVPMatrix = glm::transpose(MVPMatrix);
	//left and right planes
	m_planes[0] = MVPMatrix[3] - MVPMatrix[0];
	NormalizePlane(0);

	m_planes[1] = MVPMatrix[3] + MVPMatrix[0];
	NormalizePlane(1);

	//near and far planes
	m_planes[2] = MVPMatrix[3] - MVPMatrix[2];
	NormalizePlane(2);

	m_planes[3] = MVPMatrix[3] + MVPMatrix[2];
	NormalizePlane(3);

	//top and bottom planes
	m_planes[4] = MVPMatrix[3] - MVPMatrix[1];
	NormalizePlane(4);

	m_planes[5] = MVPMatrix[3] + MVPMatrix[1];
	NormalizePlane(5);
	
}
Example #5
0
/*
===============
FindPlane

Returns a global plane number and the side that will be the front
===============
*/
int	FindPlane (plane_t *dplane, int *side)
{
	int			i;
	plane_t		*dp, pl;
	vec_t		dot;
		
	dot = VectorLength(dplane->normal);
	if (dot < 1.0 - ANGLEEPSILON || dot > 1.0 + ANGLEEPSILON)
		Error ("FindPlane: normalization error");
	
	pl = *dplane;
	NormalizePlane (&pl);
	if (DotProduct(pl.normal, dplane->normal) > 0)
		*side = 0;
	else
		*side = 1;

	dp = planes;	
	for (i=0 ; i<numbrushplanes;i++, dp++)
	{
		dot = DotProduct (dp->normal, pl.normal);
		if (dot > 1.0 - ANGLEEPSILON 
		&& fabs(dp->dist - pl.dist) < DISTEPSILON )
		{	// regular match
			return i;		
		}
	}

	if (numbrushplanes == MAX_MAP_PLANES)
		Error ("numbrushplanes == MAX_MAP_PLANES");

	planes[numbrushplanes] = pl;

	numbrushplanes++;

	return numbrushplanes-1;
}
Example #6
0
File: brush.c Project: kellyrm/Q1
/*
===============
FindPlane

Returns a global plane number and the side that will be the front
===============
*/
int	FindPlane (plane_t *dplane, int *side)
{
	int			i;
	plane_t		*dp, pl;
	vec_t		dot;

	dot = VectorLength(dplane->normal);
	if (dot < 1.0 - ANGLEEPSILON || dot > 1.0 + ANGLEEPSILON)
		Message (MSGERR, "FindPlane: Normalization error");

	pl = *dplane;
	NormalizePlane (&pl);
	if (DotProduct(pl.normal, dplane->normal) > 0)
		*side = 0;
	else
		*side = 1;

	dp = planes;
	for (i=0 ; i<numbrushplanes;i++, dp++)
	{
		dot = DotProduct (dp->normal, pl.normal);
		if (dot > 1.0 - ANGLEEPSILON
		&& fabs(dp->dist - pl.dist) < DISTEPSILON )
		{	// regular match
			return i;
		}
	}

        if (validfacesactive)
                ExtendArray(validfaces, numbrushplanes);
	ExtendArray(planes, numbrushplanes);
	planes[numbrushplanes] = pl;

	numbrushplanes++;

	return numbrushplanes-1;
}
Example #7
0
//**************************************************************************************
// Function name    : CFrustum::CalculateFrustum
// Author           : Gary Ingram
// Return type      : void 
// Date Created     : 25/05/2003
// Description      : Calculates the frustum from the modelview and projection 
//                    matrices, The frustrum that is set in this class is a 
//                    static member and so will be the same wherever it is used  
//**************************************************************************************
void CFrustum::CalculateFrustum()
{    
	CMatrix   proj(GL_PROJECTION_MATRIX);
	CMatrix   modl(GL_MODELVIEW_MATRIX);
												//////////////////////////////////////////////
												//Now that we have our modelview and        //
												//projection matrix, if we combine these 2  //
												//matrices, it will give us our clipping    //
												//planes.  To combine 2 matrices, we        //
												//multiply them.                            //
												//////////////////////////////////////////////

	CMatrix clip(proj*modl);

												//////////////////////////////////////////////
												//Now we actually want to get the sides of  //
												//the frustum.  To do this we take the      //
												//clipping planes we received above and     //
												//extract the sides from them.              //
												//////////////////////////////////////////////


												//////////////////////////////////////////////
												//This will extract the RIGHT side of the   //
												//frustum                                   //
												//////////////////////////////////////////////

	m_Frustum[RIGHT][A] = clip.element( 3) - clip.element( 0);
	m_Frustum[RIGHT][B] = clip.element( 7) - clip.element( 4);
	m_Frustum[RIGHT][C] = clip.element(11) - clip.element( 8);
	m_Frustum[RIGHT][D] = clip.element(15) - clip.element(12);

												//////////////////////////////////////////////
												//Now that we have a normal (A,B,C) and a   //
												//distance (D) to the plane, we want to     //
												//normalize that normal and distance.       //
												//////////////////////////////////////////////


												//////////////////////////////////////////////
												//Normalize the RIGHT side                  //
												//////////////////////////////////////////////

	NormalizePlane(RIGHT);

												//////////////////////////////////////////////
												//This will extract the LEFT side of the    //
												//frustum                                   //
												//////////////////////////////////////////////

	m_Frustum[LEFT][A] = clip.element( 3) + clip.element( 0);
	m_Frustum[LEFT][B] = clip.element( 7) + clip.element( 4);
	m_Frustum[LEFT][C] = clip.element(11) + clip.element( 8);
	m_Frustum[LEFT][D] = clip.element(15) + clip.element(12);

												//////////////////////////////////////////////
												//Normalize the LEFT side                   //
												//////////////////////////////////////////////

	NormalizePlane(LEFT);

												//////////////////////////////////////////////
												//This will extract the BOTTOM side of the  //
												//frustum                                   //
												//////////////////////////////////////////////

	m_Frustum[BOTTOM][A] = clip.element( 3) + clip.element( 1);
	m_Frustum[BOTTOM][B] = clip.element( 7) + clip.element( 5);
	m_Frustum[BOTTOM][C] = clip.element(11) + clip.element( 9);
	m_Frustum[BOTTOM][D] = clip.element(15) + clip.element(13);

												//////////////////////////////////////////////
												//Normalize the BOTTOM side                 //
												//////////////////////////////////////////////

	NormalizePlane(BOTTOM);

												//////////////////////////////////////////////
												//This will extract the TOP side of the     //
												//Frustum                                   //
												//////////////////////////////////////////////

	m_Frustum[TOP][A] = clip.element( 3) - clip.element( 1);
	m_Frustum[TOP][B] = clip.element( 7) - clip.element( 5);
	m_Frustum[TOP][C] = clip.element(11) - clip.element( 9);
	m_Frustum[TOP][D] = clip.element(15) - clip.element(13);

												//////////////////////////////////////////////
												//Normalize the TOP side                    //
												//////////////////////////////////////////////

	NormalizePlane(TOP);

												//////////////////////////////////////////////
												//This will extract the BACK side of the    //
												//frustum                                   //
												//////////////////////////////////////////////

	m_Frustum[BACK][A] = clip.element( 3) - clip.element( 2);
	m_Frustum[BACK][B] = clip.element( 7) - clip.element( 6);
	m_Frustum[BACK][C] = clip.element(11) - clip.element(10);
	m_Frustum[BACK][D] = clip.element(15) - clip.element(14);

												//////////////////////////////////////////////
												//Normalize the BACK side                   //
												//////////////////////////////////////////////

	NormalizePlane(BACK);

												//////////////////////////////////////////////
												//This will extract the FRONT side of the   //
												//frustum                                   //
												//////////////////////////////////////////////

	m_Frustum[FRONT][A] = clip.element( 3) + clip.element( 2);
	m_Frustum[FRONT][B] = clip.element( 7) + clip.element( 6);
	m_Frustum[FRONT][C] = clip.element(11) + clip.element(10);
	m_Frustum[FRONT][D] = clip.element(15) + clip.element(14);

												//////////////////////////////////////////////
												//Normalize the FRONT side                  //
												//////////////////////////////////////////////

	NormalizePlane(FRONT);

}
Example #8
0
void CFrustum::CalculateFrustum()
{    
	float   proj[16];								// This will hold our projection matrix
	float   modl[16];								// This will hold our modelview matrix
	float   clip[16];								// This will hold the clipping planes

	// glGetFloatv() is used to extract information about our OpenGL world.
	// Below, we pass in GL_PROJECTION_MATRIX to abstract our projection matrix.
	// It then stores the matrix into an array of [16].
	glGetFloatv( GL_PROJECTION_MATRIX, proj );

	// By passing in GL_MODELVIEW_MATRIX, we can abstract our model view matrix.
	// This also stores it in an array of [16].
	glGetFloatv( GL_MODELVIEW_MATRIX, modl );

	// Now that we have our modelview and projection matrix, if we combine these 2 matrices,
	// it will give us our clipping planes.  To combine 2 matrices, we multiply them.

	clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
	clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
	clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
	clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

	clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
	clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
	clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
	clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

	clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
	clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
	clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
	clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

	clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
	clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
	clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
	clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];
	
	// Now we actually want to get the sides of the frustum.  To do this we take
	// the clipping planes we received above and extract the sides from them.

	// This will extract the RIGHT side of the frustum
	m_Frustum[RIGHT][A] = clip[ 3] - clip[ 0];
	m_Frustum[RIGHT][B] = clip[ 7] - clip[ 4];
	m_Frustum[RIGHT][C] = clip[11] - clip[ 8];
	m_Frustum[RIGHT][D] = clip[15] - clip[12];

	// Now that we have a normal (A,B,C) and a distance (D) to the plane,
	// we want to normalize that normal and distance.

	// Normalize the RIGHT side
	NormalizePlane(m_Frustum, RIGHT);

	// This will extract the LEFT side of the frustum
	m_Frustum[LEFT][A] = clip[ 3] + clip[ 0];
	m_Frustum[LEFT][B] = clip[ 7] + clip[ 4];
	m_Frustum[LEFT][C] = clip[11] + clip[ 8];
	m_Frustum[LEFT][D] = clip[15] + clip[12];

	// Normalize the LEFT side
	NormalizePlane(m_Frustum, LEFT);

	// This will extract the BOTTOM side of the frustum
	m_Frustum[BOTTOM][A] = clip[ 3] + clip[ 1];
	m_Frustum[BOTTOM][B] = clip[ 7] + clip[ 5];
	m_Frustum[BOTTOM][C] = clip[11] + clip[ 9];
	m_Frustum[BOTTOM][D] = clip[15] + clip[13];

	// Normalize the BOTTOM side
	NormalizePlane(m_Frustum, BOTTOM);

	// This will extract the TOP side of the frustum
	m_Frustum[TOP][A] = clip[ 3] - clip[ 1];
	m_Frustum[TOP][B] = clip[ 7] - clip[ 5];
	m_Frustum[TOP][C] = clip[11] - clip[ 9];
	m_Frustum[TOP][D] = clip[15] - clip[13];

	// Normalize the TOP side
	NormalizePlane(m_Frustum, TOP);

	// This will extract the BACK side of the frustum
	m_Frustum[BACK][A] = clip[ 3] - clip[ 2];
	m_Frustum[BACK][B] = clip[ 7] - clip[ 6];
	m_Frustum[BACK][C] = clip[11] - clip[10];
	m_Frustum[BACK][D] = clip[15] - clip[14];

	// Normalize the BACK side
	NormalizePlane(m_Frustum, BACK);

	// This will extract the FRONT side of the frustum
	m_Frustum[FRONT][A] = clip[ 3] + clip[ 2];
	m_Frustum[FRONT][B] = clip[ 7] + clip[ 6];
	m_Frustum[FRONT][C] = clip[11] + clip[10];
	m_Frustum[FRONT][D] = clip[15] + clip[14];

	// Normalize the FRONT side
	NormalizePlane(m_Frustum, FRONT);
}
Example #9
0
	//get frustum
	long SmtGLRenderDevice::GetFrustum(SmtFrustum &smtFrustum)
	{
		float   frustum[6][4];

		float   proj[16];								// This will hold our projection matrix
		float   modl[16];								// This will hold our modelview matrix
		float   clip[16];								// This will hold the clipping planes


		glGetFloatv( GL_PROJECTION_MATRIX, proj );
		glGetFloatv( GL_MODELVIEW_MATRIX, modl );

		// Now that we have our modelview and projection matrix, if we combine these 2 matrices,
		// it will give us our clipping planes.  To combine 2 matrices, we multiply them.

		clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
		clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
		clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
		clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

		clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
		clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
		clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
		clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

		clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
		clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
		clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
		clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

		clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
		clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
		clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
		clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];

		// Now we actually want to get the sides of the frustum.  To do this we take
		// the clipping planes we received above and extract the sides from them.

		// This will extract the RIGHT side of the frustum
		frustum[FS_RIGHT][P_A] = clip[ 3] - clip[ 0];
		frustum[FS_RIGHT][P_B] = clip[ 7] - clip[ 4];
		frustum[FS_RIGHT][P_C] = clip[11] - clip[ 8];
		frustum[FS_RIGHT][P_D] = clip[15] - clip[12];

		// Now that we have a normal (A,B,C) and a distance (D) to the plane,
		// we want to normalize that normal and distance.

		// Normalize the RIGHT side
		NormalizePlane(frustum, FS_RIGHT);

		// This will extract the LEFT side of the frustum
		frustum[FS_LEFT][P_A] = clip[ 3] + clip[ 0];
		frustum[FS_LEFT][P_B] = clip[ 7] + clip[ 4];
		frustum[FS_LEFT][P_C] = clip[11] + clip[ 8];
		frustum[FS_LEFT][P_D] = clip[15] + clip[12];

		// Normalize the LEFT side
		NormalizePlane(frustum, FS_LEFT);

		// This will extract the BOTTOM side of the frustum
		frustum[FS_BOTTOM][P_A] = clip[ 3] + clip[ 1];
		frustum[FS_BOTTOM][P_B] = clip[ 7] + clip[ 5];
		frustum[FS_BOTTOM][P_C] = clip[11] + clip[ 9];
		frustum[FS_BOTTOM][P_D] = clip[15] + clip[13];

		// Normalize the BOTTOM side
		NormalizePlane(frustum, FS_BOTTOM);

		// This will extract the TOP side of the frustum
		frustum[FS_TOP][P_A] = clip[ 3] - clip[ 1];
		frustum[FS_TOP][P_B] = clip[ 7] - clip[ 5];
		frustum[FS_TOP][P_C] = clip[11] - clip[ 9];
		frustum[FS_TOP][P_D] = clip[15] - clip[13];

		// Normalize the TOP side
		NormalizePlane(frustum, FS_TOP);

		// This will extract the BACK side of the frustum
		frustum[FS_BACK][P_A] = clip[ 3] - clip[ 2];
		frustum[FS_BACK][P_B] = clip[ 7] - clip[ 6];
		frustum[FS_BACK][P_C] = clip[11] - clip[10];
		frustum[FS_BACK][P_D] = clip[15] - clip[14];

		// Normalize the BACK side
		NormalizePlane(frustum, FS_BACK);

		// This will extract the FRONT side of the frustum
		frustum[FS_FRONT][P_A] = clip[ 3] + clip[ 2];
		frustum[FS_FRONT][P_B] = clip[ 7] + clip[ 6];
		frustum[FS_FRONT][P_C] = clip[11] + clip[10];
		frustum[FS_FRONT][P_D] = clip[15] + clip[14];

		// Normalize the FRONT side
		NormalizePlane(frustum, FS_FRONT);

		smtFrustum.SetFrustum(frustum);

		return SMT_ERR_NONE;
	}
Example #10
0
void Frustum::CalculateFrustum ()
{
	float   proj[16];								// array per projection matrix
	float   modl[16];								// array per modelview matrix
	float   clip[16];								// array per clipping planes

	glGetFloatv( GL_PROJECTION_MATRIX, proj );
	glGetFloatv( GL_MODELVIEW_MATRIX, modl );

	clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
	clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
	clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
	clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

	clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
	clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
	clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
	clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

	clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
	clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
	clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
	clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

	clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
	clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
	clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
	clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];

	// RIGHT side of the frustum
	m_Frustum[RIGHT][A] = clip[ 3] - clip[ 0];
	m_Frustum[RIGHT][B] = clip[ 7] - clip[ 4];
	m_Frustum[RIGHT][C] = clip[11] - clip[ 8];
	m_Frustum[RIGHT][D] = clip[15] - clip[12];

	// Normalize the RIGHT side
	NormalizePlane(m_Frustum, RIGHT);

	// LEFT side of the frustum
	m_Frustum[LEFT][A] = clip[ 3] + clip[ 0];
	m_Frustum[LEFT][B] = clip[ 7] + clip[ 4];
	m_Frustum[LEFT][C] = clip[11] + clip[ 8];
	m_Frustum[LEFT][D] = clip[15] + clip[12];

	// Normalize the LEFT side
	NormalizePlane(m_Frustum, LEFT);

	// BOTTOM side of the frustum
	m_Frustum[BOTTOM][A] = clip[ 3] + clip[ 1];
	m_Frustum[BOTTOM][B] = clip[ 7] + clip[ 5];
	m_Frustum[BOTTOM][C] = clip[11] + clip[ 9];
	m_Frustum[BOTTOM][D] = clip[15] + clip[13];

	// Normalize the BOTTOM side
	NormalizePlane(m_Frustum, BOTTOM);

	// TOP side of the frustum
	m_Frustum[TOP][A] = clip[ 3] - clip[ 1];
	m_Frustum[TOP][B] = clip[ 7] - clip[ 5];
	m_Frustum[TOP][C] = clip[11] - clip[ 9];
	m_Frustum[TOP][D] = clip[15] - clip[13];

	// Normalize the TOP side
	NormalizePlane(m_Frustum, TOP);

	// BACK side of the frustum
	m_Frustum[BACK][A] = clip[ 3] - clip[ 2];
	m_Frustum[BACK][B] = clip[ 7] - clip[ 6];
	m_Frustum[BACK][C] = clip[11] - clip[10];
	m_Frustum[BACK][D] = clip[15] - clip[14];

	// Normalize the BACK side
	NormalizePlane(m_Frustum, BACK);

	// FRONT side of the frustum
	m_Frustum[FRONT][A] = clip[ 3] + clip[ 2];
	m_Frustum[FRONT][B] = clip[ 7] + clip[ 6];
	m_Frustum[FRONT][C] = clip[11] + clip[10];
	m_Frustum[FRONT][D] = clip[15] + clip[14];

	// Normalize the FRONT side
	NormalizePlane(m_Frustum, FRONT);
}