Преглед изворни кода

KinematicRagdollControl : the ragdoll can now be moved using setLocalTranslation on the model while in ragdoll mode.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7498 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
rem..om пре 14 година
родитељ
комит
5468dfe927
1 измењених фајлова са 6 додато и 1 уклоњено
  1. 6 1
      engine/src/jbullet/com/jme3/bullet/control/KinematicRagdollControl.java

+ 6 - 1
engine/src/jbullet/com/jme3/bullet/control/KinematicRagdollControl.java

@@ -125,6 +125,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
     protected float rootMass = 15;
     protected float rootMass = 15;
     protected float totalMass = 0;
     protected float totalMass = 0;
     protected boolean added = false;
     protected boolean added = false;
+  
 
 
     public static enum Mode {
     public static enum Mode {
 
 
@@ -171,7 +172,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
         Quaternion tmpRot2 = vars.quat2;
         Quaternion tmpRot2 = vars.quat2;
 
 
         //if the ragdoll has the control of the skeleton, we update each bone with its position in physic world space.
         //if the ragdoll has the control of the skeleton, we update each bone with its position in physic world space.
-        if (mode == mode.Ragdoll) {
+        if (mode == mode.Ragdoll && targetModel.getLocalTranslation().equals(modelPosition)){                       
             for (PhysicsBoneLink link : boneLinks.values()) {
             for (PhysicsBoneLink link : boneLinks.values()) {
 
 
                 Vector3f position = vars.vect1;
                 Vector3f position = vars.vect1;
@@ -192,12 +193,15 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
 
 
                 //if the bone is the root bone, we apply the physic's transform to the model, so its position and rotation are correctly updated
                 //if the bone is the root bone, we apply the physic's transform to the model, so its position and rotation are correctly updated
                 if (link.bone.getParent() == null) {
                 if (link.bone.getParent() == null) {
+                    
                     //offsetting the physic's position/rotation by the root bone inverse model space position/rotaion
                     //offsetting the physic's position/rotation by the root bone inverse model space position/rotaion
                     modelPosition.set(p).subtractLocal(link.bone.getInitialPos());
                     modelPosition.set(p).subtractLocal(link.bone.getInitialPos());
                     modelRotation.set(q).multLocal(tmpRot2.set(link.bone.getInitialRot()).inverseLocal());
                     modelRotation.set(q).multLocal(tmpRot2.set(link.bone.getInitialRot()).inverseLocal());
+                    
 
 
                     //applying transforms to the model
                     //applying transforms to the model
                     targetModel.setLocalTranslation(modelPosition);
                     targetModel.setLocalTranslation(modelPosition);
+                    
                     targetModel.setLocalRotation(modelRotation);
                     targetModel.setLocalRotation(modelRotation);
 
 
                     //Applying computed transforms to the bone
                     //Applying computed transforms to the bone
@@ -249,6 +253,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
                 }
                 }
                 //setting skeleton transforms to the ragdoll
                 //setting skeleton transforms to the ragdoll
                 matchPhysicObjectToBone(link, position, tmpRot1);
                 matchPhysicObjectToBone(link, position, tmpRot1);
+                modelPosition.set(targetModel.getLocalTranslation());
 
 
             }
             }