Browse Source

Rename RigidBody::Phantom to RigidBody::Trigger to align it with common terminology for physics.

Alex Parlett 11 years ago
parent
commit
a22a24c0e4

+ 2 - 2
Docs/Reference.dox

@@ -1429,7 +1429,7 @@ CollisionShape provides two APIs for defining the collision geometry. Either set
 
 RigidBodies can be either static or moving. A body is static if its mass is 0, and moving if the mass is greater than 0. Note that the triangle mesh collision shape is not supported for moving objects; it will not collide properly due to limitations in the Bullet library. In this case the convex hull shape can be used instead.
 
-The collision behaviour of a rigid body is controlled by several variables. First, the collision layer and mask define which other objects to collide with: see \ref RigidBody::SetCollisionLayer "SetCollisionLayer()" and \ref RigidBody::SetCollisionMask "SetCollisionMask()". By default a rigid body is on layer 1; the layer will be ANDed with the other body's collision mask to see if the collision should be reported. A rigid body can also be set to \ref RigidBody::SetPhantom "phantom mode" to only report collisions without actually applying collision forces. This can be used to implement trigger areas. Finally, the \ref RigidBody::SetFriction "friction", \ref RigidBody::SetRollingFriction "rolling friction" and \ref RigidBody::SetRestitution "restitution" coefficients (between 0 - 1) control how kinetic energy is transferred in the collisions. Note that rolling friction is by default zero, and if you want for example a sphere rolling on the floor to eventually stop, you need to set a non-zero rolling friction on both the sphere and floor rigid bodies.
+The collision behaviour of a rigid body is controlled by several variables. First, the collision layer and mask define which other objects to collide with: see \ref RigidBody::SetCollisionLayer "SetCollisionLayer()" and \ref RigidBody::SetCollisionMask "SetCollisionMask()". By default a rigid body is on layer 1; the layer will be ANDed with the other body's collision mask to see if the collision should be reported. A rigid body can also be set to \ref RigidBody::SetTrigger "trigger mode" to only report collisions without actually applying collision forces. This can be used to implement trigger areas. Finally, the \ref RigidBody::SetFriction "friction", \ref RigidBody::SetRollingFriction "rolling friction" and \ref RigidBody::SetRestitution "restitution" coefficients (between 0 - 1) control how kinetic energy is transferred in the collisions. Note that rolling friction is by default zero, and if you want for example a sphere rolling on the floor to eventually stop, you need to set a non-zero rolling friction on both the sphere and floor rigid bodies.
 
 By default rigid bodies can move and rotate about all 3 coordinate axes when forces are applied. To limit the movement, use \ref RigidBody::SetLinearFactor "SetLinearFactor()" and \ref RigidBody::SetAngularFactor "SetAngularFactor()" and set the axes you wish to use to 1 and those you do not wish to use to 0. For example moving humanoid characters are often represented by a capsule shape: to ensure they stay upright and only rotate when you explicitly set the rotation in code, set the angular factor to 0, 0, 0.
 
@@ -1459,7 +1459,7 @@ Note that if the rendering framerate is high, the physics might not be stepped a
 
 \section Physics_Collision Reading collision events
 
-A new or ongoing physics collision event will report the collided scene nodes and rigid bodies, whether either of the bodies is a phantom, and the list of contact points.
+A new or ongoing physics collision event will report the collided scene nodes and rigid bodies, whether either of the bodies is a trigger, and the list of contact points.
 
 The contact points are encoded in a byte buffer, which can be read using the VectorBuffer or MemoryBuffer helper class. The following structure repeats for each contact:
 

+ 3 - 3
Source/Engine/LuaScript/pkgs/Physics/RigidBody.pkg

@@ -31,7 +31,7 @@ class RigidBody : public Component
     void SetUseGravity(bool enable);
     void SetGravityOverride(const Vector3& gravity);
     void SetKinematic(bool enable);
-    void SetPhantom(bool enable);
+    void SetTrigger(bool enable);
     void SetCollisionLayer(unsigned layer);
     void SetCollisionMask(unsigned mask);
     void SetCollisionLayerAndMask(unsigned layer, unsigned mask);
@@ -71,7 +71,7 @@ class RigidBody : public Component
     const Vector3& GetGravityOverride() const;
     const Vector3& GetCenterOfMass() const;
     bool IsKinematic() const;
-    bool IsPhantom() const;
+    bool IsTrigger() const;
     bool IsActive() const;
     unsigned GetCollisionLayer() const;
     unsigned GetCollisionMask() const;
@@ -100,7 +100,7 @@ class RigidBody : public Component
     tolua_property__get_set Vector3& gravityOverride;
     tolua_readonly tolua_property__get_set Vector3& centerOfMass;
     tolua_property__is_set bool kinematic;
-    tolua_property__is_set bool phantom;
+    tolua_property__is_set bool trigger;
     tolua_readonly tolua_property__is_set bool active;
     tolua_property__get_set unsigned collisionLayer;
     tolua_property__get_set unsigned collisionMask;

+ 2 - 2
Source/Engine/Physics/PhysicsWorld.cpp

@@ -674,7 +674,7 @@ void PhysicsWorld::SendCollisionEvents()
             WeakPtr<Node> nodeWeakA(nodeA);
             WeakPtr<Node> nodeWeakB(nodeB);
 
-            bool phantom = bodyA->IsPhantom() || bodyB->IsPhantom();
+            bool phantom = bodyA->IsTrigger() || bodyB->IsTrigger();
             bool newCollision = !previousCollisions_.Contains(i->first_);
 
             physicsCollisionData_[PhysicsCollision::P_NODEA] = nodeA;
@@ -766,7 +766,7 @@ void PhysicsWorld::SendCollisionEvents()
                 if (!bodyA || !bodyB)
                     continue;
 
-                bool phantom = bodyA->IsPhantom() || bodyB->IsPhantom();
+                bool phantom = bodyA->IsTrigger() || bodyB->IsTrigger();
 
                 // Skip collision event signaling if both objects are static, or if collision event mode does not match
                 if (bodyA->GetMass() == 0.0f && bodyB->GetMass() == 0.0f)

+ 6 - 6
Source/Engine/Physics/RigidBody.cpp

@@ -74,7 +74,7 @@ RigidBody::RigidBody(Context* context) :
     lastPosition_(Vector3::ZERO),
     lastRotation_(Quaternion::IDENTITY),
     kinematic_(false),
-    phantom_(false),
+    trigger_(false),
     useGravity_(true),
     hasSmoothedTransform_(false),
     readdBody_(false),
@@ -126,7 +126,7 @@ void RigidBody::RegisterObject(Context* context)
     ENUM_ATTRIBUTE(RigidBody, "Collision Event Mode", collisionEventMode_, collisionEventModeNames, COLLISION_ACTIVE, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(RigidBody, VAR_BOOL, "Use Gravity", GetUseGravity, SetUseGravity, bool, true, AM_DEFAULT);
     ATTRIBUTE(RigidBody, VAR_BOOL, "Is Kinematic", kinematic_, false, AM_DEFAULT);
-    ATTRIBUTE(RigidBody, VAR_BOOL, "Is Phantom", phantom_, false, AM_DEFAULT);
+    ATTRIBUTE(RigidBody, VAR_BOOL, "Is Trigger", trigger_, false, AM_DEFAULT);
     REF_ACCESSOR_ATTRIBUTE(RigidBody, VAR_VECTOR3, "Gravity Override", GetGravityOverride, SetGravityOverride, Vector3, Vector3::ZERO, AM_DEFAULT);
 }
 
@@ -456,11 +456,11 @@ void RigidBody::SetKinematic(bool enable)
     }
 }
 
-void RigidBody::SetPhantom(bool enable)
+void RigidBody::SetTrigger(bool enable)
 {
-    if (enable != phantom_)
+    if (enable != trigger_)
     {
-        phantom_ = enable;
+        trigger_ = enable;
         AddBodyToWorld();
         MarkNetworkUpdate();
     }
@@ -960,7 +960,7 @@ void RigidBody::AddBodyToWorld()
     UpdateGravity();
 
     int flags = body_->getCollisionFlags();
-    if (phantom_)
+    if (trigger_)
         flags |= btCollisionObject::CF_NO_CONTACT_RESPONSE;
     else
         flags &= ~btCollisionObject::CF_NO_CONTACT_RESPONSE;

+ 5 - 5
Source/Engine/Physics/RigidBody.h

@@ -116,8 +116,8 @@ public:
     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 rigid body trigger mode. In trigger mode collisions are reported but do not apply forces.
+    void SetTrigger(bool enable);
     /// Set collision layer.
     void SetCollisionLayer(unsigned layer);
     /// Set collision mask.
@@ -197,8 +197,8 @@ public:
     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 this RigidBody is acting as a trigger.
+    bool IsTrigger() const { return trigger_; }
     /// Return whether rigid body is active (not sleeping.)
     bool IsActive() const;
     /// Return collision layer.
@@ -274,7 +274,7 @@ private:
     /// Kinematic flag.
     bool kinematic_;
     /// Phantom flag.
-    bool phantom_;
+    bool trigger_;
     /// Use gravity flag.
     bool useGravity_;
     /// Smoothed transform mode.

+ 2 - 2
Source/Engine/Script/PhysicsAPI.cpp

@@ -173,8 +173,8 @@ static void RegisterRigidBody(asIScriptEngine* engine)
     engine->RegisterObjectMethod("RigidBody", "void set_gravityOverride(const Vector3&in)", asMETHOD(RigidBody, SetGravityOverride), asCALL_THISCALL);
     engine->RegisterObjectMethod("RigidBody", "const Vector3& get_gravityOverride() const", asMETHOD(RigidBody, GetGravityOverride), asCALL_THISCALL);
     engine->RegisterObjectMethod("RigidBody", "const Vector3& get_centerOfMass() const", asMETHOD(RigidBody, GetCenterOfMass), asCALL_THISCALL);
-    engine->RegisterObjectMethod("RigidBody", "void set_phantom(bool)", asMETHOD(RigidBody, SetPhantom), asCALL_THISCALL);
-    engine->RegisterObjectMethod("RigidBody", "bool get_phantom() const", asMETHOD(RigidBody, IsPhantom), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody", "void set_trigger(bool)", asMETHOD(RigidBody, SetTrigger), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RigidBody", "bool get_trigger() const", asMETHOD(RigidBody, IsTrigger), asCALL_THISCALL);
     engine->RegisterObjectMethod("RigidBody", "void set_kinematic(bool)", asMETHOD(RigidBody, SetKinematic), asCALL_THISCALL);
     engine->RegisterObjectMethod("RigidBody", "bool get_kinematic() const", asMETHOD(RigidBody, IsKinematic), asCALL_THISCALL);
     engine->RegisterObjectMethod("RigidBody", "bool get_active() const", asMETHOD(RigidBody, IsActive), asCALL_THISCALL);

+ 2 - 2
Source/Samples/13_Ragdolls/Ragdolls.cpp

@@ -151,9 +151,9 @@ void Ragdolls::CreateScene()
             // Create a rigid body and a collision shape. These will act as a trigger for transforming the
             // model into a ragdoll when hit by a moving object
             RigidBody* body = modelNode->CreateComponent<RigidBody>();
-            // The phantom mode makes the rigid body only detect collisions, but impart no forces on the
+            // The Trigger mode makes the rigid body only detect collisions, but impart no forces on the
             // colliding objects
-            body->SetPhantom(true);
+            body->SetTrigger(true);
             CollisionShape* shape = modelNode->CreateComponent<CollisionShape>();
             // Create the capsule shape with an offset so that it is correctly aligned with the model, which
             // has its origin at the feet