00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTEXTTRIANGLEPROCESSOR_H
00030 #define NVBLASTEXTTRIANGLEPROCESSOR_H
00031
00032 #include <PxVec2.h>
00033 #include <PxVec3.h>
00034 #include <vector>
00035 #include <algorithm>
00036
00037 using namespace physx;
00038
00039
00040 namespace Nv
00041 {
00042 namespace Blast
00043 {
00044
00048 struct TrPrcTriangle
00049 {
00050 PxVec3 points[3];
00051 TrPrcTriangle(PxVec3 a = PxVec3(0.0f), PxVec3 b = PxVec3(0.0f), PxVec3 c = PxVec3(0.0f))
00052 {
00053 points[0] = a;
00054 points[1] = b;
00055 points[2] = c;
00056 }
00057
00058 TrPrcTriangle& operator=(const TrPrcTriangle& b)
00059 {
00060 points[0] = b.points[0];
00061 points[1] = b.points[1];
00062 points[2] = b.points[2];
00063 return *this;
00064 }
00065
00066 TrPrcTriangle(const TrPrcTriangle& b)
00067 {
00068 points[0] = b.points[0];
00069 points[1] = b.points[1];
00070 points[2] = b.points[2];
00071 }
00072 PxVec3 getNormal() const
00073 {
00074 return (points[1] - points[0]).cross(points[2] - points[0]);
00075 }
00076 };
00077
00081 struct TrPrcTriangle2d
00082 {
00083 PxVec2 points[3];
00084 TrPrcTriangle2d(PxVec2 a = PxVec2(0.0f), PxVec2 b = PxVec2(0.0f), PxVec2 c = PxVec2(0.0f))
00085 {
00086 points[0] = a;
00087 points[1] = b;
00088 points[2] = c;
00089 }
00090
00091 TrPrcTriangle2d operator=(const TrPrcTriangle2d& b)
00092 {
00093 points[0] = b.points[0];
00094 points[1] = b.points[1];
00095 points[2] = b.points[2];
00096 return *this;
00097 }
00098
00099 TrPrcTriangle2d(const TrPrcTriangle2d& b)
00100 {
00101 points[0] = b.points[0];
00102 points[1] = b.points[1];
00103 points[2] = b.points[2];
00104 }
00105 };
00106
00107 class TriangleProcessor
00108 {
00109 public:
00110 TriangleProcessor(){};
00111 ~TriangleProcessor() {}
00112
00113
00124 uint32_t getTriangleIntersection(TrPrcTriangle& a, TrPrcTriangle2d& aProjected, TrPrcTriangle& b, PxVec3& centroid,
00125 std::vector<PxVec3>& intersectionBuffer, PxVec3 normal);
00126
00133 bool triangleBoundingBoxIntersection(TrPrcTriangle2d& a, TrPrcTriangle2d& b);
00134
00135
00142 uint32_t isPointInside(const PxVec2& point, const TrPrcTriangle2d& triangle);
00143
00153 uint32_t getSegmentIntersection(const PxVec2& s1, const PxVec2& e1, const PxVec2& s2, const PxVec2& e2, PxF32& t1);
00154
00158 void sortToCCW(std::vector<PxVec3>& points, PxVec3& normal);
00159
00166 void buildConvexHull(std::vector<PxVec3>& points, std::vector<PxVec3>& convexHull, const PxVec3& normal);
00167 };
00168
00169 }
00170 }
00171
00172
00173 #endif // NVBLASTEXTTRIANGLEPROCESSOR_H