Actor.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "Types.h"
  25. #include "IdArray.h"
  26. #include "PhysicsTypes.h"
  27. #include "Vector3.h"
  28. #include "Matrix4x4.h"
  29. #include "Quaternion.h"
  30. #include "PxPhysics.h"
  31. #include "PxScene.h"
  32. #include "PxRigidActor.h"
  33. using physx::PxRigidActor;
  34. using physx::PxMaterial;
  35. using physx::PxScene;
  36. using physx::PxPhysics;
  37. namespace crown
  38. {
  39. struct PhysicsResource;
  40. struct PhysicsConfigResource;
  41. struct Quaternion;
  42. struct Matrix4x4;
  43. struct Unit;
  44. class SceneGraph;
  45. struct Actor
  46. {
  47. Actor(const PhysicsResource* res, const PhysicsConfigResource* config, uint32_t index, PxPhysics* physics, PxScene* scene, SceneGraph& sg, int32_t node, const Vector3& pos, const Quaternion& rot);
  48. ~Actor();
  49. void enable_gravity();
  50. void disable_gravity();
  51. void enable_collision();
  52. void disable_collision();
  53. void set_kinematic();
  54. void clear_kinematic();
  55. /// Returns whether the actor is static (i.e. immovable).
  56. bool is_static() const;
  57. /// Returns whether the actor is dynamic (i.e. driven dy physics).
  58. bool is_dynamic() const;
  59. /// Returns whether the actor is kinematic (i.e. driven by the user).
  60. bool is_kinematic() const;
  61. float linear_damping() const;
  62. void set_linear_damping(float rate);
  63. float angular_damping() const;
  64. void set_angular_damping(float rate);
  65. Vector3 linear_velocity() const;
  66. void set_linear_velocity(const Vector3& vel);
  67. Vector3 angular_velocity() const;
  68. void set_angular_velocity(const Vector3& vel);
  69. void add_impulse(const Vector3& impulse);
  70. void add_impulse_at(const Vector3& impulse, const Vector3& pos);
  71. void push(const Vector3& vel, const float mass);
  72. bool is_sleeping();
  73. void wake_up();
  74. StringId32 name();
  75. private:
  76. void update(const Matrix4x4& pose);
  77. void create_shapes(const PhysicsResource* res, const PhysicsConfigResource* config, PxPhysics* physics);
  78. public:
  79. const PhysicsResource* m_resource;
  80. const PhysicsConfigResource* m_config;
  81. uint32_t m_index;
  82. PxScene* m_scene;
  83. SceneGraph& m_scene_graph;
  84. int32_t m_node;
  85. PxRigidActor* m_actor;
  86. uint32_t m_group;
  87. uint32_t m_mask;
  88. private:
  89. friend class PhysicsWorld;
  90. };
  91. } // namespace crown