|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright (c) 2009-2012 jMonkeyEngine |
|
|
|
* Copyright (c) 2009-2018 jMonkeyEngine |
|
|
|
* All rights reserved. |
|
|
|
* All rights reserved. |
|
|
|
* |
|
|
|
* |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
@ -73,7 +73,7 @@ import java.util.logging.Logger; |
|
|
|
* use this control you need a model with an AnimControl and a |
|
|
|
* use this control you need a model with an AnimControl and a |
|
|
|
* SkeletonControl.<br> This should be the case if you imported an animated |
|
|
|
* SkeletonControl.<br> This should be the case if you imported an animated |
|
|
|
* model from Ogre or blender.<br> Note enabling/disabling the control |
|
|
|
* model from Ogre or blender.<br> Note enabling/disabling the control |
|
|
|
* add/removes it from the physic space<br> <p> This control creates collision |
|
|
|
* add/removes it from the physics space<br> <p> This control creates collision |
|
|
|
* shapes for each bones of the skeleton when you call |
|
|
|
* shapes for each bones of the skeleton when you call |
|
|
|
* spatial.addControl(ragdollControl). <ul> <li>The shape is HullCollision shape |
|
|
|
* spatial.addControl(ragdollControl). <ul> <li>The shape is HullCollision shape |
|
|
|
* based on the vertices associated with each bone and based on a tweakable |
|
|
|
* based on the vertices associated with each bone and based on a tweakable |
|
|
@ -84,11 +84,11 @@ import java.util.logging.Logger; |
|
|
|
* </ul> </p> <p> There are 2 modes for this control : <ul> <li><strong>The |
|
|
|
* </ul> </p> <p> There are 2 modes for this control : <ul> <li><strong>The |
|
|
|
* kinematic modes :</strong><br> this is the default behavior, this means that |
|
|
|
* kinematic modes :</strong><br> this is the default behavior, this means that |
|
|
|
* the collision shapes of the body are able to interact with physics enabled |
|
|
|
* the collision shapes of the body are able to interact with physics enabled |
|
|
|
* objects. in this mode physic shapes follow the moovements of the animated |
|
|
|
* objects. in this mode physics shapes follow the motion of the animated |
|
|
|
* skeleton (for example animated by a key framed animation) this mode is |
|
|
|
* skeleton (for example animated by a key framed animation) this mode is |
|
|
|
* enabled by calling setKinematicMode(); </li> <li><strong>The ragdoll modes |
|
|
|
* enabled by calling setKinematicMode(); </li> <li><strong>The ragdoll modes |
|
|
|
* :</strong><br> To enable this behavior, you need to call setRagdollMode() |
|
|
|
* :</strong><br> To enable this behavior, you need to call setRagdollMode() |
|
|
|
* method. In this mode the charater is entirely controled by physics, so it |
|
|
|
* method. In this mode the character is entirely controlled by physics, so it |
|
|
|
* will fall under the gravity and move if any force is applied to it. </li> |
|
|
|
* will fall under the gravity and move if any force is applied to it. </li> |
|
|
|
* </ul> </p> |
|
|
|
* </ul> </p> |
|
|
|
* |
|
|
|
* |
|
|
@ -201,7 +201,7 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
if(mode == Mode.IK){ |
|
|
|
if(mode == Mode.IK){ |
|
|
|
ikUpdate(tpf); |
|
|
|
ikUpdate(tpf); |
|
|
|
} else if (mode == mode.Ragdoll && targetModel.getLocalTranslation().equals(modelPosition)) { |
|
|
|
} else if (mode == mode.Ragdoll && targetModel.getLocalTranslation().equals(modelPosition)) { |
|
|
|
//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 physics world space.
|
|
|
|
ragDollUpdate(tpf); |
|
|
|
ragDollUpdate(tpf); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
kinematicUpdate(tpf); |
|
|
|
kinematicUpdate(tpf); |
|
|
@ -217,12 +217,12 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
|
|
|
|
|
|
|
|
Vector3f position = vars.vect1; |
|
|
|
Vector3f position = vars.vect1; |
|
|
|
|
|
|
|
|
|
|
|
//retrieving bone position in physic world space
|
|
|
|
//retrieving bone position in physics world space
|
|
|
|
Vector3f p = link.rigidBody.getMotionState().getWorldLocation(); |
|
|
|
Vector3f p = link.rigidBody.getMotionState().getWorldLocation(); |
|
|
|
//transforming this position with inverse transforms of the model
|
|
|
|
//transforming this position with inverse transforms of the model
|
|
|
|
targetModel.getWorldTransform().transformInverseVector(p, position); |
|
|
|
targetModel.getWorldTransform().transformInverseVector(p, position); |
|
|
|
|
|
|
|
|
|
|
|
//retrieving bone rotation in physic world space
|
|
|
|
//retrieving bone rotation in physics world space
|
|
|
|
Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat(); |
|
|
|
Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat(); |
|
|
|
|
|
|
|
|
|
|
|
//multiplying this rotation by the initialWorld rotation of the bone,
|
|
|
|
//multiplying this rotation by the initialWorld rotation of the bone,
|
|
|
@ -264,7 +264,7 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void kinematicUpdate(float tpf) { |
|
|
|
protected void kinematicUpdate(float tpf) { |
|
|
|
//the ragdoll does not have the controll, so the keyframed animation updates the physic position of the physic bonces
|
|
|
|
//the ragdoll does not have control, so the keyframed animation updates the physics position of the physics bonces
|
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Quaternion tmpRot1 = vars.quat1; |
|
|
|
Quaternion tmpRot1 = vars.quat1; |
|
|
|
Quaternion tmpRot2 = vars.quat2; |
|
|
|
Quaternion tmpRot2 = vars.quat2; |
|
|
@ -420,7 +420,7 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
targetModel.getWorldRotation().mult(tmpRot1, tmpRot1); |
|
|
|
targetModel.getWorldRotation().mult(tmpRot1, tmpRot1); |
|
|
|
tmpRot1.normalizeLocal(); |
|
|
|
tmpRot1.normalizeLocal(); |
|
|
|
|
|
|
|
|
|
|
|
//updating physic location/rotation of the physic bone
|
|
|
|
//updating physics location/rotation of the physics bone
|
|
|
|
link.rigidBody.setPhysicsLocation(position); |
|
|
|
link.rigidBody.setPhysicsLocation(position); |
|
|
|
link.rigidBody.setPhysicsRotation(tmpRot1); |
|
|
|
link.rigidBody.setPhysicsRotation(tmpRot1); |
|
|
|
|
|
|
|
|
|
|
@ -707,9 +707,9 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Enable or disable the ragdoll behaviour. if ragdollEnabled is true, the |
|
|
|
* Enable or disable the ragdoll behaviour. if ragdollEnabled is true, the |
|
|
|
* character motion will only be powerd by physics else, the characted will |
|
|
|
* character motion will only be powered by physics else, the character will |
|
|
|
* be animated by the keyframe animation, but will be able to physically |
|
|
|
* be animated by the keyframe animation, but will be able to physically |
|
|
|
* interact with its physic environnement |
|
|
|
* interact with its physics environment |
|
|
|
* |
|
|
|
* |
|
|
|
* @param ragdollEnabled |
|
|
|
* @param ragdollEnabled |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -789,9 +789,9 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the control into Kinematic mode In theis mode, the collision shapes |
|
|
|
* Set the control into Kinematic mode In this mode, the collision shapes |
|
|
|
* follow the movements of the skeleton, and can interact with physical |
|
|
|
* follow the movements of the skeleton, and can interact with physical |
|
|
|
* environement |
|
|
|
* environment |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setKinematicMode() { |
|
|
|
public void setKinematicMode() { |
|
|
|
if (mode != Mode.Kinematic) { |
|
|
|
if (mode != Mode.Kinematic) { |
|
|
@ -820,7 +820,7 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* retruns the mode of this control |
|
|
|
* returns the mode of this control |
|
|
|
* |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -903,7 +903,7 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* For internal use only specific render for the ragdoll(if debugging) |
|
|
|
* For internal use only specific render for the ragdoll (if debugging) |
|
|
|
* |
|
|
|
* |
|
|
|
* @param rm |
|
|
|
* @param rm |
|
|
|
* @param vp |
|
|
|
* @param vp |
|
|
|