00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WM4INTRTRIANGLE3TRIANGLE3_H
00018 #define WM4INTRTRIANGLE3TRIANGLE3_H
00019
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4Intersector.h"
00022 #include "Wm4Triangle3.h"
00023 #include "Wm4Line3.h"
00024 #include "Wm4Plane3.h"
00025
00026 namespace Wm4
00027 {
00028
00029 template <class Real>
00030 class WM4_FOUNDATION_ITEM IntrTriangle3Triangle3
00031 : public Intersector<Real,Vector3<Real> >
00032 {
00033 public:
00034 IntrTriangle3Triangle3 (const Triangle3<Real>& rkTriangle0,
00035 const Triangle3<Real>& rkTriangle1);
00036
00037
00038 const Triangle3<Real>& GetTriangle0 () const;
00039 const Triangle3<Real>& GetTriangle1 () const;
00040
00041 bool ReportCoplanarIntersections;
00042
00043
00044 virtual bool Test ();
00045 virtual bool Find ();
00046
00047
00048 virtual bool Test (Real fTMax, const Vector3<Real>& rkVelocity0,
00049 const Vector3<Real>& rkVelocity1);
00050 virtual bool Find (Real fTMax, const Vector3<Real>& rkVelocity0,
00051 const Vector3<Real>& rkVelocity1);
00052
00053
00054 int GetQuantity () const;
00055 const Vector3<Real>& GetPoint (int i) const;
00056
00057 private:
00058 using Intersector<Real,Vector3<Real> >::m_fContactTime;
00059
00060 static void ProjectOntoAxis (const Triangle3<Real>& rkTri,
00061 const Vector3<Real>& rkAxis, Real& rfMin, Real& rfMax);
00062
00063 static void TrianglePlaneRelations (const Triangle3<Real>& rkTriangle,
00064 const Plane3<Real>& rkPlane, Real afDistance[3], int aiSign[3],
00065 int& riPositive, int& riNegative, int& riZero);
00066
00067 static void GetInterval (const Triangle3<Real>& rkTriangle,
00068 const Line3<Real>& rkLine, const Real afDistance[3],
00069 const int aiSign[3], Real afParam[2]);
00070
00071 bool ContainsPoint (const Triangle3<Real>& rkTriangle,
00072 const Plane3<Real>& rkPlane, const Vector3<Real>& rkPoint);
00073
00074 bool IntersectsSegment (const Triangle3<Real>& rkTriangle,
00075 const Vector3<Real>& rkEnd0, const Vector3<Real>& rkEnd1);
00076
00077 bool GetCoplanarIntersection (const Plane3<Real>& rkPlane,
00078 const Triangle3<Real>& rkTri0, const Triangle3<Real>& rkTri1);
00079
00080 static bool TestOverlap (const Vector3<Real>& rkAxis, Real fTMax,
00081 Real fSpeed, Real fUMin, Real fUMax, Real fVMin, Real fVMax,
00082 Real& rfTFirst, Real& rfTLast);
00083
00084 bool TestOverlap (const Vector3<Real>& rkAxis, Real fTMax,
00085 const Vector3<Real>& rkVelocity, Real& rfTFirst, Real& rfTLast);
00086
00087 enum ProjectionMap
00088 {
00089 M2, M11,
00090 M3, M21, M12, M111,
00091 M44, M2_2, M1_1
00092 };
00093
00094 enum ContactSide
00095 {
00096 CS_LEFT,
00097 CS_RIGHT,
00098 CS_NONE
00099 };
00100
00101 class WM4_FOUNDATION_ITEM Configuration
00102 {
00103 public:
00104 ProjectionMap Map;
00105 int Index[8];
00106 Real Min, Max;
00107 };
00108
00109 static void ProjectOntoAxis (const Triangle3<Real>& rkTri,
00110 const Vector3<Real>& rkAxis, Configuration& rkCfg);
00111
00112 bool FindOverlap (const Vector3<Real>& rkAxis, Real fTMax, Real fSpeed,
00113 const Configuration& rkUC, const Configuration& rkVC,
00114 ContactSide& reSide, Configuration& rkTUC, Configuration& rkTVC,
00115 Real& rfTFirst, Real& rfTLast);
00116
00117 bool FindOverlap (const Vector3<Real>& rkAxis, Real fTMax,
00118 const Vector3<Real>& rkVelocity, ContactSide& reSide,
00119 Configuration& rkTCfg0, Configuration& rkTCfg1, Real& rfTFirst,
00120 Real& rfTLast);
00121
00122 void FindContactSet (const Triangle3<Real>& rkTri0,
00123 const Triangle3<Real>& rkTri1, ContactSide& reSide,
00124 Configuration& rkCfg0, Configuration& rkCfg1);
00125
00126 void GetEdgeEdgeIntersection (const Vector3<Real>& rkU0,
00127 const Vector3<Real>& rkU1, const Vector3<Real>& rkV0,
00128 const Vector3<Real>& rkV1);
00129
00130
00131 const Triangle3<Real>& m_rkTriangle0;
00132 const Triangle3<Real>& m_rkTriangle1;
00133
00134
00135 int m_iQuantity;
00136 Vector3<Real> m_akPoint[6];
00137 };
00138
00139 typedef IntrTriangle3Triangle3<float> IntrTriangle3Triangle3f;
00140 typedef IntrTriangle3Triangle3<double> IntrTriangle3Triangle3d;
00141
00142 }
00143
00144 #endif