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.
 
 
 

109 rivejä
3.0 KiB

  1. //
  2. // Lol Engine — Bullet physics test
  3. //
  4. // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  5. // © 2012—2018 Sam Hocevar <sam@hocevar.net>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #pragma once
  14. //
  15. // The EasyCharacterController class
  16. // ------------------
  17. //
  18. //Should try to to make a btKinematicCharacterController for real.
  19. //
  20. #include <lol/engine.h>
  21. #include "easyphysics.h"
  22. #include "bulletcharactercontroller.h"
  23. #include <BulletDynamics/Character/btKinematicCharacterController.h>
  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. public:
  34. EasyCharacterController(WorldEntity* NewOwnerEntity) :
  35. EasyPhysic(NewOwnerEntity),
  36. m_pair_caching_object(nullptr),
  37. m_character(nullptr),
  38. m_step_height(.0f),
  39. m_base_is_updating(false),
  40. m_base_cached_movement(vec3(0.f)),
  41. m_frame_cached_movement(vec3(0.f)),
  42. m_walk_velocity(vec3(0.f)),
  43. m_current_velocity(vec3(0.f))
  44. {
  45. m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
  46. m_up_axis = 1;
  47. m_gravity = vec3(.0f, -9.81f, .0f);
  48. m_walk_velocity_damping = 0.2f;
  49. }
  50. ~EasyCharacterController()
  51. {
  52. delete m_character;
  53. }
  54. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  55. virtual void InitBodyToGhost();
  56. virtual void AddToSimulation(class Simulation* current_simulation);
  57. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  58. virtual void SetMovementForFrame(vec3 const &MoveQuantity);
  59. virtual void Jump();
  60. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  61. protected:
  62. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  63. virtual std::string GetName();
  64. public:
  65. virtual void tick_game(float seconds);
  66. protected:
  67. virtual btGhostObject* GetGhostObjectInstance();
  68. btPairCachingGhostObject* m_pair_caching_object;
  69. //btKinematicCharacterController* m_character;
  70. BulletKinematicCharacterController* 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. };
  84. } /* namespace phys */
  85. } /* namespace lol */