⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plane.cpp

📁 小型的3D游戏引擎
💻 CPP
字号:
#include "../global.h"
#include "plane.h"
#include <windows.h>
#include <gl/gl.h>

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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -