Răsfoiți Sursa

Fixed a hack in Bone class for the ragdoll, so Kirill can sleep again.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7303 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
rem..om 14 ani în urmă
părinte
comite
609d975965

+ 16 - 10
engine/src/core/com/jme3/animation/Bone.java

@@ -39,6 +39,7 @@ import com.jme3.export.Savable;
 import com.jme3.math.Matrix3f;
 import com.jme3.math.Matrix3f;
 import com.jme3.math.Matrix4f;
 import com.jme3.math.Matrix4f;
 import com.jme3.math.Quaternion;
 import com.jme3.math.Quaternion;
+import com.jme3.math.Transform;
 import com.jme3.math.Vector3f;
 import com.jme3.math.Vector3f;
 import com.jme3.scene.Node;
 import com.jme3.scene.Node;
 import com.jme3.util.TempVars;
 import com.jme3.util.TempVars;
@@ -92,6 +93,9 @@ public final class Bone implements Savable {
     private Vector3f worldPos = new Vector3f();
     private Vector3f worldPos = new Vector3f();
     private Quaternion worldRot = new Quaternion();
     private Quaternion worldRot = new Quaternion();
     private Vector3f worldScale = new Vector3f();
     private Vector3f worldScale = new Vector3f();
+    
+    //used for getCombinedTransform 
+    private Transform tmpTransform=new Transform();
 
 
     /**
     /**
      * Creates a new bone with the given name.
      * Creates a new bone with the given name.
@@ -372,17 +376,19 @@ public final class Bone implements Savable {
         worldPos.set(translation);
         worldPos.set(translation);
         worldRot.set(rotation);
         worldRot.set(rotation);
     }
     }
-    protected Vector3f tmpVec = new Vector3f();
-    protected Quaternion tmpQuat = new Quaternion();
-
-    public Quaternion getTmpQuat() {
-        return tmpQuat;
-    }
-
-    public Vector3f getTmpVec() {
-        return tmpVec;
+    
+    /**
+     * Returns teh local transform of this bone combined with the given position and rotation
+     * @param position a position
+     * @param rotation a rotation
+     * @return 
+     */
+    public Transform getCombinedTransform(Vector3f position, Quaternion rotation){
+            rotation.mult(localPos, tmpTransform.getTranslation()).addLocal(position);
+            tmpTransform.setRotation(rotation).getRotation().multLocal(localRot);
+            return tmpTransform;
     }
     }
-
+    
     /**
     /**
      * Returns the attachment node.
      * Returns the attachment node.
      * Attach models and effects to this node to make
      * Attach models and effects to this node to make

+ 5 - 10
engine/src/jbullet/com/jme3/bullet/control/RagdollControl.java

@@ -50,6 +50,7 @@ import com.jme3.bullet.objects.PhysicsRigidBody;
 import com.jme3.export.JmeExporter;
 import com.jme3.export.JmeExporter;
 import com.jme3.export.JmeImporter;
 import com.jme3.export.JmeImporter;
 import com.jme3.math.Quaternion;
 import com.jme3.math.Quaternion;
+import com.jme3.math.Transform;
 import com.jme3.math.Vector3f;
 import com.jme3.math.Vector3f;
 import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.ViewPort;
 import com.jme3.renderer.ViewPort;
@@ -83,7 +84,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
     protected Skeleton skeleton;
     protected Skeleton skeleton;
     protected PhysicsSpace space;
     protected PhysicsSpace space;
     protected boolean enabled = true;
     protected boolean enabled = true;
-    protected boolean debug = false;   
+    protected boolean debug = false;
     protected PhysicsRigidBody baseRigidBody;
     protected PhysicsRigidBody baseRigidBody;
     protected float weightThreshold = 1.0f;
     protected float weightThreshold = 1.0f;
     protected Spatial targetModel;
     protected Spatial targetModel;
@@ -186,12 +187,8 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
         bone.setUserTransformsWorld(pos, rot);
         bone.setUserTransformsWorld(pos, rot);
         for (Bone childBone : bone.getChildren()) {
         for (Bone childBone : bone.getChildren()) {
             if (!boneList.contains(childBone.getName())) {
             if (!boneList.contains(childBone.getName())) {
-                Vector3f tmpVec = childBone.getTmpVec();
-                Quaternion tmpQuat = childBone.getTmpQuat();
-                rot.mult(childBone.getLocalPosition(), tmpVec).addLocal(pos);
-                tmpQuat.set(rot).multLocal(childBone.getLocalRotation());
-                setTransform(childBone, tmpVec, tmpQuat);
-
+                Transform t = childBone.getCombinedTransform(pos, rot);
+                setTransform(childBone, t.getTranslation(), t.getRotation());
             }
             }
         }
         }
     }
     }
@@ -592,7 +589,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
             }
             }
         }
         }
 
 
-        if (hit && event.getAppliedImpulse() > eventDispatchImpulseThreshold) {       
+        if (hit && event.getAppliedImpulse() > eventDispatchImpulseThreshold) {
             for (RagdollCollisionListener listener : listeners) {
             for (RagdollCollisionListener listener : listeners) {
                 listener.collide(hitBone, hitObject, event);
                 listener.collide(hitBone, hitObject, event);
             }
             }
@@ -680,6 +677,4 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
     public void setEventDispatchImpulseThreshold(float eventDispatchImpulseThreshold) {
     public void setEventDispatchImpulseThreshold(float eventDispatchImpulseThreshold) {
         this.eventDispatchImpulseThreshold = eventDispatchImpulseThreshold;
         this.eventDispatchImpulseThreshold = eventDispatchImpulseThreshold;
     }
     }
-    
-    
 }
 }