Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

108 rader
3.1 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. //
  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. #include <lol/main.h>
  20. #include "easyphysics.h"
  21. #include "bulletcharactercontroller.h"
  22. #include <BulletDynamics/Character/btKinematicCharacterController.h>
  23. namespace lol
  24. {
  25. namespace phys
  26. {
  27. class EasyCharacterController : public EasyPhysic,
  28. public Entity
  29. {
  30. friend class Simulation;
  31. friend class EasyPhysic;
  32. public:
  33. EasyCharacterController(WorldEntity* NewOwnerEntity) :
  34. EasyPhysic(NewOwnerEntity),
  35. m_pair_caching_object(NULL),
  36. m_character(NULL),
  37. m_step_height(.0f),
  38. m_base_is_updating(false),
  39. m_base_cached_movement(vec3(0.f)),
  40. m_frame_cached_movement(vec3(0.f)),
  41. m_walk_velocity(vec3(0.f)),
  42. m_current_velocity(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. m_walk_velocity_damping = 0.2f;
  48. }
  49. ~EasyCharacterController()
  50. {
  51. delete m_character;
  52. }
  53. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  54. virtual void InitBodyToGhost();
  55. virtual void AddToSimulation(class Simulation* current_simulation);
  56. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  57. virtual void SetMovementForFrame(vec3 const &MoveQuantity);
  58. virtual void Jump();
  59. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  60. protected:
  61. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  62. virtual char const *GetName();
  63. public:
  64. virtual void TickGame(float seconds);
  65. protected:
  66. virtual btGhostObject* GetGhostObjectInstance();
  67. btPairCachingGhostObject* m_pair_caching_object;
  68. //btKinematicCharacterController* m_character;
  69. BulletKinematicCharacterController* m_character;
  70. float m_step_height;
  71. int m_up_axis;
  72. bool m_base_is_updating;
  73. vec3 m_base_cached_movement;
  74. vec3 m_frame_cached_movement;
  75. //----
  76. float m_walk_velocity_damping;
  77. //----
  78. vec3 m_gravity;
  79. //----
  80. vec3 m_walk_velocity;
  81. vec3 m_current_velocity;
  82. };
  83. } /* namespace phys */
  84. } /* namespace lol */
  85. #endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */