您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

136 行
3.4 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
  5. // (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  10. //
  11. //
  12. // The EasyPhysic class
  13. // ------------------
  14. //
  15. #if !defined __EASYPHYSICS_EASYPHYSICS_H__
  16. #define __EASYPHYSICS_EASYPHYSICS_H__
  17. #ifdef HAVE_PHYS_USE_BULLET
  18. #include "core.h"
  19. #include <bullet/btBulletDynamicsCommon.h>
  20. #include <bullet/btBulletCollisionCommon.h>
  21. #endif
  22. namespace lol
  23. {
  24. namespace phys
  25. {
  26. class EasyPhysic
  27. {
  28. #ifdef HAVE_PHYS_USE_BULLET
  29. public:
  30. EasyPhysic();
  31. ~EasyPhysic();
  32. void SetShapeToBox(lol::vec3& box_size);
  33. void SetShapeToSphere(float radius);
  34. void SetShapeToCone(float radius, float height);
  35. void SetShapeToCylinder(lol::vec3& cyl_size);
  36. void SetShapeToCapsule(float radius, float height);
  37. bool CanChangeCollisionChannel() { return (m_rigid_body == NULL); }
  38. void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)));
  39. void SetMass(float mass);
  40. void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  41. void AddToSimulation(class Simulation* current_simulation);
  42. mat4 GetTransform();
  43. protected:
  44. void SetLocalInertia(float mass);
  45. void SetShapeTo(btCollisionShape* collision_shape);
  46. btCollisionObject* m_collision_object;
  47. btRigidBody* m_rigid_body;
  48. btVector3 m_local_inertia;
  49. btCollisionShape* m_collision_shape;
  50. btMotionState* m_motion_state;
  51. #else // NO PHYSIC IMPLEMENTATION
  52. public:
  53. EasyPhysic() { }
  54. void SetShapeToBox(lol::vec3& BoxSize) { }
  55. void SetShapeToSphere(float radius) { }
  56. void SetShapeToCone(float radius, float height) { }
  57. void SetShapeToCylinder(lol::vec3& cyl_size) { }
  58. void SetShapeToCapsule(float radius, float height) { }
  59. bool CanChangeCollisionChannel() { return true; }
  60. void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { }
  61. void SetMass(float mass) { }
  62. void InitBodyToRigid() { }
  63. void AddToSimulation(class Simulation* current_simulation) { }
  64. mat4 GetTransform() { return mat4(1.0f); }
  65. #endif // PHYSIC IMPLEMENTATION
  66. public:
  67. //Sets the collision Group & Mask.
  68. //Mask can change at runtime, not group !
  69. bool SetCollisionChannel(int NewGroup, int NewMask)
  70. {
  71. if (CanChangeCollisionChannel())
  72. {
  73. m_collision_group = (1<<NewGroup);
  74. m_collision_mask = NewMask;
  75. return true;
  76. }
  77. return false;
  78. }
  79. int GetCollisionGroup() { return m_collision_group; }
  80. int GetCollisionMask() { return m_collision_mask; }
  81. protected:
  82. lol::mat4 m_local_to_world;
  83. float m_mass;
  84. int m_collision_group;
  85. int m_collision_mask;
  86. };
  87. class EasyConstraint
  88. {
  89. EasyConstraint()
  90. {
  91. //btPoint2PointConstraint(bA, bB, PivotA, PivotB)
  92. //btHingeConstraint(bA, bB, TransfA, TransfB, UseRefA)
  93. //btSliderConstraint(bA, bB, TransfA, TransfB, UseRefA)
  94. //btConeTwistConstraint(bA, bB, TransfA, TransfB)
  95. //btGeneric6DofConstraint(bA, bB, TransfA, TransfB, UseRefA)
  96. }
  97. #ifdef HAVE_PHYS_USE_BULLET
  98. btTypedConstraint* m_typed_constraint;
  99. #else // NO PHYSIC IMPLEMENTATION
  100. #endif // PHYSIC IMPLEMENTATION
  101. };
  102. } /* namespace phys */
  103. } /* namespace lol */
  104. #endif /* __EASYPHYSICS_EASYPHYSICS_H__ */