Ejemplo n.º 1
0
  PlaneSide ClassifyTriangle(const Vec3f &p0, const Vec3f &p1, const Vec3f &p2,
                             const float ep = 0) const {
    const PlaneSide r1 = ClassifyPoint(p0, ep);
    const PlaneSide r2 = ClassifyPoint(p1, ep);
    const PlaneSide r3 = ClassifyPoint(p2, ep);

    if ( r1 == kPlaneCoplanar && r2 == kPlaneCoplanar && r3 == kPlaneCoplanar )
      return kPlaneCoplanar;

    if ( r1 != r2 || r1 != r3 )
      return kPlaneSpanning;

    return r1;
  }
Ejemplo n.º 2
0
bool Terrain::inFrustrum(const Vector& TestPoint)
{	
	HalfSpace ViewLeft  = ClassifyPoint(CameraEye, ViewFrustrum[0], TestPoint);
	HalfSpace ViewRight = ClassifyPoint(CameraEye, ViewFrustrum[1], TestPoint);		
	HalfSpace ViewUp    = ClassifyPoint(CameraEye, ViewFrustrum[2], TestPoint);
	HalfSpace ViewDown  = ClassifyPoint(CameraEye, ViewFrustrum[3], TestPoint);	
	if( ViewLeft == POSITIVE && ViewRight == NEGATIVE && ViewDown == NEGATIVE && ViewUp == POSITIVE)
	{
		return true;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 3
0
bool IsConvexPoly(pFace f1, pFace f2)
{
	int		i;

//	if(NombreDePointsEnCommunEntreDeuxPoly(f1,f2) != 2)
//		return false;

	for(i=0 ; i<f1->NumberOfVertices ; i++)
	if( ClassifyPoint(&f1->point[i],&f2->Plan) == DEVANT)
		return false;
	return true;
}
Ejemplo n.º 4
0
int ClassifyPoly(plan_t *Plan, RECTANGLE *Poly)
{
	int		Infront=0;
	int		Behind=0;
	int		OnPlane=0;
	int		i;

	for(i=0 ; i<Poly->NumberOfVertices ; i++)
	{
		switch(ClassifyPoint(&Poly->point[i],Plan))
		{
			case DEVANT:
			Infront++;
			break;

			case DERRIERE:
			Behind++;
			break;

			default:
			OnPlane++;
			Infront++;
			Behind++;
			break;
		}
	}

	if(OnPlane==Poly->NumberOfVertices)
		return CONFONDU;
	if(Behind==Poly->NumberOfVertices)
		return DERRIERE;
	if(Infront==Poly->NumberOfVertices)
		return DEVANT;

	return AUMILIEU;
}
Ejemplo n.º 5
0
bool Plane::ClipTriangle(Vector3D *inVerts, int totalInVerts,
                         Vector3D *outFrontVerts, int *totalOutFrontVerts,
                         Vector3D *outBackVerts, int *totalOutBackVerts)
{
   if(inVerts == 0 || totalInVerts <= 0 || totalInVerts != 3)
      return false;

   float dist[3] = { 0 };
   int side[3] = { 0 };
   int numFront = 0, numBack = 0;
   int frontIndex = 0, backIndex = 0;

   BB_PLANE_STATUS result = BB_PLANE_FRONT;

   Vector3D tempFront[4];
   Vector3D tempBack[4];

   for(int i = 0; i < 3; i++)
      {
         result = ClassifyPoint(inVerts[i], &dist[i]);

         if(result == BB_PLANE_FRONT)
            {
               side[i] = BB_PLANE_FRONT;
               numFront++;
            }
         if(result == BB_PLANE_BACK)
            {
               side[i] = BB_PLANE_BACK;
               numBack++;
            }
         else
            {
               side[i] = BB_PLANE_FRONT;
               numFront++;
            }
      }

   if(!numBack)
      {
         outFrontVerts = new Vector3D[totalInVerts];
         memcpy(outFrontVerts, inVerts, sizeof(Vector3D) * totalInVerts);

         if(totalOutFrontVerts != NULL)
            *totalOutFrontVerts = totalInVerts;
      }
   else if(!numFront)
      {
         outBackVerts = new Vector3D[totalInVerts];
         memcpy(outBackVerts, inVerts, sizeof(Vector3D) * totalInVerts);

         if(totalOutBackVerts != NULL)
            *totalOutBackVerts = totalInVerts;
      }
   else
      {
         for(int i = 0; i < 3; i++)
            {
               if(side[i] == BB_PLANE_FRONT)
                  {
                     tempFront[frontIndex++] = inVerts[i];
                  }
               else if(side[i] == BB_PLANE_FRONT)
                  {
                     tempBack[backIndex++] = inVerts[i];
                  }

               int j = (i + 1) % 3;

               if(side[i] != side[j])
                  {
                     float t = dist[i] / (dist[i] - dist[j]);
                     Vector3D v = inVerts[i] * (1.0f - t) + inVerts[j] * t;
                     
                     tempFront[frontIndex++] = v;
                     tempBack[backIndex++] = v;
                  }
            }

         if(frontIndex < 4)
            {
               outFrontVerts = new Vector3D[frontIndex];
               memcpy(outFrontVerts, tempFront, sizeof(Vector3D) * frontIndex);

               if(totalOutFrontVerts != NULL)
                  *totalOutFrontVerts = frontIndex;
            }
         else
            {
               outFrontVerts = new Vector3D[6];

               outFrontVerts[0] = tempFront[0];
               outFrontVerts[1] = tempFront[1];
               outFrontVerts[2] = tempFront[2];

               outFrontVerts[3] = tempFront[2];
               outFrontVerts[4] = tempFront[3];
               outFrontVerts[5] = tempFront[0];

               if(totalOutFrontVerts != NULL)
                  *totalOutFrontVerts = 6;
            }

         if(backIndex < 4)
            {
               outBackVerts = new Vector3D[backIndex];
               memcpy(outBackVerts, tempBack, sizeof(Vector3D) * backIndex);

               if(totalOutBackVerts != NULL)
                  *totalOutBackVerts = backIndex;
            }
         else
            {
               outBackVerts = new Vector3D[6];

               outBackVerts[0] = tempBack[0];
               outBackVerts[1] = tempBack[1];
               outBackVerts[2] = tempBack[2];

               outBackVerts[3] = tempBack[2];
               outBackVerts[4] = tempBack[3];
               outBackVerts[5] = tempBack[0];

               if(totalOutBackVerts != NULL)
                  *totalOutBackVerts = 6;
            }
      }

   return true;
}
Ejemplo n.º 6
0
BB_PLANE_STATUS Plane::ClassifyPoint(float x, float y, float z)
{
   return ClassifyPoint(x, y, z, 0);
}
Ejemplo n.º 7
0
BB_PLANE_STATUS Plane::ClassifyPoint(const Vector3D &v, float *dist)
{
   return ClassifyPoint(v.x, v.y, v.z, dist);
}
Ejemplo n.º 8
0
BB_PLANE_STATUS Plane::ClassifyPoint(const Vector3D &v)
{
   return ClassifyPoint(v.x, v.y, v.z, 0);
}