No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

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