www.pudn.com > Gimcrack-v0.0051-Source.zip > plane.cpp


#include "../global.h" 
#include "plane.h" 
#include  
#include  
 
GcPlane::GcPlane( const GcVector3 & normal, const GcVector3 & point ) 
{ 
	m_normal = normal; 
	 
	GcVector3 tmp = point; 
 
	m_distance = -( tmp.DotProduct(m_normal) ); 
} 
 
void GcPlane::SetPlane( const GcVector3 & normal, const GcVector3 & point ) 
{ 
	m_normal = normal; 
	 
	GcVector3 tmp = point; 
 
	m_distance = -( tmp.DotProduct(m_normal) ); 
} 
 
 
void GcPlane::RenderOutlines() 
{ 
	GcVector3 point; 
 
	point = m_normal * m_distance; 
 
	glColor3f(0.5f, 0.0f, 0.0f); 
 
	glPointSize(7); 
 
	glBegin(GL_POINTS); 
		glVertex3fv(point); 
	glEnd(); 
 
 
	glBegin(GL_LINES); 
		glVertex3fv(point); 
		point += m_normal; 
		//point.Normalize(); 
		point *= 2; 
		glVertex3fv(point); 
	glEnd(); 
 
	glPointSize(1.0f); 
} 
 
bool GcPlane::Intersects( GcAABB & aabb ) 
{ 
	if( Distance( aabb.Point(0) ) > 0  || 
		Distance( aabb.Point(1) ) > 0  || 
		Distance( aabb.Point(2) ) > 0  || 
		Distance( aabb.Point(3) ) > 0  || 
		Distance( aabb.Point(4) ) > 0  || 
		Distance( aabb.Point(5) ) > 0  || 
		Distance( aabb.Point(6) ) > 0  || 
		Distance( aabb.Point(7) ) > 0  ) 
		return true; 
 
 
	//for( int i = 0; i < 8; ++i ) 
	//	dbgC.Write("AABB %f %f %f\n", aabb.Point(i).x, aabb.Point(i).y, aabb.Point(i).z ); 
 
 
	//dbgC.Write("***********\n"); 
	//dbgC.Write("***********\n"); 
 
 
	//if( Distance( aabb.GetWorldTranslation() ) < 0 ) 
	//if( Distance( aabb.Point(0) ) < 0 ) 
	//	dbgC.Write("HOLY MACARONI!\n"); 
	//dbgC.Write("Dist: %f", Distance( aabb.GetWorldTranslation() ) ); 
	/*float d = Distance( aabb.GetWorldTranslation() ); 
 
	float proj; 
 
	proj =	( aabb.Extent(X) * ( m_normal * aabb.GetOrthogonal(X) ) ) + 
			( aabb.Extent(Y) * ( m_normal * aabb.GetOrthogonal(Y) ) ) + 
			( aabb.Extent(Z) * ( m_normal * aabb.GetOrthogonal(Z) ) ); 
	 
	if( d <= proj ) 
		return true;*/ 
 
	return false; 
}