controller.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "physics_callback.h"
  25. #include "resource_types.h"
  26. #include "math_types.h"
  27. #include "PxController.h"
  28. #include "PxControllerManager.h"
  29. using physx::PxController;
  30. using physx::PxControllerManager;
  31. using physx::PxPhysics;
  32. using physx::PxScene;
  33. using physx::PxU32;
  34. namespace crown
  35. {
  36. struct SceneGraph;
  37. ///
  38. /// @ingroup Physics
  39. struct Controller
  40. {
  41. Controller(const PhysicsResource* pr, SceneGraph& sg, int32_t node, PxPhysics* physics, PxControllerManager* manager);
  42. ~Controller();
  43. /// Moves the controller to @a pos.
  44. void move(const Vector3& pos);
  45. /// Sets the contoller height.
  46. void set_height(float height);
  47. /// Returns whether the contoller collides upwards.
  48. bool collides_up() const;
  49. /// Returns whether the controller collides downwards.
  50. bool collides_down() const;
  51. /// Returns whether the controller collides sidewards.
  52. bool collides_sides() const;
  53. /// Returns the position of the controller.
  54. Vector3 position() const;
  55. void update();
  56. private:
  57. const PhysicsResource* m_resource;
  58. SceneGraph& m_scene_graph;
  59. int32_t m_node;
  60. PxControllerManager* m_manager;
  61. PxController* m_controller;
  62. PxU32 m_flags;
  63. PhysicsControllerCallback m_callback;
  64. };
  65. } // namespace crown