PhysicsCollisionShape.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_PHYSICS_PHYSICS_COLLISION_SHAPE_H
  6. #define ANKI_PHYSICS_PHYSICS_COLLISION_SHAPE_H
  7. #include "anki/physics/PhysicsObject.h"
  8. namespace anki {
  9. /// @addtogroup physics
  10. /// @{
  11. /// The base of all collision shapes.
  12. class PhysicsCollisionShape: public PhysicsObject
  13. {
  14. public:
  15. /// Type of supported physics collision shapes.
  16. enum class ShapeType: U8
  17. {
  18. NONE,
  19. SPHERE,
  20. BOX,
  21. STATIC_TRIANGLE_SOUP
  22. };
  23. /// Standard initializer for all collision shapes.
  24. struct Initializer
  25. {
  26. // Empty for now
  27. };
  28. PhysicsCollisionShape(PhysicsWorld* world)
  29. : PhysicsObject(Type::COLLISION_SHAPE, world)
  30. {}
  31. ~PhysicsCollisionShape();
  32. /// @privatesection
  33. /// @{
  34. NewtonCollision* _getNewtonShape() const
  35. {
  36. ANKI_ASSERT(m_shape);
  37. return m_shape;
  38. }
  39. /// @}
  40. protected:
  41. NewtonCollision* m_shape = nullptr;
  42. static I32 m_gid;
  43. };
  44. /// Sphere collision shape.
  45. class PhysicsSphere final: public PhysicsCollisionShape
  46. {
  47. public:
  48. PhysicsSphere(PhysicsWorld* world)
  49. : PhysicsCollisionShape(world)
  50. {}
  51. ~PhysicsSphere()
  52. {}
  53. ANKI_USE_RESULT Error create(Initializer& init, F32 radius);
  54. };
  55. /// Box collision shape.
  56. class PhysicsBox final: public PhysicsCollisionShape
  57. {
  58. public:
  59. PhysicsBox(PhysicsWorld* world)
  60. : PhysicsCollisionShape(world)
  61. {}
  62. ~PhysicsBox()
  63. {}
  64. ANKI_USE_RESULT Error create(Initializer& init, const Vec3& extend);
  65. };
  66. /// Convex hull collision shape.
  67. class PhysicsConvexHull final: public PhysicsCollisionShape
  68. {
  69. public:
  70. PhysicsConvexHull(PhysicsWorld* world)
  71. : PhysicsCollisionShape(world)
  72. {}
  73. ~PhysicsConvexHull()
  74. {}
  75. ANKI_USE_RESULT Error create(Initializer& init,
  76. const Vec3* positions, U32 positionsCount, U32 positionsStride);
  77. };
  78. /// Static triangle mesh shape.
  79. class PhysicsTriangleSoup final: public PhysicsCollisionShape
  80. {
  81. public:
  82. PhysicsTriangleSoup(PhysicsWorld* world)
  83. : PhysicsCollisionShape(world)
  84. {}
  85. ~PhysicsTriangleSoup()
  86. {}
  87. ANKI_USE_RESULT Error create(Initializer& init,
  88. const Vec3* positions, U32 positionsStride,
  89. const U16* indices, U32 indicesCount);
  90. };
  91. /// @}
  92. } // end namespace anki
  93. #endif