optimizedPolyList.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 _OPTIMIZEDPOLYLIST_H_
  23. #define _OPTIMIZEDPOLYLIST_H_
  24. #ifndef _ABSTRACTPOLYLIST_H_
  25. #include "collision/abstractPolyList.h"
  26. #endif
  27. #ifndef _MPOLYHEDRON_H_
  28. #include "math/mPolyhedron.h"
  29. #endif
  30. #define DEV 0.01
  31. /// A concrete, renderable PolyList
  32. ///
  33. /// This class is used to store geometry from a PolyList query.
  34. ///
  35. /// @see AbstractPolyList
  36. class OptimizedPolyList : public AbstractPolyList
  37. {
  38. public:
  39. enum PolyType
  40. {
  41. TriangleFan,
  42. TriangleStrip,
  43. TriangleList
  44. };
  45. struct VertIndex
  46. {
  47. S32 vertIdx;
  48. S32 normalIdx;
  49. S32 uv0Idx;
  50. S32 uv1Idx;
  51. VertIndex()
  52. : vertIdx( -1 ),
  53. normalIdx ( -1 ),
  54. uv0Idx( -1 ),
  55. uv1Idx( -1 )
  56. {
  57. }
  58. bool operator==(const VertIndex& _test) const
  59. {
  60. return ( vertIdx == _test.vertIdx &&
  61. normalIdx == _test.normalIdx &&
  62. uv0Idx == _test.uv0Idx &&
  63. uv1Idx == _test.uv1Idx );
  64. }
  65. };
  66. struct Poly
  67. {
  68. S32 plane;
  69. S32 material;
  70. U32 vertexStart;
  71. U32 vertexCount;
  72. U32 surfaceKey;
  73. SceneObject* object;
  74. PolyType type;
  75. Poly()
  76. : plane( -1 ),
  77. material( 0 ),
  78. vertexStart(0),
  79. vertexCount( 0 ),
  80. surfaceKey(0),
  81. object( NULL ),
  82. type( TriangleFan )
  83. {
  84. }
  85. };
  86. // Vertex data
  87. Vector<Point3F> mPoints;
  88. Vector<Point3F> mNormals;
  89. Vector<Point2F> mUV0s;
  90. Vector<Point2F> mUV1s;
  91. // List of the VertIndex structure that puts
  92. // all of the vertex data together
  93. Vector<VertIndex> mVertexList;
  94. // Polygon data
  95. Vector<U32> mIndexList;
  96. Vector<PlaneF> mPlaneList;
  97. Vector<BaseMatInstance*> mMaterialList;
  98. // The Polygon structure puts the vertex data
  99. // and the polygon together
  100. Vector<Poly> mPolyList;
  101. public:
  102. OptimizedPolyList();
  103. ~OptimizedPolyList();
  104. void clear();
  105. // Virtual methods
  106. U32 addPoint(const Point3F& p);
  107. U32 addPlane(const PlaneF& plane);
  108. void begin(BaseMatInstance* material, U32 surfaceKey);
  109. void begin(BaseMatInstance* material, U32 surfaceKey, PolyType type);
  110. void plane(U32 v1, U32 v2, U32 v3);
  111. void plane(const PlaneF& p);
  112. void plane(const U32 index);
  113. void vertex(U32 vi);
  114. void vertex(const Point3F& p);
  115. void vertex(const Point3F& p,
  116. const Point3F& normal,
  117. const Point2F& uv0 = Point2F(0.0f, 0.0f),
  118. const Point2F& uv1 = Point2F(0.0f, 0.0f));
  119. void end();
  120. U32 insertPoint(const Point3F& point);
  121. U32 insertNormal(const Point3F& normal);
  122. U32 insertUV0(const Point2F& uv);
  123. U32 insertUV1(const Point2F& uv);
  124. U32 insertPlane(const PlaneF& plane);
  125. U32 insertMaterial(BaseMatInstance* baseMat);
  126. U32 insertVertex(const Point3F& point,
  127. const Point3F& normal = Point3F(0.0f, 0.0f, 1.0f),
  128. const Point2F& uv0 = Point2F(0.0f, 0.0f),
  129. const Point2F& uv1 = Point2F(0.0f, 0.0f));
  130. bool isEmpty() const;
  131. Polyhedron toPolyhedron() const;
  132. protected:
  133. const PlaneF& getIndexedPlane(const U32 index);
  134. };
  135. #endif // _OPTIMIZEDPOLYLIST_H_