瀏覽代碼

Do not force RigidBody's interpolation transform when the body is kinematic to allow velocity estimation to work right for dynamic bodies colliding with the kinematic body. Thanks to Andy51.

Lasse Öörni 12 年之前
父節點
當前提交
a833141727
共有 1 個文件被更改,包括 25 次插入12 次删除
  1. 25 12
      Source/Engine/Physics/RigidBody.cpp

+ 25 - 12
Source/Engine/Physics/RigidBody.cpp

@@ -235,9 +235,14 @@ void RigidBody::SetPosition(Vector3 position)
         worldTrans.setOrigin(ToBtVector3(position + ToQuaternion(worldTrans.getRotation()) * centerOfMass_));
         
         // When forcing the physics position, set also interpolated position so that there is no jitter
-        btTransform interpTrans = body_->getInterpolationWorldTransform();
-        interpTrans.setOrigin(worldTrans.getOrigin());
-        body_->setInterpolationWorldTransform(interpTrans);
+        // Do not reset for kinematic objects, so that they can estimate velocity properly
+        if (!kinematic_)
+        {
+            btTransform interpTrans = body_->getInterpolationWorldTransform();
+            interpTrans.setOrigin(worldTrans.getOrigin());
+            body_->setInterpolationWorldTransform(interpTrans);
+        }
+        
         body_->updateInertiaTensor();
 
         Activate();
@@ -256,11 +261,15 @@ void RigidBody::SetRotation(Quaternion rotation)
         if (!centerOfMass_.Equals(Vector3::ZERO))
             worldTrans.setOrigin(ToBtVector3(oldPosition + rotation * centerOfMass_));
 
-        btTransform interpTrans = body_->getInterpolationWorldTransform();
-        interpTrans.setRotation(worldTrans.getRotation());
-        if (!centerOfMass_.Equals(Vector3::ZERO))
-            interpTrans.setOrigin(worldTrans.getOrigin());
-        body_->setInterpolationWorldTransform(interpTrans);
+        if (!kinematic_)
+        {
+            btTransform interpTrans = body_->getInterpolationWorldTransform();
+            interpTrans.setRotation(worldTrans.getRotation());
+            if (!centerOfMass_.Equals(Vector3::ZERO))
+                interpTrans.setOrigin(worldTrans.getOrigin());
+            body_->setInterpolationWorldTransform(interpTrans);
+        }
+        
         body_->updateInertiaTensor();
 
         Activate();
@@ -276,10 +285,14 @@ void RigidBody::SetTransform(const Vector3& position, const Quaternion& rotation
         worldTrans.setRotation(ToBtQuaternion(rotation));
         worldTrans.setOrigin(ToBtVector3(position + rotation * centerOfMass_));
         
-        btTransform interpTrans = body_->getInterpolationWorldTransform();
-        interpTrans.setOrigin(worldTrans.getOrigin());
-        interpTrans.setRotation(worldTrans.getRotation());
-        body_->setInterpolationWorldTransform(interpTrans);
+        if (!kinematic_)
+        {
+            btTransform interpTrans = body_->getInterpolationWorldTransform();
+            interpTrans.setOrigin(worldTrans.getOrigin());
+            interpTrans.setRotation(worldTrans.getRotation());
+            body_->setInterpolationWorldTransform(interpTrans);
+        }
+        
         body_->updateInertiaTensor();
 
         Activate();