Author Topic: What does it mean?  (Read 4050 times)

Farabi

  • Member
  • ****
  • Posts: 968
  • Neuroscience Fans
What does it mean?
« on: June 04, 2012, 02:54:51 AM »
Code: [Select]
CVector3 LP1
CVector3 TP1
 float Dist1 = (LP1-TP1).Dot( Normal );

Code: [Select]
bool CheckLineTri( CVector3 TP1, CVector3 TP2, CVector3 TP3, CVector3 LP1, CVector3 LP2, CVector3 &HitPos)
  {
   CVector3 Normal, IntersectPos;

   // Find Triangle Normal
   Normal = CrossProduct( TP2 - TP1, TP3 - TP1 );
   Normal.Normalize(); // not really needed

   // Find distance from LP1 and LP2 to the plane defined by the triangle
   float Dist1 = (LP1-TP1).Dot( Normal );
   float Dist2 = (LP2-TP1).Dot( Normal );
   if ( (Dist1 * Dist2) >= 0.0f) return false;  // line doesn't cross the triangle.
   if ( Dist1 == Dist2) return false;// line and plane are parallel

   // Find point on the line that intersects with the plane
   IntersectPos = LP1 + (LP2-LP1) * ( -Dist1/(Dist2-Dist1) );

   // Find if the interesection point lies inside the triangle by testing it against all edges
   CVector3 vTest;
   vTest = CrossProduct( Normal, TP2-TP1 );
   if ( Dot( vTest, IntersectPos-TP1) < 0.0f ) return false;
   vTest = CrossProduct( Normal, TP3-TP2 );
   if ( Dot( vTest, IntersectPos-TP2) < 0.0f ) return false;
   vTest = CrossProduct( Normal, TP1-TP3 );
   if ( Dot( vTest, IntersectPos-TP1) < 0.0f ) return false;

   HitPos = IntersectPos;
   return true;
   }


Substract the vector and then multiply with the dot product of normal, or substract and then dot product and put the result to normal?
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: What does it mean?
« Reply #1 on: June 04, 2012, 04:41:20 AM »
Code: [Select]
dist1 = (LP1-TP1) * Normal // "*" == dot product
MREAL macros - when you need floating point arithmetic while assembling!