2
0

decomposePoly.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef DECOMPOSE_POLY_H
  2. #define DECOMPOSE_POLY_H
  3. #include "core/util/tVector.h"
  4. #include "math/mathTypes.h"
  5. #include "math/mPoint3.h"
  6. struct twoIndices{
  7. U8 i1, i2;
  8. public:
  9. twoIndices();
  10. twoIndices(U8 a, U8 b);
  11. bool operator==(const twoIndices&) const;
  12. };
  13. inline bool twoIndices::operator==(const twoIndices& _test) const
  14. {
  15. return ((i1 == _test.i1) && (i2 == _test.i2) || (i1 == _test.i2) && (i2 == _test.i1));
  16. }
  17. class decompTri
  18. {
  19. private:
  20. U8 mVertIdx[3];
  21. public:
  22. decompTri();
  23. void setVert(U8 val, U8 idx);
  24. U8 getVert(U8 idx);
  25. twoIndices getOtherVerts(U8 idx);
  26. void orderVerts();
  27. };
  28. class decompPoly
  29. {
  30. private:
  31. Vector<Point3F> mVertList;
  32. Vector<twoIndices> mEdgeList;
  33. Vector<U8> mInsideVerts;
  34. Vector<decompTri> mTris;
  35. decompTri mTestTri;
  36. protected:
  37. void initEdgeList();
  38. bool sameSide(Point3F &p1, Point3F &p2, Point3F &l1, Point3F &l2);
  39. bool isInside(decompTri &tri, U8 vertIdx);
  40. U8 leftmost();
  41. U8 rightmost();
  42. U8 uppermost();
  43. U8 lowermost();
  44. twoIndices findEdges(U8 idx, bool &notUnique);
  45. decompTri formTriFromEdges(U8 idx1, U8 idx2);
  46. twoIndices leftmostInsideVerts(U8 idx1, U8 idx2);
  47. twoIndices rightmostInsideVerts(U8 idx1, U8 idx2);
  48. twoIndices uppermostInsideVerts(U8 idx1, U8 idx2);
  49. twoIndices lowermostInsideVerts(U8 idx1, U8 idx2);
  50. void findPointsInside();
  51. void addRemoveEdge(U8 idx1, U8 idx2);
  52. bool isVertInEdgeList(U8 idx);
  53. public:
  54. void addVert(Point3F &newVert);
  55. Point3F getVert(U8 idx);
  56. void newPoly();
  57. U8 getNumVerts() { return mVertList.size(); }
  58. U32 getNumTris() { return mTris.size(); }
  59. U8 getTriIdx(U32 tri, U8 idx);
  60. bool checkEdgeLength(F32 len);
  61. bool decompose();
  62. };
  63. #endif