recastPolyList.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _RECAST_POLYLIST_H_
  23. #define _RECAST_POLYLIST_H_
  24. #include "collision/abstractPolyList.h"
  25. #include "core/util/tVector.h"
  26. /// Represents polygons in the same manner as the .obj file format. Handy for
  27. /// padding data to Recast, since it expects this data format. At the moment,
  28. /// this class only accepts triangles.
  29. /// @see AbstractPolyList
  30. class RecastPolyList : public AbstractPolyList {
  31. public:
  32. /// @name AbstractPolyList
  33. /// @{
  34. bool isEmpty() const;
  35. U32 addPoint(const Point3F &p);
  36. U32 addPlane(const PlaneF &plane);
  37. void begin(BaseMatInstance *material, U32 surfaceKey);
  38. void plane(U32 v1, U32 v2, U32 v3);
  39. void plane(const PlaneF& p);
  40. void plane(const U32 index);
  41. void vertex(U32 vi);
  42. void end();
  43. /// @}
  44. /// @name Data interface
  45. /// @{
  46. U32 getVertCount() const;
  47. const F32 *getVerts() const;
  48. U32 getTriCount() const;
  49. const S32 *getTris() const;
  50. void clear();
  51. /// @}
  52. void renderWire() const;
  53. /// Default constructor.
  54. RecastPolyList();
  55. /// Default destructor.
  56. ~RecastPolyList();
  57. protected:
  58. /// Number of vertices defined.
  59. U32 nverts;
  60. /// Array of vertex coordinates. Size nverts*3
  61. F32 *verts;
  62. /// Size of vertex array.
  63. U32 vertcap;
  64. /// Number of triangles defined.
  65. U32 ntris;
  66. /// Array of triangle vertex indices. Size ntris*3
  67. S32 *tris;
  68. /// Size of triangle array.
  69. U32 tricap;
  70. /// Index of vertex we're adding to the current triangle.
  71. U8 vidx;
  72. /// Store a list of planes - not actually used.
  73. Vector<PlaneF> planes;
  74. /// Another inherited utility function.
  75. const PlaneF& getIndexedPlane(const U32 index) { return planes[index]; }
  76. private:
  77. };
  78. #endif