optimizedPolyList.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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( NULL ),
  78. vertexCount( 0 ),
  79. object( NULL ),
  80. type( TriangleFan )
  81. {
  82. }
  83. };
  84. // Vertex data
  85. Vector<Point3F> mPoints;
  86. Vector<Point3F> mNormals;
  87. Vector<Point2F> mUV0s;
  88. Vector<Point2F> mUV1s;
  89. // List of the VertIndex structure that puts
  90. // all of the vertex data together
  91. Vector<VertIndex> mVertexList;
  92. // Polygon data
  93. Vector<U32> mIndexList;
  94. Vector<PlaneF> mPlaneList;
  95. Vector<BaseMatInstance*> mMaterialList;
  96. // The Polygon structure puts the vertex data
  97. // and the polygon together
  98. Vector<Poly> mPolyList;
  99. public:
  100. OptimizedPolyList();
  101. ~OptimizedPolyList();
  102. void clear();
  103. // Virtual methods
  104. U32 addPoint(const Point3F& p);
  105. U32 addPlane(const PlaneF& plane);
  106. void begin(BaseMatInstance* material, U32 surfaceKey);
  107. void begin(BaseMatInstance* material, U32 surfaceKey, PolyType type);
  108. void plane(U32 v1, U32 v2, U32 v3);
  109. void plane(const PlaneF& p);
  110. void plane(const U32 index);
  111. void vertex(U32 vi);
  112. void vertex(const Point3F& p);
  113. void vertex(const Point3F& p,
  114. const Point3F& normal,
  115. const Point2F& uv0 = Point2F(0.0f, 0.0f),
  116. const Point2F& uv1 = Point2F(0.0f, 0.0f));
  117. void end();
  118. U32 insertPoint(const Point3F& point);
  119. U32 insertNormal(const Point3F& normal);
  120. U32 insertUV0(const Point2F& uv);
  121. U32 insertUV1(const Point2F& uv);
  122. U32 insertPlane(const PlaneF& plane);
  123. U32 insertMaterial(BaseMatInstance* baseMat);
  124. U32 insertVertex(const Point3F& point,
  125. const Point3F& normal = Point3F(0.0f, 0.0f, 1.0f),
  126. const Point2F& uv0 = Point2F(0.0f, 0.0f),
  127. const Point2F& uv1 = Point2F(0.0f, 0.0f));
  128. bool isEmpty() const;
  129. Polyhedron toPolyhedron() const;
  130. protected:
  131. const PlaneF& getIndexedPlane(const U32 index);
  132. };
  133. #endif // _OPTIMIZEDPOLYLIST_H_