99 líneas
2.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 __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
  16. #define __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
  17. #ifdef HAVE_PHYS_USE_BULLET
  18. #include "core.h"
  19. #include "EasyPhysics.h"
  20. #include <BulletDynamics/Character/btKinematicCharacterController.h>
  21. #endif
  22. namespace lol
  23. {
  24. namespace phys
  25. {
  26. class EasyCharacterController : public EasyPhysic,
  27. public Entity
  28. {
  29. #ifdef HAVE_PHYS_USE_BULLET
  30. public:
  31. EasyCharacterController(WorldEntity* NewOwnerEntity) :
  32. EasyPhysic(NewOwnerEntity),
  33. m_pair_caching_object(NULL),
  34. m_character(NULL),
  35. m_step_height(.0f),
  36. m_base_is_updating(false),
  37. m_base_cached_movement(vec3(0.f)),
  38. m_frame_cached_movement(vec3(0.f))
  39. {
  40. m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
  41. m_up_axis = 1;
  42. }
  43. ~EasyCharacterController()
  44. {
  45. delete m_character;
  46. }
  47. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  48. virtual void InitBodyToGhost();
  49. virtual void AddToSimulation(class Simulation* current_simulation);
  50. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  51. virtual void SetMovementForFrame(vec3 const &MoveQuantity);
  52. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  53. protected:
  54. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  55. public:
  56. virtual void TickGame(float seconds);
  57. protected:
  58. virtual btGhostObject* GetGhostObjectInstance();
  59. btPairCachingGhostObject* m_pair_caching_object;
  60. btKinematicCharacterController* m_character;
  61. float m_step_height;
  62. int m_up_axis;
  63. bool m_base_is_updating;
  64. vec3 m_base_cached_movement;
  65. vec3 m_frame_cached_movement;
  66. #else // NO PHYSIC IMPLEMENTATION
  67. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false) { }
  68. virtual void InitBodyToGhost() { }
  69. virtual void AddToSimulation(class Simulation* current_simulation) { }
  70. virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
  71. virtual void SetMovementForFrame(vec3 const &MoveQuantity) { }
  72. #endif // PHYSIC IMPLEMENTATION
  73. };
  74. } /* namespace phys */
  75. } /* namespace lol */
  76. #endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */