選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

129 行
3.4 KiB

  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 "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. friend class BulletKinematicCharacterController;
  36. public:
  37. EasyCharacterController(WorldEntity* NewOwnerEntity) :
  38. EasyPhysic(NewOwnerEntity),
  39. m_pair_caching_object(NULL),
  40. m_character(NULL),
  41. m_step_height(.0f),
  42. m_base_is_updating(false),
  43. m_base_cached_movement(vec3(0.f)),
  44. m_frame_cached_movement(vec3(0.f)),
  45. m_walk_velocity(vec3(0.f)),
  46. m_current_velocity(vec3(0.f))
  47. {
  48. m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
  49. m_up_axis = 1;
  50. m_gravity = vec3(.0f, -9.81f, .0f);
  51. m_walk_velocity_damping = 0.2f;
  52. }
  53. ~EasyCharacterController()
  54. {
  55. delete m_character;
  56. }
  57. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
  58. virtual void InitBodyToGhost();
  59. virtual void AddToSimulation(class Simulation* current_simulation);
  60. virtual void RemoveFromSimulation(class Simulation* current_simulation);
  61. virtual void SetMovementForFrame(vec3 const &MoveQuantity);
  62. virtual void Jump();
  63. virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
  64. protected:
  65. virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
  66. virtual char const *GetName();
  67. public:
  68. virtual void TickGame(float seconds);
  69. protected:
  70. virtual btGhostObject* GetGhostObjectInstance();
  71. btPairCachingGhostObject* m_pair_caching_object;
  72. //btKinematicCharacterController* m_character;
  73. BulletKinematicCharacterController* m_character;
  74. float m_step_height;
  75. int m_up_axis;
  76. bool m_base_is_updating;
  77. vec3 m_base_cached_movement;
  78. vec3 m_frame_cached_movement;
  79. //----
  80. float m_walk_velocity_damping;
  81. //----
  82. vec3 m_gravity;
  83. //----
  84. vec3 m_walk_velocity;
  85. vec3 m_current_velocity;
  86. //Feedback from Bullet collision :
  87. //The idea is : we tell what to do to the BCC at each Hit
  88. int MoveDidImpact(int HitType, const ClosestNotMeConvexResultCallback& SweepCallback);
  89. #else // NO PHYSIC IMPLEMENTATION
  90. virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false) { }
  91. virtual void InitBodyToGhost() { }
  92. virtual void AddToSimulation(class Simulation* current_simulation) { }
  93. virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
  94. virtual void SetMovementForFrame(vec3 const &MoveQuantity) { }
  95. #endif // PHYSIC IMPLEMENTATION
  96. };
  97. } /* namespace phys */
  98. } /* namespace lol */
  99. #endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */