Beispiel #1
0
 // is this plane reverse equal to the other plane
 // true if dot product of outward normals is <= (-1+tol) and abs(d1+d2) <= tol
 bool Plane::reverseEqual(const Plane& other, double tol) const
 {
   double dot = (m_a*other.a() + m_b*other.b() + m_c*other.c());
   double dist = m_d + other.d();
   bool result = (dot <= -1+tol) && (fabs(dist) <= tol);
   return result;
 }
Beispiel #2
0
 // is this plane equal to the other plane
 // true if dot product of outward normals is >= (1-tol) and abs(d1-d2) <= tol
 bool Plane::equal(const Plane& other, double tol) const
 {
   double dot = (m_a*other.a() + m_b*other.b() + m_c*other.c());
   double dist = m_d - other.d();
   bool result = (dot >= 1-tol) && (fabs(dist) <= tol);
   return result;
 }
Beispiel #3
0
 bool Plane::parallel(const Plane& other, double tol) const
 {
   // dot product of outward normals should be 1 or negative 1
   double dot = (m_a*other.a() + m_b*other.b() + m_c*other.c());
   bool result = (fabs(dot) >= 1.0-tol);
   return result;
 }
Beispiel #4
0
 Plane::Plane(const Plane& other)
   : m_a(other.a()), m_b(other.b()), m_c(other.c()), m_d(other.d())
 {
   // test that normal has length 1
   double length = m_a*m_a + m_b*m_b + m_c*m_c;
   double tol = 0.0001;
   OS_ASSERT(fabs(1.0-length) < tol);
 }
Beispiel #5
0
void Frustum::extract(const Matrix4f &projmatrix,const Matrix4f &viewmatrix)
{
	planes->clear();

	Plane plane;
	Matrix4f matr;

	matr=viewmatrix*projmatrix;
	
//	matr.dumpMatrix();
//	Kernel::logger() << "\n";
	
	// Left
	plane.a(matr[3]+matr[0]);
	plane.b(matr[7]+matr[4]);
	plane.c(matr[11]+matr[8]);
	plane.d(matr[15]+matr[12]);
	plane.d(plane.d()/plane.normal().length());
	plane.normal().normalize();
	planes->push_back(plane);
	
	// Right
	plane.a(matr[3]-matr[0]);
	plane.b(matr[7]-matr[4]);
	plane.c(matr[11]-matr[8]);
	plane.d(matr[15]-matr[12]);
	plane.d(plane.d()/plane.normal().length());
	plane.normal().normalize();
	planes->push_back(plane);

	// Bottom
	plane.a(matr[3]+matr[1]);
	plane.b(matr[7]+matr[5]);
	plane.c(matr[11]+matr[9]);
	plane.d(matr[15]+matr[13]);
	plane.d(plane.d()/plane.normal().length());
	plane.normal().normalize();
	planes->push_back(plane);

	// Top
	plane.a(matr[3]-matr[1]);
	plane.b(matr[7]-matr[5]);
	plane.c(matr[11]-matr[9]);
	plane.d(matr[15]-matr[13]);
	plane.d(plane.d()/plane.normal().length());
	plane.normal().normalize();
	planes->push_back(plane);

	// Near
	plane.a(matr[3]+matr[2]);
	plane.b(matr[7]+matr[6]);
	plane.c(matr[11]+matr[10]);
	plane.d(matr[15]+matr[14]);
	plane.d(plane.d()/plane.normal().length());
	plane.normal().normalize();
	planes->push_back(plane);
		
	// Far
	plane.a(matr[3]-matr[2]);
	plane.b(matr[7]-matr[6]);
	plane.c(matr[11]-matr[10]);
	plane.d(matr[15]-matr[14]);
	plane.d(plane.d()/plane.normal().length());
	plane.normal().normalize();

/*	projmatrix->dumpMatrix();
	printf("]\n%.02f %.02f %.02f %.02f\n",
		plane.a(),
		plane.b(),
		plane.c(),
		plane.d());*/

//	planes->push_back(plane);	
/*     p=&frustumPlane[RIGHT];
     p->n.x=m[3]-m[0];
     p->n.y=m[7]-m[4];
     p->n.z=m[11]-m[8];
     p->d=m[15]-m[12];
   
     p=&frustumPlane[LEFT];
     p->n.x=m[3]+m[0];
     p->n.y=m[7]+m[4];
     p->n.z=m[11]+m[8];
     p->d=m[15]+m[12];
   
     p=&frustumPlane[BOTTOM];
     p->n.x=m[3]+m[1];
     p->n.y=m[7]+m[5];
     p->n.z=m[11]+m[9];
     p->d=m[15]+m[13];
   
     p=&frustumPlane[TOP];
     p->n.x=m[3]-m[1];
     p->n.y=m[7]-m[5];
     p->n.z=m[11]-m[9];
     p->d=m[15]-m[13];
   
     p=&frustumPlane[PFAR];
     p->n.x=m[3]-m[2];
     p->n.y=m[7]-m[6];
     p->n.z=m[11]-m[10];
     p->d=m[15]-m[14];
   
     p=&frustumPlane[PNEAR];
     p->n.x=m[3]+m[2];
     p->n.y=m[7]+m[6];
     p->n.z=m[11]+m[10];
     p->d=m[15]+m[14];*/	
}
Beispiel #6
0
//**********************************************************************************
//distace of point from a plane (squared) with sign
double Oriented_squared_distance2(Plane P, CGALpoint x){
	double h = P.a()*x.x()+P.b()*x.y()+P.c()*x.z()+P.d();
	return ((h>0.)-(h<0.))*pow(h,2)/(CGALvector(P.a(),P.b(),P.c())).squared_length();
}