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.

easycharactercontroller.h 3.5 KiB

преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // (c) 2009-2013 Benjamin "Touky" 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://www.wtfpl.net/ 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 "bulletcharactercontroller.h"
  23. #include <BulletDynamics/Character/btKinematicCharacterController.h>
  24. #endif
  25. namespace lol
  26. {
  27. namespace phys
  28. {
  29. class EasyCharacterController : public EasyPhysic,
  30. public Entity
  31. {
  32. friend class Simulation;
  33. friend class EasyPhysic;
  34. #ifdef HAVE_PHYS_USE_BULLET
  35. public:
  36. EasyCharacterController(WorldEntity* NewOwnerEntity) :
  37. EasyPhysic(NewOwnerEntity),
  38. m_pair_caching_object(NULL),
  39. m_character(NULL),
  40. m_step_height(.0f),
  41. m_base_is_updating(false),
  42. m_base_cached_movement(vec3(0.f)),
  43. m_frame_cached_movement(vec3(0.f)),
  44. m_walk_velocity(vec3(0.f)),
  45. m_current_velocity(vec3(0.f))
  46. {
  47. m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
  48. m_up_axis = 1;
  49. m_gravity = vec3(.0f, -9.81f, .0f);
  50. m_walk_velocity_damping = 0.2f;
  51. }
  52. ~EasyCharacterController()
  53. {
  54. delete m_character;
  55. }
  56. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  57. virtual void InitBodyToGhost();
  58. virtual void AddToSimulation(class Simulation* current_simulation);
  59. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  60. virtual void SetMovementForFrame(vec3 const &MoveQuantity);
  61. virtual void Jump();
  62. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  63. protected:
  64. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  65. virtual char const *GetName();
  66. public:
  67. virtual void TickGame(float seconds);
  68. protected:
  69. virtual btGhostObject* GetGhostObjectInstance();
  70. btPairCachingGhostObject* m_pair_caching_object;
  71. //btKinematicCharacterController* m_character;
  72. BulletKinematicCharacterController* m_character;
  73. float m_step_height;
  74. int m_up_axis;
  75. bool m_base_is_updating;
  76. vec3 m_base_cached_movement;
  77. vec3 m_frame_cached_movement;
  78. //----
  79. float m_walk_velocity_damping;
  80. //----
  81. vec3 m_gravity;
  82. //----
  83. vec3 m_walk_velocity;
  84. vec3 m_current_velocity;
  85. #else // NO PHYSIC IMPLEMENTATION
  86. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false) { }
  87. virtual void InitBodyToGhost() { }
  88. virtual void AddToSimulation(class Simulation* current_simulation) { }
  89. virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
  90. virtual void SetMovementForFrame(vec3 const &MoveQuantity) { }
  91. #endif // PHYSIC IMPLEMENTATION
  92. };
  93. } /* namespace phys */
  94. } /* namespace lol */
  95. #endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */