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.
 
 
 

105 rivejä
2.9 KiB

  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. #pragma once
  12. //
  13. // The EasyCharacterController class
  14. // ------------------
  15. //
  16. //Should try to to make a btKinematicCharacterController for real.
  17. //
  18. #include <lol/engine.h>
  19. #include "easyphysics.h"
  20. #include "bulletcharactercontroller.h"
  21. #include <BulletDynamics/Character/btKinematicCharacterController.h>
  22. namespace lol
  23. {
  24. namespace phys
  25. {
  26. class EasyCharacterController : public EasyPhysic,
  27. public Entity
  28. {
  29. friend class Simulation;
  30. friend class EasyPhysic;
  31. public:
  32. EasyCharacterController(WorldEntity* NewOwnerEntity) :
  33. EasyPhysic(NewOwnerEntity),
  34. m_pair_caching_object(NULL),
  35. m_character(NULL),
  36. m_step_height(.0f),
  37. m_base_is_updating(false),
  38. m_base_cached_movement(vec3(0.f)),
  39. m_frame_cached_movement(vec3(0.f)),
  40. m_walk_velocity(vec3(0.f)),
  41. m_current_velocity(vec3(0.f))
  42. {
  43. m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
  44. m_up_axis = 1;
  45. m_gravity = vec3(.0f, -9.81f, .0f);
  46. m_walk_velocity_damping = 0.2f;
  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 Jump();
  58. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  59. protected:
  60. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  61. virtual char const *GetName();
  62. public:
  63. virtual void TickGame(float seconds);
  64. protected:
  65. virtual btGhostObject* GetGhostObjectInstance();
  66. btPairCachingGhostObject* m_pair_caching_object;
  67. //btKinematicCharacterController* m_character;
  68. BulletKinematicCharacterController* m_character;
  69. float m_step_height;
  70. int m_up_axis;
  71. bool m_base_is_updating;
  72. vec3 m_base_cached_movement;
  73. vec3 m_frame_cached_movement;
  74. //----
  75. float m_walk_velocity_damping;
  76. //----
  77. vec3 m_gravity;
  78. //----
  79. vec3 m_walk_velocity;
  80. vec3 m_current_velocity;
  81. };
  82. } /* namespace phys */
  83. } /* namespace lol */