extrudedPolyList.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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;
  51. };
  52. struct Poly {
  53. PlaneF plane;
  54. SceneObject* object;
  55. BaseMatInstance* material;
  56. };
  57. struct ExtrudedFace {
  58. bool active;
  59. PlaneF plane;
  60. F32 maxDistance;
  61. U32 planeMask;
  62. F32 faceDot;
  63. F32 faceShift;
  64. F32 time;
  65. Point3F point;
  66. F32 height;
  67. };
  68. typedef Vector<ExtrudedFace> ExtrudedList;
  69. typedef Vector<PlaneF> PlaneList;
  70. typedef Vector<Vertex> VertexList;
  71. typedef Vector<U32> IndexList;
  72. static F32 EqualEpsilon;
  73. static F32 FaceEpsilon;
  74. // Internal data
  75. VertexList mVertexList;
  76. IndexList mIndexList;
  77. ExtrudedList mExtrudedList;
  78. PlaneList mPlaneList;
  79. VectorF mVelocity;
  80. VectorF mNormalVelocity;
  81. F32 mFaceShift;
  82. Poly mPoly;
  83. // Returned info
  84. CollisionList* mCollisionList;
  85. PlaneList mPolyPlaneList;
  86. //
  87. private:
  88. bool testPoly(ExtrudedFace&);
  89. public:
  90. ExtrudedPolyList();
  91. ~ExtrudedPolyList();
  92. void extrude(const Polyhedron&, const VectorF& vec);
  93. void setVelocity(const VectorF& velocity);
  94. void setCollisionList(CollisionList*);
  95. void adjustCollisionTime();
  96. // Virtual methods
  97. bool isEmpty() const;
  98. U32 addPoint(const Point3F& p);
  99. U32 addPlane(const PlaneF& plane);
  100. void begin(BaseMatInstance* material, U32 surfaceKey);
  101. void plane(U32 v1,U32 v2,U32 v3);
  102. void plane(const PlaneF& p);
  103. void plane(const U32 index);
  104. void vertex(U32 vi);
  105. void end();
  106. protected:
  107. const PlaneF& getIndexedPlane(const U32 index);
  108. };
  109. #endif