Search in sources :

Example 91 with Quaternion

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);
        }
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars) Bone(com.jme3.animation.Bone) AnimControl(com.jme3.animation.AnimControl)

Example 92 with Quaternion

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();
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Bone(com.jme3.animation.Bone) TempVars(com.jme3.util.TempVars)

Example 93 with Quaternion

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);
    }
}
Also used : Spatial(com.jme3.scene.Spatial) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 94 with Quaternion

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();
}
Also used : Quaternion(com.jme3.math.Quaternion) TempVars(com.jme3.util.TempVars)

Example 95 with Quaternion

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;
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Aggregations

Quaternion (com.jme3.math.Quaternion)115 Vector3f (com.jme3.math.Vector3f)100 Geometry (com.jme3.scene.Geometry)42 DirectionalLight (com.jme3.light.DirectionalLight)37 Material (com.jme3.material.Material)36 Node (com.jme3.scene.Node)30 FilterPostProcessor (com.jme3.post.FilterPostProcessor)26 Spatial (com.jme3.scene.Spatial)26 KeyTrigger (com.jme3.input.controls.KeyTrigger)22 Box (com.jme3.scene.shape.Box)21 TempVars (com.jme3.util.TempVars)16 ActionListener (com.jme3.input.controls.ActionListener)15 ColorRGBA (com.jme3.math.ColorRGBA)15 Quad (com.jme3.scene.shape.Quad)15 AmbientLight (com.jme3.light.AmbientLight)14 Sphere (com.jme3.scene.shape.Sphere)11 Bone (com.jme3.animation.Bone)9 PointLight (com.jme3.light.PointLight)8 AnimControl (com.jme3.animation.AnimControl)7 SpotLight (com.jme3.light.SpotLight)7