| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- $#include "RigidBody.h"
- /// Rigid body collision event signaling mode.
- enum CollisionEventMode
- {
- COLLISION_NEVER = 0,
- COLLISION_ACTIVE,
- COLLISION_ALWAYS
- };
- /// Physics rigid body component.
- class RigidBody : public Component
- {
- public:
- /// Set mass. Zero mass makes the body static.
- void SetMass(float mass);
- /// Set rigid body world-space position.
- void SetPosition(Vector3 position);
- /// Set rigid body world-space rotation.
- void SetRotation(Quaternion rotation);
- /// Set rigid body world-space position and rotation.
- void SetTransform(const Vector3& position, const Quaternion& rotation);
- /// Set linear velocity.
- void SetLinearVelocity(Vector3 velocity);
- /// Set linear degrees of freedom.
- void SetLinearFactor(Vector3 factor);
- /// Set linear velocity deactivation threshold.
- void SetLinearRestThreshold(float threshold);
- /// Set linear velocity damping factor.
- void SetLinearDamping(float damping);
- /// Set angular velocity.
- void SetAngularVelocity(Vector3 angularVelocity);
- /// Set angular degrees of freedom.
- void SetAngularFactor(Vector3 factor);
- /// Set angular velocity deactivation threshold.
- void SetAngularRestThreshold(float threshold);
- /// Set angular velocity damping factor.
- void SetAngularDamping(float factor);
- /// Set friction coefficient.
- void SetFriction(float friction);
- /// Set restitution coefficient.
- void SetRestitution(float restitution);
- /// Set contact processing threshold.
- void SetContactProcessingThreshold(float threshold);
- /// Set continuous collision detection swept sphere radius.
- void SetCcdRadius(float radius);
- /// Set continuous collision detection motion-per-simulation-step threshold. 0 disables, which is the default.
- void SetCcdMotionThreshold(float threshold);
- /// Set whether gravity is applied to rigid body.
- void SetUseGravity(bool enable);
- /// Set gravity override. If zero, uses physics world's gravity.
- void SetGravityOverride(const Vector3& gravity);
- /// Set rigid body kinematic mode. In kinematic mode forces are not applied to the rigid body.
- void SetKinematic(bool enable);
- /// Set rigid body phantom mode. In phantom mode collisions are reported but do not apply forces.
- void SetPhantom(bool enable);
- /// Set collision layer.
- void SetCollisionLayer(unsigned layer);
- /// Set collision mask.
- void SetCollisionMask(unsigned mask);
- /// Set collision group and mask.
- void SetCollisionLayerAndMask(unsigned layer, unsigned mask);
- /// Set collision event signaling mode. Default is to signal when rigid bodies are active.
- void SetCollisionEventMode(CollisionEventMode mode);
- /// Apply force to center of mass.
- void ApplyForce(const Vector3& force);
- /// Apply force at local position.
- void ApplyForce(const Vector3& force, const Vector3& position);
- /// Apply torque.
- void ApplyTorque(const Vector3& torque);
- /// Apply impulse to center of mass.
- void ApplyImpulse(const Vector3& impulse);
- /// Apply impulse at local position.
- void ApplyImpulse(const Vector3& impulse, const Vector3& position);
- /// Apply torque impulse.
- void ApplyTorqueImpulse(const Vector3& torque);
- /// Reset accumulated forces.
- void ResetForces();
- /// Activate rigid body if it was resting.
- void Activate();
- /// Readd rigid body to the physics world to clean up internal state like stale contacts.
- void ReAddBodyToWorld();
-
- /// Return physics world.
- PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
- /// Return mass.
- float GetMass() const { return mass_; }
- /// Return rigid body world-space position.
- Vector3 GetPosition() const;
- /// Return rigid body world-space rotation.
- Quaternion GetRotation() const;
- /// Return linear velocity.
- Vector3 GetLinearVelocity() const;
- /// Return linear degrees of freedom.
- Vector3 GetLinearFactor() const;
- /// Return linear velocity at local point.
- Vector3 GetVelocityAtPoint(const Vector3& position) const;
- /// Return linear velocity deactivation threshold.
- float GetLinearRestThreshold() const;
- /// Return linear velocity damping threshold.
- float GetLinearDamping() const;
- /// Return linear velocity damping scale.
- // float GetLinearDampingScale() const;
- /// Return angular velocity.
- Vector3 GetAngularVelocity() const;
- /// Return angular degrees of freedom.
- Vector3 GetAngularFactor() const;
- /// Return angular velocity deactivation threshold.
- float GetAngularRestThreshold() const;
- /// Return angular velocity damping threshold.
- float GetAngularDamping() const;
- /// Return angular velocity damping scale.
- // float GetAngularDampingScale() const;
- /// Return friction coefficient.
- float GetFriction() const;
- /// Return restitution coefficient.
- float GetRestitution() const;
- /// Return contact processing threshold.
- float GetContactProcessingThreshold() const;
- /// Return continuous collision detection swept sphere radius.
- float GetCcdRadius() const;
- /// Return continuous collision detection motion-per-simulation-step threshold.
- float GetCcdMotionThreshold() const;
- /// Return whether rigid body uses gravity.
- bool GetUseGravity() const { return useGravity_; }
- /// Return gravity override. If zero (default), uses the physics world's gravity.
- const Vector3& GetGravityOverride() const { return gravityOverride_; }
- /// Return center of mass offset.
- const Vector3& GetCenterOfMass() const { return centerOfMass_; }
- /// Return kinematic mode flag.
- bool IsKinematic() const { return kinematic_; }
- /// Return phantom mode flag.
- bool IsPhantom() const { return phantom_; }
- /// Return whether rigid body is active (not sleeping.)
- bool IsActive() const;
- /// Return collision layer.
- unsigned GetCollisionLayer() const { return collisionLayer_; }
- /// Return collision mask.
- unsigned GetCollisionMask() const { return collisionMask_; }
- /// Return collision event signaling mode.
- CollisionEventMode GetCollisionEventMode() const { return collisionEventMode_; }
-
- /// Apply new world transform after a simulation step. Called internally.
- void ApplyWorldTransform(const Vector3& newWorldPosition, const Quaternion& newWorldRotation);
- /// Update mass and inertia to the Bullet rigid body.
- void UpdateMass();
- /// Update gravity parameters to the Bullet rigid body.
- void UpdateGravity();
- /// Add a constraint that refers to this rigid body.
- void AddConstraint(Constraint* constraint);
- /// Remove a constraint that refers to this rigid body.
- void RemoveConstraint(Constraint* constraint);
- /// Remove the rigid body.
- void ReleaseBody();
-
- // Properties:
- tolua_property__get_set float mass;
- tolua_property__get_set Vector3 position;
- tolua_property__get_set Quaternion rotation;
- tolua_property__get_set Vector3 linearVelocity;
- tolua_property__get_set Vector3 linearFactor;
- tolua_property__get_set float linearRestThreshold;
- tolua_property__get_set float linearDamping;
- tolua_property__get_set Vector3 angularVelocity;
- tolua_property__get_set Vector3 angularFactor;
- tolua_property__get_set float angularRestThreshold;
- tolua_property__get_set float angularDamping;
- tolua_property__get_set float friction;
- tolua_property__get_set float restitution;
- tolua_property__get_set float contactProcessingThreshold;
- tolua_property__get_set float ccdRadius;
- tolua_property__get_set float ccdMotionThreshold;
- tolua_property__get_set bool useGravity;
- tolua_property__get_set const Vector3& gravityOverride;
- tolua_readonly tolua_property__get_set const Vector3& centerOfMass;
- tolua_property__is_set bool kinematic;
- tolua_property__is_set bool phantom;
- tolua_readonly tolua_property__is_set bool active;
- tolua_property__get_set unsigned collisionLayer;
- tolua_property__get_set unsigned collisionMask;
- tolua_property__get_set CollisionEventMode collisionEventMode;
- };
- ${
- #define TOLUA_DISABLE_tolua_get_RigidBody_position
- #define tolua_get_RigidBody_position tolua_PhysicsLuaAPI_RigidBody_GetPosition00
- #define TOLUA_DISABLE_tolua_get_RigidBody_rotation
- #define tolua_get_RigidBody_rotation tolua_PhysicsLuaAPI_RigidBody_GetRotation00
- #define TOLUA_DISABLE_tolua_get_RigidBody_linearVelocity
- #define tolua_get_RigidBody_linearVelocity tolua_PhysicsLuaAPI_RigidBody_GetLinearVelocity00
- #define TOLUA_DISABLE_tolua_get_RigidBody_linearFactor
- #define tolua_get_RigidBody_linearFactor tolua_PhysicsLuaAPI_RigidBody_GetLinearFactor00
- #define TOLUA_DISABLE_tolua_get_RigidBody_angularVelocity
- #define tolua_get_RigidBody_angularVelocity tolua_PhysicsLuaAPI_RigidBody_GetAngularVelocity00
- #define TOLUA_DISABLE_tolua_get_RigidBody_angularFactor
- #define tolua_get_RigidBody_angularFactor tolua_PhysicsLuaAPI_RigidBody_GetAngularFactor00
- $}
|