Common.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright (C) 2009-2021, 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/Util/StdTypes.h>
  7. #include <AnKi/Util/Enum.h>
  8. #include <AnKi/Util/Ptr.h>
  9. #include <AnKi/Math.h>
  10. #if ANKI_COMPILER_GCC_COMPATIBLE
  11. # pragma GCC diagnostic push
  12. # pragma GCC diagnostic ignored "-Wall"
  13. # pragma GCC diagnostic ignored "-Wconversion"
  14. # pragma GCC diagnostic ignored "-Wfloat-conversion"
  15. # if(ANKI_COMPILER_GCC && __GNUC__ >= 9) || (ANKI_COMPILER_CLANG && __clang_major__ >= 10)
  16. # pragma GCC diagnostic ignored "-Wdeprecated-copy"
  17. # endif
  18. #endif
  19. #if ANKI_COMPILER_MSVC
  20. # pragma warning(push)
  21. # pragma warning(disable : 4305)
  22. #endif
  23. #define BT_THREADSAFE 0
  24. #define BT_NO_PROFILE 1
  25. #include <btBulletCollisionCommon.h>
  26. #include <btBulletDynamicsCommon.h>
  27. #include <BulletCollision/CollisionDispatch/btGhostObject.h>
  28. #include <BulletDynamics/Character/btKinematicCharacterController.h>
  29. #include <BulletCollision/Gimpact/btGImpactShape.h>
  30. #if ANKI_COMPILER_GCC_COMPATIBLE
  31. # pragma GCC diagnostic pop
  32. #endif
  33. #if ANKI_COMPILER_MSVC
  34. # pragma warning(pop)
  35. #endif
  36. namespace anki
  37. {
  38. #define ANKI_PHYS_LOGI(...) ANKI_LOG("PHYS", NORMAL, __VA_ARGS__)
  39. #define ANKI_PHYS_LOGE(...) ANKI_LOG("PHYS", ERROR, __VA_ARGS__)
  40. #define ANKI_PHYS_LOGW(...) ANKI_LOG("PHYS", WARNING, __VA_ARGS__)
  41. #define ANKI_PHYS_LOGF(...) ANKI_LOG("PHYS", FATAL, __VA_ARGS__)
  42. // Forward
  43. class PhysicsObject;
  44. class PhysicsFilteredObject;
  45. class PhysicsWorld;
  46. class PhysicsCollisionShape;
  47. class PhysicsBody;
  48. class PhysicsPlayerController;
  49. class PhysicsJoint;
  50. class PhysicsTrigger;
  51. /// @addtogroup physics
  52. /// @{
  53. /// PhysicsPtr custom deleter.
  54. class PhysicsPtrDeleter
  55. {
  56. public:
  57. void operator()(PhysicsObject* ptr);
  58. };
  59. /// Smart pointer for physics objects.
  60. template<typename T>
  61. using PhysicsPtr = IntrusivePtr<T, PhysicsPtrDeleter>;
  62. using PhysicsObjectPtr = PhysicsPtr<PhysicsObject>;
  63. using PhysicsFilteredObjectPtr = PhysicsPtr<PhysicsFilteredObject>;
  64. using PhysicsCollisionShapePtr = PhysicsPtr<PhysicsCollisionShape>;
  65. using PhysicsBodyPtr = PhysicsPtr<PhysicsBody>;
  66. using PhysicsPlayerControllerPtr = PhysicsPtr<PhysicsPlayerController>;
  67. using PhysicsJointPtr = PhysicsPtr<PhysicsJoint>;
  68. using PhysicsTriggerPtr = PhysicsPtr<PhysicsTrigger>;
  69. /// Material types.
  70. enum class PhysicsMaterialBit : U64
  71. {
  72. NONE = 0,
  73. STATIC_GEOMETRY = 1 << 0,
  74. DYNAMIC_GEOMETRY = 1 << 1,
  75. TRIGGER = 1 << 2,
  76. PLAYER = 1 << 3,
  77. PARTICLE = 1 << 4,
  78. ALL = MAX_U64
  79. };
  80. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(PhysicsMaterialBit)
  81. ANKI_USE_RESULT inline Vec3 toAnki(const btVector3& v)
  82. {
  83. return Vec3(v.getX(), v.getY(), v.getZ());
  84. }
  85. ANKI_USE_RESULT inline btVector3 toBt(const Vec3& v)
  86. {
  87. return btVector3(v.x(), v.y(), v.z());
  88. }
  89. ANKI_USE_RESULT inline btTransform toBt(const Transform& a)
  90. {
  91. Mat4 mat(a);
  92. mat.transpose();
  93. btTransform out;
  94. out.setFromOpenGLMatrix(&mat(0, 0));
  95. return out;
  96. }
  97. ANKI_USE_RESULT inline Mat3x4 toAnki(const btMatrix3x3& m)
  98. {
  99. Mat3x4 m3;
  100. m3.setRows(Vec4(toAnki(m[0]), 0.0f), Vec4(toAnki(m[1]), 0.0f), Vec4(toAnki(m[2]), 0.0f));
  101. return m3;
  102. }
  103. ANKI_USE_RESULT inline Transform toAnki(const btTransform& t)
  104. {
  105. Transform out;
  106. out.setRotation(toAnki(t.getBasis()));
  107. out.setOrigin(Vec4(toAnki(t.getOrigin()), 0.0f));
  108. out.setScale(1.0f);
  109. return out;
  110. }
  111. /// @}
  112. } // end namespace anki