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 2.8 KiB

12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. {
  44. m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
  45. m_up_axis = 1;
  46. m_gravity = vec3(.0f, -9.81f, .0f);
  47. }
  48. ~EasyCharacterController()
  49. {
  50. delete m_character;
  51. }
  52. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  53. virtual void InitBodyToGhost();
  54. virtual void AddToSimulation(class Simulation* current_simulation);
  55. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  56. virtual void SetMovementForFrame(vec3 const &MoveQuantity);
  57. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  58. protected:
  59. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  60. public:
  61. virtual void TickGame(float seconds);
  62. protected:
  63. virtual btGhostObject* GetGhostObjectInstance();
  64. btPairCachingGhostObject* m_pair_caching_object;
  65. btKinematicCharacterController* m_character;
  66. float m_step_height;
  67. int m_up_axis;
  68. bool m_base_is_updating;
  69. vec3 m_base_cached_movement;
  70. vec3 m_frame_cached_movement;
  71. vec3 m_gravity;
  72. vec3 m_velocity;
  73. #else // NO PHYSIC IMPLEMENTATION
  74. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false) { }
  75. virtual void InitBodyToGhost() { }
  76. virtual void AddToSimulation(class Simulation* current_simulation) { }
  77. virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
  78. virtual void SetMovementForFrame(vec3 const &MoveQuantity) { }
  79. #endif // PHYSIC IMPLEMENTATION
  80. };
  81. } /* namespace phys */
  82. } /* namespace lol */
  83. #endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */