Common.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/util/StdTypes.h>
  7. #include <anki/util/Enum.h>
  8. #include <anki/util/Ptr.h>
  9. #include <anki/Math.h>
  10. #include <Newton.h>
  11. namespace anki
  12. {
  13. // Forward
  14. class PhysicsObject;
  15. class PhysicsWorld;
  16. class PhysicsCollisionShape;
  17. class PhysicsBody;
  18. class PhysicsPlayerController;
  19. /// @addtogroup physics
  20. /// @{
  21. /// PhysicsPtr custom deleter.
  22. class PhysicsPtrDeleter
  23. {
  24. public:
  25. void operator()(PhysicsObject* ptr);
  26. };
  27. /// Smart pointer for physics objects.
  28. template<typename T>
  29. using PhysicsPtr = IntrusivePtr<T, PhysicsPtrDeleter>;
  30. using PhysicsCollisionShapePtr = PhysicsPtr<PhysicsCollisionShape>;
  31. using PhysicsBodyPtr = PhysicsPtr<PhysicsBody>;
  32. using PhysicsPlayerControllerPtr = PhysicsPtr<PhysicsPlayerController>;
  33. /// Material types.
  34. enum class PhysicsMaterialBit : U16
  35. {
  36. NONE = 0,
  37. STATIC_GEOMETRY = 1 << 0,
  38. DYNAMIC_GEOMETRY = 1 << 1,
  39. RAGDOLL = 1 << 2,
  40. PARTICLES = 1 << 3,
  41. ALL = MAX_U16
  42. };
  43. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(PhysicsMaterialBit, inline)
  44. /// Convert newton to AnKi.
  45. ANKI_USE_RESULT inline Quat toAnki(const Quat& q)
  46. {
  47. return Quat(q.y(), q.z(), q.w(), q.x());
  48. }
  49. /// Convert AnKi to Newton.
  50. ANKI_USE_RESULT inline Quat toNewton(const Quat& q)
  51. {
  52. return Quat(q.w(), q.x(), q.y(), q.z());
  53. }
  54. /// Convert newton to AnKi.
  55. ANKI_USE_RESULT inline Mat4 toAnki(const Mat4& m)
  56. {
  57. return m.getTransposed();
  58. }
  59. /// Convert AnKi to Newton.
  60. ANKI_USE_RESULT inline Mat4 toNewton(const Mat4& m)
  61. {
  62. return m.getTransposed();
  63. }
  64. /// @}
  65. } // end namespace anki