Common.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #define ANKI_PHYS_LOGI(...) ANKI_LOG("PHYS", NORMAL, __VA_ARGS__)
  38. #define ANKI_PHYS_LOGE(...) ANKI_LOG("PHYS", ERROR, __VA_ARGS__)
  39. #define ANKI_PHYS_LOGW(...) ANKI_LOG("PHYS", WARNING, __VA_ARGS__)
  40. #define ANKI_PHYS_LOGF(...) ANKI_LOG("PHYS", FATAL, __VA_ARGS__)
  41. // Forward
  42. class PhysicsObject;
  43. class PhysicsFilteredObject;
  44. class PhysicsWorld;
  45. class PhysicsCollisionShape;
  46. class PhysicsBody;
  47. class PhysicsPlayerController;
  48. class PhysicsJoint;
  49. class PhysicsTrigger;
  50. /// @addtogroup physics
  51. /// @{
  52. /// PhysicsPtr custom deleter.
  53. class PhysicsPtrDeleter
  54. {
  55. public:
  56. void operator()(PhysicsObject* ptr);
  57. };
  58. /// Smart pointer for physics objects.
  59. template<typename T>
  60. using PhysicsPtr = IntrusivePtr<T, PhysicsPtrDeleter>;
  61. using PhysicsObjectPtr = PhysicsPtr<PhysicsObject>;
  62. using PhysicsFilteredObjectPtr = PhysicsPtr<PhysicsFilteredObject>;
  63. using PhysicsCollisionShapePtr = PhysicsPtr<PhysicsCollisionShape>;
  64. using PhysicsBodyPtr = PhysicsPtr<PhysicsBody>;
  65. using PhysicsPlayerControllerPtr = PhysicsPtr<PhysicsPlayerController>;
  66. using PhysicsJointPtr = PhysicsPtr<PhysicsJoint>;
  67. using PhysicsTriggerPtr = PhysicsPtr<PhysicsTrigger>;
  68. /// Material types.
  69. enum class PhysicsMaterialBit : U64
  70. {
  71. NONE = 0,
  72. STATIC_GEOMETRY = 1 << 0,
  73. DYNAMIC_GEOMETRY = 1 << 1,
  74. TRIGGER = 1 << 2,
  75. PLAYER = 1 << 3,
  76. PARTICLE = 1 << 4,
  77. ALL = MAX_U64
  78. };
  79. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(PhysicsMaterialBit)
  80. ANKI_USE_RESULT inline Vec3 toAnki(const btVector3& v)
  81. {
  82. return Vec3(v.getX(), v.getY(), v.getZ());
  83. }
  84. ANKI_USE_RESULT inline btVector3 toBt(const Vec3& v)
  85. {
  86. return btVector3(v.x(), v.y(), v.z());
  87. }
  88. ANKI_USE_RESULT inline btTransform toBt(const Transform& a)
  89. {
  90. Mat4 mat(a);
  91. mat.transpose();
  92. btTransform out;
  93. out.setFromOpenGLMatrix(&mat(0, 0));
  94. return out;
  95. }
  96. ANKI_USE_RESULT inline Mat3x4 toAnki(const btMatrix3x3& m)
  97. {
  98. Mat3x4 m3;
  99. m3.setRows(Vec4(toAnki(m[0]), 0.0f), Vec4(toAnki(m[1]), 0.0f), Vec4(toAnki(m[2]), 0.0f));
  100. return m3;
  101. }
  102. ANKI_USE_RESULT inline Transform toAnki(const btTransform& t)
  103. {
  104. Transform out;
  105. out.setRotation(toAnki(t.getBasis()));
  106. out.setOrigin(Vec4(toAnki(t.getOrigin()), 0.0f));
  107. out.setScale(1.0f);
  108. return out;
  109. }
  110. /// @}
  111. } // end namespace anki