Java Code Examples for com.jme3.math.Quaternion#slerp()

The following examples show how to use com.jme3.math.Quaternion#slerp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnimationFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Interpolates over the key frames for the given keyFrame array and the given type of transform
 * @param keyFrames the keyFrames array
 * @param type the type of transforms
 */
private void interpolate(Object[] keyFrames, Type type) {
    int i = 0;
    while (i < totalFrames) {
        //fetching the next keyFrame index transform in the array
        int key = getNextKeyFrame(i, keyFrames);
        if (key != -1) {
            //computing the frame span to interpolate over
            int span = key - i;
            //interating over the frames
            for (int j = i; j <= key; j++) {
                // computing interpolation value
                float val = (j - i) / (float) span;
                //interpolationg depending on the transform type
                switch (type) {
                    case Translation:
                        translations[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]);
                        break;
                    case Rotation:
                        Quaternion rot = new Quaternion();
                        rotations[j] = rot.slerp(((Rotation) keyFrames[i]).rotation, ((Rotation) keyFrames[key]).rotation, val);
                        break;
                    case Scale:
                        scales[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]);
                        break;
                }
            }
            //jumping to the next keyFrame
            i = key;
        } else {
            //No more key frame, filling the array with the last transform computed.
            for (int j = i; j < totalFrames; j++) {

                switch (type) {
                    case Translation:
                        translations[j] = ((Vector3f) keyFrames[i]).clone();
                        break;
                    case Rotation:
                        rotations[j] = ((Rotation) keyFrames[i]).rotation.clone();
                        break;
                    case Scale:
                        scales[j] = ((Vector3f) keyFrames[i]).clone();
                        break;
                }
            }
            //we're done
            i = totalFrames;
        }
    }
}
 
Example 2
Source File: AnimationFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Interpolates over the key frames for the given keyFrame array and the given type of transform
 * @param keyFrames the keyFrames array
 * @param type the type of transforms
 */
private void interpolate(Object[] keyFrames, Type type) {
    int i = 0;
    while (i < totalFrames) {
        //fetching the next keyFrame index transform in the array
        int key = getNextKeyFrame(i, keyFrames);
        if (key != -1) {
            //computing the frame span to interpolate over
            int span = key - i;
            //interating over the frames
            for (int j = i; j <= key; j++) {
                // computing interpolation value
                float val = (float) (j - i) / (float) span;
                //interpolationg depending on the transform type
                switch (type) {
                    case Translation:
                        translations[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]);
                        break;
                    case Rotation:
                        Quaternion rot = new Quaternion();
                        rotations[j] = rot.slerp(((Rotation) keyFrames[i]).rotation, ((Rotation) keyFrames[key]).rotation, val);
                        break;
                    case Scale:
                        scales[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]);
                        break;
                }
            }
            //jumping to the next keyFrame
            i = key;
        } else {
            //No more key frame, filling the array witht he last transform computed.
            for (int j = i; j < totalFrames; j++) {

                switch (type) {
                    case Translation:
                        translations[j] = ((Vector3f) keyFrames[i]).clone();
                        break;
                    case Rotation:
                        rotations[j] = ((Quaternion) ((Rotation) keyFrames[i]).rotation).clone();
                        break;
                    case Scale:
                        scales[j] = ((Vector3f) keyFrames[i]).clone();
                        break;
                }
            }
            //we're done
            i = totalFrames;
        }
    }
}