- Ragdolled model position now updates when ragdoll has control

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7248 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 3824676354
commit 9b5aa824fd
  1. 31
      engine/src/jbullet/com/jme3/bullet/control/RagdollControl.java

@ -60,6 +60,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
protected float eventDiscardImpulseThreshold = 3;
protected RagdollPreset preset = new HumanoidRagdollPreset();
protected List<String> boneList = new LinkedList<String>();
protected Vector3f initPosition = new Vector3f();
public RagdollControl() {
}
@ -78,7 +79,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
Quaternion q2 = vars.quat1;
Quaternion q3 = vars.quat2;
Vector3f p2 = vars.vect2;
Vector3f pos = vars.vect2;
// skeleton.reset();
for (PhysicsBoneLink link : boneLinks.values()) {
@ -90,20 +91,23 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
q2.set(q).multLocal(link.initalWorldRotation).normalize();
q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2,q2);
q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
q2.normalize();
if (boneList.isEmpty()) {
if (link.bone.getParent() == null) {
initPosition.set(p).subtractLocal(link.bone.getInitialPos());
targetModel.setLocalTranslation(initPosition);
link.bone.setUserControl(true);
link.bone.setUserTransformsWorld(position, q2);
} else {
setTransform(link.bone, position, q2);
} else {
if (boneList.isEmpty()) {
link.bone.setUserControl(true);
link.bone.setUserTransformsWorld(position, q2);
} else {
setTransform(link.bone, position, q2);
}
}
}
targetModel.updateModelBound();
} else {
for (PhysicsBoneLink link : boneLinks.values()) {
//the ragdoll does not control the skeleton
@ -121,7 +125,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
//computing rotation
rotation.set(link.bone.getModelSpaceRotation()).multLocal(link.bone.getWorldBindInverseRotation());
targetModel.getWorldRotation().mult(rotation,rotation);
targetModel.getWorldRotation().mult(rotation, rotation);
rotation.normalize();
// scale.set(link.bone.getModelSpaceScale());
@ -160,7 +164,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
Vector3f initPosition = model.getLocalTranslation().clone();
Quaternion initRotation = model.getLocalRotation().clone();
Quaternion initRotation = model.getLocalRotation().clone();
initScale = model.getLocalScale().clone();
model.removeFromParent();
@ -220,7 +224,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
private void boneRecursion(Spatial model, Bone bone, PhysicsRigidBody parent, int reccount) {
PhysicsRigidBody parentShape = parent;
if (boneList.isEmpty() || boneList.contains(bone.getName())) {
//creating the collision shape from the bone's associated vertices
PhysicsRigidBody shapeNode = new PhysicsRigidBody(makeShape(bone, model), 10.0f / (float) reccount);
@ -530,6 +534,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
boolean hit = false;
Bone hitBone = null;
PhysicsCollisionObject hitObject = null;
if (objA.getUserObject() instanceof PhysicsBoneLink) {
PhysicsBoneLink link = (PhysicsBoneLink) objA.getUserObject();

Loading…
Cancel
Save