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
3.0
rem..om 14 years ago
parent 1c76575ef7
commit 5468dfe927
  1. 7
      engine/src/jbullet/com/jme3/bullet/control/KinematicRagdollControl.java

@ -126,6 +126,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
protected float totalMass = 0; protected float totalMass = 0;
protected boolean added = false; protected boolean added = false;
public static enum Mode { public static enum Mode {
Kinetmatic, Kinetmatic,
@ -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());
} }

Loading…
Cancel
Save