Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

93 wiersze
2.5 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
  5. // (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
  6. // (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the Do What The Fuck You Want To
  9. // Public License, Version 2, as published by Sam Hocevar. See
  10. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  11. //
  12. #if defined HAVE_CONFIG_H
  13. # include "config.h"
  14. #endif
  15. #include "../Include/LolBtPhysicsIntegration.h"
  16. #include "../Include/LolPhysics.h"
  17. #include "../Include/EasyCharacterController.h"
  18. namespace lol
  19. {
  20. namespace phys
  21. {
  22. #ifdef HAVE_PHYS_USE_BULLET
  23. //-------------------------------------------------------------------------
  24. //EASY_CHARACTER_CONTROLLER
  25. //--
  26. //Deactivated for Character controller
  27. void EasyCharacterController::InitBodyToRigid(bool ZeroMassIsKinematic)
  28. {
  29. }
  30. //Return correct Ghost Object
  31. btGhostObject* EasyCharacterController::GetGhostObject()
  32. {
  33. return new btPairCachingGhostObject();
  34. }
  35. //Init to Pair caching ghost object, since Character uses that one.
  36. void EasyCharacterController::InitBodyToGhost()
  37. {
  38. EasyPhysic::InitBodyToGhost();
  39. m_pair_caching_object = (btPairCachingGhostObject*)m_ghost_object;
  40. m_ghost_object->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT | m_ghost_object->getCollisionFlags());
  41. }
  42. //Add Physic object to the simulation
  43. void EasyCharacterController::AddToSimulation(class Simulation* current_simulation)
  44. {
  45. EasyPhysic::AddToSimulation(current_simulation);
  46. btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
  47. if (dynamics_world)
  48. {
  49. if (m_character)
  50. delete m_character;
  51. m_character = new btKinematicCharacterController(m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis);
  52. dynamics_world->addAction(m_character);
  53. }
  54. }
  55. //Remove Physic object to the simulation
  56. void EasyCharacterController::RemoveFromSimulation(class Simulation* current_simulation)
  57. {
  58. EasyPhysic::RemoveFromSimulation(current_simulation);
  59. btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
  60. if (dynamics_world)
  61. {
  62. if (m_character)
  63. dynamics_world->removeAction(m_character);
  64. }
  65. }
  66. //Set movement for this frame
  67. void EasyCharacterController::SetMovementForFrame(vec3 const &MoveQuantity)
  68. {
  69. m_character->setWalkDirection(LOL2BT_VEC3(MoveQuantity));
  70. }
  71. #endif // HAVE_PHYS_USE_BULLET
  72. } /* namespace phys */
  73. } /* namespace lol */