use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method setMode.
/**
* Enable or disable the ragdoll behaviour. if ragdollEnabled is true, the
* character motion will only be powerd by physics else, the characted will
* be animated by the keyframe animation, but will be able to physically
* interact with its physic environnement
*
* @param ragdollEnabled
*/
protected void setMode(Mode mode) {
this.mode = mode;
AnimControl animControl = targetModel.getControl(AnimControl.class);
animControl.setEnabled(mode == Mode.Kinematic);
baseRigidBody.setKinematic(mode == Mode.Kinematic);
if (mode != Mode.IK) {
TempVars vars = TempVars.get();
for (PhysicsBoneLink link : boneLinks.values()) {
link.rigidBody.setKinematic(mode == Mode.Kinematic);
if (mode == Mode.Ragdoll) {
Quaternion tmpRot1 = vars.quat1;
Vector3f position = vars.vect1;
//making sure that the ragdoll is at the correct place.
matchPhysicObjectToBone(link, position, tmpRot1);
}
}
vars.release();
}
if (mode != Mode.IK) {
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, mode == Mode.Ragdoll);
}
}
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method applyUserControl.
public void applyUserControl() {
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, false);
}
if (ikTargets.isEmpty()) {
setKinematicMode();
} else {
Iterator iterator = ikTargets.keySet().iterator();
TempVars vars = TempVars.get();
while (iterator.hasNext()) {
Bone bone = (Bone) iterator.next();
while (bone.getParent() != null) {
Quaternion tmpRot1 = vars.quat1;
Vector3f position = vars.vect1;
matchPhysicObjectToBone(boneLinks.get(bone.getName()), position, tmpRot1);
bone.setUserControl(true);
bone = bone.getParent();
}
}
vars.release();
}
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class SpatialTrack method setTime.
/**
*
* Modify the spatial which this track modifies.
*
* @param time
* the current time of the animation
*/
public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
Spatial spatial = control.getSpatial();
Vector3f tempV = vars.vect1;
Vector3f tempS = vars.vect2;
Quaternion tempQ = vars.quat1;
Vector3f tempV2 = vars.vect3;
Vector3f tempS2 = vars.vect4;
Quaternion tempQ2 = vars.quat2;
int lastFrame = times.length - 1;
if (time < 0 || lastFrame == 0) {
if (rotations != null)
rotations.get(0, tempQ);
if (translations != null)
translations.get(0, tempV);
if (scales != null) {
scales.get(0, tempS);
}
} else if (time >= times[lastFrame]) {
if (rotations != null)
rotations.get(lastFrame, tempQ);
if (translations != null)
translations.get(lastFrame, tempV);
if (scales != null) {
scales.get(lastFrame, tempS);
}
} else {
int startFrame = 0;
int endFrame = 1;
// use lastFrame so we never overflow the array
for (int i = 0; i < lastFrame && times[i] < time; ++i) {
startFrame = i;
endFrame = i + 1;
}
float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]);
if (rotations != null)
rotations.get(startFrame, tempQ);
if (translations != null)
translations.get(startFrame, tempV);
if (scales != null) {
scales.get(startFrame, tempS);
}
if (rotations != null)
rotations.get(endFrame, tempQ2);
if (translations != null)
translations.get(endFrame, tempV2);
if (scales != null) {
scales.get(endFrame, tempS2);
}
tempQ.nlerp(tempQ2, blend);
tempV.interpolateLocal(tempV2, blend);
tempS.interpolateLocal(tempS2, blend);
}
if (translations != null)
spatial.setLocalTranslation(tempV);
if (rotations != null)
spatial.setLocalRotation(tempQ);
if (scales != null) {
spatial.setLocalScale(tempS);
}
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class ChaseCameraAppState method rotateCamera.
/**
* rotate the camera around the target
*/
protected void rotateCamera() {
verticalRotation = FastMath.clamp(verticalRotation, minVerticalRotation, maxVerticalRotation);
TempVars vars = TempVars.get();
Quaternion rot = vars.quat1;
Quaternion rot2 = vars.quat2;
rot.fromAngleNormalAxis(verticalRotation, leftVector);
rot2.fromAngleNormalAxis(horizontalRotation, upVector);
rot2.multLocal(rot);
target.setLocalRotation(rot2);
vars.release();
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class RigidBodyMotionState method applyTransform.
/**
* applies the current transform to the given jme Node if the location has been updated on the physics side
* @param spatial
*/
public boolean applyTransform(Spatial spatial) {
Vector3f localLocation = spatial.getLocalTranslation();
Quaternion localRotationQuat = spatial.getLocalRotation();
boolean physicsLocationDirty = applyTransform(motionStateId, localLocation, localRotationQuat);
if (!physicsLocationDirty) {
return false;
}
if (!applyPhysicsLocal && spatial.getParent() != null) {
localLocation.subtractLocal(spatial.getParent().getWorldTranslation());
localLocation.divideLocal(spatial.getParent().getWorldScale());
tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
// localRotationQuat.set(worldRotationQuat);
tmp_inverseWorldRotation.mult(localRotationQuat, localRotationQuat);
spatial.setLocalTranslation(localLocation);
spatial.setLocalRotation(localRotationQuat);
} else {
spatial.setLocalTranslation(localLocation);
spatial.setLocalRotation(localRotationQuat);
// spatial.setLocalTranslation(worldLocation);
// spatial.setLocalRotation(worldRotationQuat);
}
if (vehicle != null) {
vehicle.updateWheels();
}
return true;
}
Aggregations