PhysicsCollisionShape.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Physics2/Common.h>
  7. #include <AnKi/Util/WeakArray.h>
  8. #include <AnKi/Util/ClassWrapper.h>
  9. namespace anki {
  10. namespace v2 {
  11. /// Wrapper on top of JPH collision shapes.
  12. class PhysicsCollisionShape : public PhysicsObjectBase
  13. {
  14. ANKI_PHYSICS_COMMON_FRIENDS
  15. friend class PhysicsCollisionShapePtrDeleter;
  16. friend class PhysicsPlayerController;
  17. friend class PhysicsBody;
  18. public:
  19. PhysicsCollisionShape(const PhysicsCollisionShape&) = delete;
  20. PhysicsCollisionShape& operator=(const PhysicsCollisionShape&) = delete;
  21. private:
  22. union
  23. {
  24. ClassWrapper<JPH::Shape> m_shapeBase;
  25. ClassWrapper<JPH::BoxShape> m_box;
  26. ClassWrapper<JPH::SphereShape> m_sphere;
  27. ClassWrapper<JPH::CapsuleShape> m_capsule;
  28. ClassWrapper<JPH::ScaledShape> m_scaled; ///< We don't hold a reference to the target shape to avoid locking mutexes twice.
  29. };
  30. PhysicsCollisionShape()
  31. : PhysicsObjectBase(PhysicsObjectType::kCollisionShape)
  32. {
  33. ANKI_ASSERT(&m_shapeBase == static_cast<JPH::Shape*>(&m_box));
  34. ANKI_ASSERT(&m_shapeBase == static_cast<JPH::Shape*>(&m_sphere));
  35. ANKI_ASSERT(&m_shapeBase == static_cast<JPH::Shape*>(&m_capsule));
  36. ANKI_ASSERT(&m_shapeBase == static_cast<JPH::Shape*>(&m_scaled));
  37. }
  38. ~PhysicsCollisionShape()
  39. {
  40. m_shapeBase.destroy();
  41. }
  42. };
  43. } // namespace v2
  44. } // end namespace anki