RigidBody.pkg 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. $#include "RigidBody.h"
  2. /// Rigid body collision event signaling mode.
  3. enum CollisionEventMode
  4. {
  5. COLLISION_NEVER = 0,
  6. COLLISION_ACTIVE,
  7. COLLISION_ALWAYS
  8. };
  9. /// Physics rigid body component.
  10. class RigidBody : public Component
  11. {
  12. public:
  13. /// Set mass. Zero mass makes the body static.
  14. void SetMass(float mass);
  15. /// Set rigid body world-space position.
  16. void SetPosition(Vector3 position);
  17. /// Set rigid body world-space rotation.
  18. void SetRotation(Quaternion rotation);
  19. /// Set rigid body world-space position and rotation.
  20. void SetTransform(const Vector3& position, const Quaternion& rotation);
  21. /// Set linear velocity.
  22. void SetLinearVelocity(Vector3 velocity);
  23. /// Set linear degrees of freedom.
  24. void SetLinearFactor(Vector3 factor);
  25. /// Set linear velocity deactivation threshold.
  26. void SetLinearRestThreshold(float threshold);
  27. /// Set linear velocity damping factor.
  28. void SetLinearDamping(float damping);
  29. /// Set angular velocity.
  30. void SetAngularVelocity(Vector3 angularVelocity);
  31. /// Set angular degrees of freedom.
  32. void SetAngularFactor(Vector3 factor);
  33. /// Set angular velocity deactivation threshold.
  34. void SetAngularRestThreshold(float threshold);
  35. /// Set angular velocity damping factor.
  36. void SetAngularDamping(float factor);
  37. /// Set friction coefficient.
  38. void SetFriction(float friction);
  39. /// Set restitution coefficient.
  40. void SetRestitution(float restitution);
  41. /// Set contact processing threshold.
  42. void SetContactProcessingThreshold(float threshold);
  43. /// Set continuous collision detection swept sphere radius.
  44. void SetCcdRadius(float radius);
  45. /// Set continuous collision detection motion-per-simulation-step threshold. 0 disables, which is the default.
  46. void SetCcdMotionThreshold(float threshold);
  47. /// Set whether gravity is applied to rigid body.
  48. void SetUseGravity(bool enable);
  49. /// Set gravity override. If zero, uses physics world's gravity.
  50. void SetGravityOverride(const Vector3& gravity);
  51. /// Set rigid body kinematic mode. In kinematic mode forces are not applied to the rigid body.
  52. void SetKinematic(bool enable);
  53. /// Set rigid body phantom mode. In phantom mode collisions are reported but do not apply forces.
  54. void SetPhantom(bool enable);
  55. /// Set collision layer.
  56. void SetCollisionLayer(unsigned layer);
  57. /// Set collision mask.
  58. void SetCollisionMask(unsigned mask);
  59. /// Set collision group and mask.
  60. void SetCollisionLayerAndMask(unsigned layer, unsigned mask);
  61. /// Set collision event signaling mode. Default is to signal when rigid bodies are active.
  62. void SetCollisionEventMode(CollisionEventMode mode);
  63. /// Apply force to center of mass.
  64. void ApplyForce(const Vector3& force);
  65. /// Apply force at local position.
  66. void ApplyForce(const Vector3& force, const Vector3& position);
  67. /// Apply torque.
  68. void ApplyTorque(const Vector3& torque);
  69. /// Apply impulse to center of mass.
  70. void ApplyImpulse(const Vector3& impulse);
  71. /// Apply impulse at local position.
  72. void ApplyImpulse(const Vector3& impulse, const Vector3& position);
  73. /// Apply torque impulse.
  74. void ApplyTorqueImpulse(const Vector3& torque);
  75. /// Reset accumulated forces.
  76. void ResetForces();
  77. /// Activate rigid body if it was resting.
  78. void Activate();
  79. /// Readd rigid body to the physics world to clean up internal state like stale contacts.
  80. void ReAddBodyToWorld();
  81. /// Return physics world.
  82. PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
  83. /// Return mass.
  84. float GetMass() const { return mass_; }
  85. /// Return rigid body world-space position.
  86. Vector3 GetPosition() const;
  87. /// Return rigid body world-space rotation.
  88. Quaternion GetRotation() const;
  89. /// Return linear velocity.
  90. Vector3 GetLinearVelocity() const;
  91. /// Return linear degrees of freedom.
  92. Vector3 GetLinearFactor() const;
  93. /// Return linear velocity at local point.
  94. Vector3 GetVelocityAtPoint(const Vector3& position) const;
  95. /// Return linear velocity deactivation threshold.
  96. float GetLinearRestThreshold() const;
  97. /// Return linear velocity damping threshold.
  98. float GetLinearDamping() const;
  99. /// Return linear velocity damping scale.
  100. // float GetLinearDampingScale() const;
  101. /// Return angular velocity.
  102. Vector3 GetAngularVelocity() const;
  103. /// Return angular degrees of freedom.
  104. Vector3 GetAngularFactor() const;
  105. /// Return angular velocity deactivation threshold.
  106. float GetAngularRestThreshold() const;
  107. /// Return angular velocity damping threshold.
  108. float GetAngularDamping() const;
  109. /// Return angular velocity damping scale.
  110. // float GetAngularDampingScale() const;
  111. /// Return friction coefficient.
  112. float GetFriction() const;
  113. /// Return restitution coefficient.
  114. float GetRestitution() const;
  115. /// Return contact processing threshold.
  116. float GetContactProcessingThreshold() const;
  117. /// Return continuous collision detection swept sphere radius.
  118. float GetCcdRadius() const;
  119. /// Return continuous collision detection motion-per-simulation-step threshold.
  120. float GetCcdMotionThreshold() const;
  121. /// Return whether rigid body uses gravity.
  122. bool GetUseGravity() const { return useGravity_; }
  123. /// Return gravity override. If zero (default), uses the physics world's gravity.
  124. const Vector3& GetGravityOverride() const { return gravityOverride_; }
  125. /// Return center of mass offset.
  126. const Vector3& GetCenterOfMass() const { return centerOfMass_; }
  127. /// Return kinematic mode flag.
  128. bool IsKinematic() const { return kinematic_; }
  129. /// Return phantom mode flag.
  130. bool IsPhantom() const { return phantom_; }
  131. /// Return whether rigid body is active (not sleeping.)
  132. bool IsActive() const;
  133. /// Return collision layer.
  134. unsigned GetCollisionLayer() const { return collisionLayer_; }
  135. /// Return collision mask.
  136. unsigned GetCollisionMask() const { return collisionMask_; }
  137. /// Return collision event signaling mode.
  138. CollisionEventMode GetCollisionEventMode() const { return collisionEventMode_; }
  139. /// Apply new world transform after a simulation step. Called internally.
  140. void ApplyWorldTransform(const Vector3& newWorldPosition, const Quaternion& newWorldRotation);
  141. /// Update mass and inertia to the Bullet rigid body.
  142. void UpdateMass();
  143. /// Update gravity parameters to the Bullet rigid body.
  144. void UpdateGravity();
  145. /// Add a constraint that refers to this rigid body.
  146. void AddConstraint(Constraint* constraint);
  147. /// Remove a constraint that refers to this rigid body.
  148. void RemoveConstraint(Constraint* constraint);
  149. /// Remove the rigid body.
  150. void ReleaseBody();
  151. // Properties:
  152. tolua_property__get_set float mass;
  153. tolua_property__get_set Vector3 position;
  154. tolua_property__get_set Quaternion rotation;
  155. tolua_property__get_set Vector3 linearVelocity;
  156. tolua_property__get_set Vector3 linearFactor;
  157. tolua_property__get_set float linearRestThreshold;
  158. tolua_property__get_set float linearDamping;
  159. tolua_property__get_set Vector3 angularVelocity;
  160. tolua_property__get_set Vector3 angularFactor;
  161. tolua_property__get_set float angularRestThreshold;
  162. tolua_property__get_set float angularDamping;
  163. tolua_property__get_set float friction;
  164. tolua_property__get_set float restitution;
  165. tolua_property__get_set float contactProcessingThreshold;
  166. tolua_property__get_set float ccdRadius;
  167. tolua_property__get_set float ccdMotionThreshold;
  168. tolua_property__get_set bool useGravity;
  169. tolua_property__get_set const Vector3& gravityOverride;
  170. tolua_readonly tolua_property__get_set const Vector3& centerOfMass;
  171. tolua_property__is_set bool kinematic;
  172. tolua_property__is_set bool phantom;
  173. tolua_readonly tolua_property__is_set bool active;
  174. tolua_property__get_set unsigned collisionLayer;
  175. tolua_property__get_set unsigned collisionMask;
  176. tolua_property__get_set CollisionEventMode collisionEventMode;
  177. };
  178. ${
  179. #define TOLUA_DISABLE_tolua_get_RigidBody_position
  180. #define tolua_get_RigidBody_position tolua_PhysicsLuaAPI_RigidBody_GetPosition00
  181. #define TOLUA_DISABLE_tolua_get_RigidBody_rotation
  182. #define tolua_get_RigidBody_rotation tolua_PhysicsLuaAPI_RigidBody_GetRotation00
  183. #define TOLUA_DISABLE_tolua_get_RigidBody_linearVelocity
  184. #define tolua_get_RigidBody_linearVelocity tolua_PhysicsLuaAPI_RigidBody_GetLinearVelocity00
  185. #define TOLUA_DISABLE_tolua_get_RigidBody_linearFactor
  186. #define tolua_get_RigidBody_linearFactor tolua_PhysicsLuaAPI_RigidBody_GetLinearFactor00
  187. #define TOLUA_DISABLE_tolua_get_RigidBody_angularVelocity
  188. #define tolua_get_RigidBody_angularVelocity tolua_PhysicsLuaAPI_RigidBody_GetAngularVelocity00
  189. #define TOLUA_DISABLE_tolua_get_RigidBody_angularFactor
  190. #define tolua_get_RigidBody_angularFactor tolua_PhysicsLuaAPI_RigidBody_GetAngularFactor00
  191. $}