Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

121 righe
3.1 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 EasyCharacterController class
  13. // ------------------
  14. //
  15. //Should try to to make a btKinematicCharacterController for real.
  16. //
  17. #if !defined __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
  18. #define __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
  19. #ifdef HAVE_PHYS_USE_BULLET
  20. #include "core.h"
  21. #include "EasyPhysics.h"
  22. #include <BulletDynamics/Character/btKinematicCharacterController.h>
  23. #endif
  24. namespace lol
  25. {
  26. namespace phys
  27. {
  28. class EasyCharacterController : public EasyPhysic,
  29. public Entity
  30. {
  31. friend class Simulation;
  32. friend class EasyPhysic;
  33. #ifdef HAVE_PHYS_USE_BULLET
  34. public:
  35. EasyCharacterController(WorldEntity* NewOwnerEntity) :
  36. EasyPhysic(NewOwnerEntity),
  37. m_pair_caching_object(NULL),
  38. m_character(NULL),
  39. m_step_height(.0f),
  40. m_base_is_updating(false),
  41. m_base_cached_movement(vec3(0.f)),
  42. m_frame_cached_movement(vec3(0.f)),
  43. m_walk_velocity(vec3(0.f)),
  44. m_current_velocity(vec3(0.f))
  45. {
  46. m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
  47. m_up_axis = 1;
  48. m_gravity = vec3(.0f, -9.81f, .0f);
  49. m_walk_velocity_damping = 0.2f;
  50. }
  51. ~EasyCharacterController()
  52. {
  53. delete m_character;
  54. }
  55. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  56. virtual void InitBodyToGhost();
  57. virtual void AddToSimulation(class Simulation* current_simulation);
  58. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  59. virtual void SetMovementForFrame(vec3 const &MoveQuantity);
  60. virtual void Jump();
  61. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  62. protected:
  63. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  64. virtual char const *GetName();
  65. public:
  66. virtual void TickGame(float seconds);
  67. protected:
  68. virtual btGhostObject* GetGhostObjectInstance();
  69. btPairCachingGhostObject* m_pair_caching_object;
  70. btKinematicCharacterController* m_character;
  71. float m_step_height;
  72. int m_up_axis;
  73. bool m_base_is_updating;
  74. vec3 m_base_cached_movement;
  75. vec3 m_frame_cached_movement;
  76. //----
  77. float m_walk_velocity_damping;
  78. //----
  79. vec3 m_gravity;
  80. //----
  81. vec3 m_walk_velocity;
  82. vec3 m_current_velocity;
  83. #else // NO PHYSIC IMPLEMENTATION
  84. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false) { }
  85. virtual void InitBodyToGhost() { }
  86. virtual void AddToSimulation(class Simulation* current_simulation) { }
  87. virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
  88. virtual void SetMovementForFrame(vec3 const &MoveQuantity) { }
  89. #endif // PHYSIC IMPLEMENTATION
  90. };
  91. } /* namespace phys */
  92. } /* namespace lol */
  93. #endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */