You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

127 lines
3.5 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 "LolPhysics.h"
  20. #endif
  21. namespace lol
  22. {
  23. namespace phys
  24. {
  25. class EasyPhysic
  26. {
  27. friend class EasyConstraint;
  28. #ifdef HAVE_PHYS_USE_BULLET
  29. public:
  30. EasyPhysic();
  31. ~EasyPhysic();
  32. virtual void SetShapeToBox(lol::vec3& box_size);
  33. virtual void SetShapeToSphere(float radius);
  34. virtual void SetShapeToCone(float radius, float height);
  35. virtual void SetShapeToCylinder(lol::vec3& cyl_size);
  36. virtual void SetShapeToCapsule(float radius, float height);
  37. virtual bool CanChangeCollisionChannel() { return (m_rigid_body == NULL); }
  38. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)));
  39. virtual void SetMass(float mass);
  40. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  41. virtual void InitBodyToGhost();
  42. virtual void AddToSimulation(class Simulation* current_simulation);
  43. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  44. virtual mat4 GetTransform();
  45. protected:
  46. virtual void SetLocalInertia(float mass);
  47. virtual void SetShapeTo(btCollisionShape* collision_shape);
  48. virtual btGhostObject* GetGhostObject();
  49. btCollisionObject* m_collision_object;
  50. btGhostObject* m_ghost_object;
  51. btRigidBody* m_rigid_body;
  52. btVector3 m_local_inertia;
  53. btCollisionShape* m_collision_shape;
  54. btConvexShape* m_convex_shape;
  55. btMotionState* m_motion_state;
  56. #else // NO PHYSIC IMPLEMENTATION
  57. public:
  58. EasyPhysic() { }
  59. virtual void SetShapeToBox(lol::vec3& BoxSize) { }
  60. virtual void SetShapeToSphere(float radius) { }
  61. virtual void SetShapeToCone(float radius, float height) { }
  62. virtual void SetShapeToCylinder(lol::vec3& cyl_size) { }
  63. virtual void SetShapeToCapsule(float radius, float height) { }
  64. virtual bool CanChangeCollisionChannel() { return true; }
  65. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { }
  66. virtual void SetMass(float mass) { }
  67. virtual void InitBodyToRigid() { }
  68. virtual void InitBodyToGhost() { }
  69. virtual void AddToSimulation(class Simulation* current_simulation) { }
  70. virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
  71. virtual mat4 GetTransform() { return mat4(1.0f); }
  72. virtual void InitBodyToGhost() { }
  73. #endif // PHYSIC IMPLEMENTATION
  74. public:
  75. //Sets the collision Group & Mask.
  76. //Mask can change at runtime, not group !
  77. virtual bool SetCollisionChannel(int NewGroup, int NewMask)
  78. {
  79. if (CanChangeCollisionChannel())
  80. {
  81. m_collision_group = (1<<NewGroup);
  82. m_collision_mask = NewMask;
  83. return true;
  84. }
  85. return false;
  86. }
  87. int GetCollisionGroup() { return m_collision_group; }
  88. int GetCollisionMask() { return m_collision_mask; }
  89. protected:
  90. lol::mat4 m_local_to_world;
  91. float m_mass;
  92. int m_collision_group;
  93. int m_collision_mask;
  94. };
  95. } /* namespace phys */
  96. } /* namespace lol */
  97. #endif /* __EASYPHYSICS_EASYPHYSICS_H__ */