extrudedPolyList.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _EXTRUDEDPOLYLIST_H_
  23. #define _EXTRUDEDPOLYLIST_H_
  24. #ifndef _MMATH_H_
  25. #include "math/mMath.h"
  26. #endif
  27. #ifndef _MPOLYHEDRON_H_
  28. #include "math/mPolyhedron.h"
  29. #endif
  30. #ifndef _TVECTOR_H_
  31. #include "core/util/tVector.h"
  32. #endif
  33. #ifndef _ABSTRACTPOLYLIST_H_
  34. #include "collision/abstractPolyList.h"
  35. #endif
  36. class CollisionList;
  37. //----------------------------------------------------------------------------
  38. /// Extruded Polytope PolyList
  39. ///
  40. /// This class is used primarily for collision detection, by objects which need
  41. /// to check for obstructions along their path. You feed it a polytope to
  42. /// extrude along the direction of movement, and it gives you a list of collisions.
  43. ///
  44. /// @see AbstractPolyList
  45. class ExtrudedPolyList: public AbstractPolyList
  46. {
  47. public:
  48. struct Vertex {
  49. Point3F point;
  50. U32 mask = 0;
  51. };
  52. struct Poly {
  53. PlaneF plane;
  54. SceneObject* object;
  55. BaseMatInstance* material;
  56. Poly() : object(NULL), material(NULL) {}
  57. ~Poly() {}
  58. };
  59. struct ExtrudedFace {
  60. bool active;
  61. PlaneF plane;
  62. F32 maxDistance;
  63. U32 planeMask;
  64. F32 faceDot;
  65. F32 faceShift;
  66. F32 time;
  67. Point3F point;
  68. F32 height;
  69. ExtrudedFace(): active(false), maxDistance(0.0f), planeMask(0), faceDot(0.0f), faceShift(0.0f), time(0.0f), height(0.0f) {}
  70. ~ExtrudedFace() {}
  71. };
  72. typedef Vector<ExtrudedFace> ExtrudedList;
  73. typedef Vector<PlaneF> PlaneList;
  74. typedef Vector<Vertex> VertexList;
  75. typedef Vector<U32> IndexList;
  76. static F32 EqualEpsilon;
  77. static F32 FaceEpsilon;
  78. // Internal data
  79. VertexList mVertexList;
  80. IndexList mIndexList;
  81. ExtrudedList mExtrudedList;
  82. PlaneList mPlaneList;
  83. VectorF mVelocity;
  84. VectorF mNormalVelocity;
  85. Poly mPoly;
  86. // Returned info
  87. CollisionList* mCollisionList;
  88. PlaneList mPolyPlaneList;
  89. //
  90. private:
  91. bool testPoly(ExtrudedFace&);
  92. public:
  93. ExtrudedPolyList();
  94. ~ExtrudedPolyList();
  95. void extrude(const Polyhedron&, const VectorF& vec);
  96. void setVelocity(const VectorF& velocity);
  97. void setCollisionList(CollisionList*);
  98. void adjustCollisionTime();
  99. // Virtual methods
  100. bool isEmpty() const;
  101. U32 addPoint(const Point3F& p);
  102. U32 addPlane(const PlaneF& plane);
  103. void begin(BaseMatInstance* material, U32 surfaceKey);
  104. void plane(U32 v1,U32 v2,U32 v3);
  105. void plane(const PlaneF& p);
  106. void plane(const U32 index);
  107. void vertex(U32 vi);
  108. void end();
  109. protected:
  110. const PlaneF& getIndexedPlane(const U32 index);
  111. };
  112. #endif