/** * Does a spherical linear interpolation between this quaternion and the given end quaternion by the given change * amount. Stores the results locally in this quaternion. * * @param endQuat * @param changeAmnt * @return this quaternion for chaining. */ public Quaternion slerpLocal(final ReadOnlyQuaternion endQuat, final double changeAmnt) { return slerpLocal(this, endQuat, changeAmnt); }
/** * Does a spherical linear interpolation between this quaternion and the given end quaternion by the given change * amount. Stores the results locally in this quaternion. * * @param endQuat * @param changeAmnt * @return this quaternion for chaining. */ public Quaternion slerpLocal(final ReadOnlyQuaternion endQuat, final double changeAmnt) { return slerpLocal(this, endQuat, changeAmnt); }
/** * Does a spherical linear interpolation between the given start and end quaternions by the given change amount. * Stores the result locally. * * @param startQuat * @param endQuat * @param changeAmnt * @return this quaternion for chaining. * @throws NullPointerException * if startQuat or endQuat are null. */ public Quaternion slerpLocal(final ReadOnlyQuaternion startQuat, final ReadOnlyQuaternion endQuat, final double changeAmnt) { final Quaternion end = Quaternion.fetchTempInstance().set(endQuat); slerpLocal(startQuat, endQuat, changeAmnt, end); Quaternion.releaseTempInstance(end); return this; }
/** * Does a spherical linear interpolation between the given start and end quaternions by the given change amount. * Stores the result locally. * * @param startQuat * @param endQuat * @param changeAmnt * @return this quaternion for chaining. * @throws NullPointerException * if startQuat or endQuat are null. */ public Quaternion slerpLocal(final ReadOnlyQuaternion startQuat, final ReadOnlyQuaternion endQuat, final double changeAmnt) { final Quaternion end = Quaternion.fetchTempInstance().set(endQuat); slerpLocal(startQuat, endQuat, changeAmnt, end); Quaternion.releaseTempInstance(end); return this; }
/** * Interpolates between the given quaternions using the * {@link Quaternion#slerpLocal(ReadOnlyQuaternion, ReadOnlyQuaternion, double)} method. */ @Override protected void interpolate(final ReadOnlyQuaternion from, final ReadOnlyQuaternion to, final double delta, final Spatial caller) { assert (null != from) : "parameter 'from' can not be null"; assert (null != to) : "parameter 'to' can not be null"; assert (null != caller) : "parameter 'caller' can not be null"; final Quaternion tempQuat = Quaternion.fetchTempInstance(); tempQuat.slerpLocal(from, to, delta); if (isLocalRotation()) { caller.setRotation(tempQuat); } else { caller.setWorldRotation(tempQuat); } Quaternion.releaseTempInstance(tempQuat); }
/** * Interpolates between the given quaternions using the * {@link Quaternion#slerpLocal(ReadOnlyQuaternion, ReadOnlyQuaternion, double)} method. */ @Override protected void interpolate(final ReadOnlyQuaternion from, final ReadOnlyQuaternion to, final double delta, final Spatial caller) { assert (null != from) : "parameter 'from' can not be null"; assert (null != to) : "parameter 'to' can not be null"; assert (null != caller) : "parameter 'caller' can not be null"; final Quaternion tempQuat = Quaternion.fetchTempInstance(); tempQuat.slerpLocal(from, to, delta); if (isLocalRotation()) { caller.setRotation(tempQuat); } else { caller.setWorldRotation(tempQuat); } Quaternion.releaseTempInstance(tempQuat); }
@Override public void setCurrentSample(final int sampleIndex, final double progressPercent, final Object applyTo) { final TransformData transformData = (TransformData) applyTo; // shortcut if we are fully on one sample or the next if (progressPercent == 0.0f) { transformData.setRotation(_rotations[sampleIndex]); transformData.setTranslation(_translations[sampleIndex]); transformData.setScale(_scales[sampleIndex]); return; } else if (progressPercent == 1.0f) { transformData.setRotation(_rotations[sampleIndex + 1]); transformData.setTranslation(_translations[sampleIndex + 1]); transformData.setScale(_scales[sampleIndex + 1]); return; } // Apply (s)lerp and set in transform _compQuat1.slerpLocal(_rotations[sampleIndex], _rotations[sampleIndex + 1], progressPercent, _compQuat2); transformData.setRotation(_compQuat1); _compVect1.lerpLocal(_translations[sampleIndex], _translations[sampleIndex + 1], progressPercent); transformData.setTranslation(_compVect1); _compVect1.lerpLocal(_scales[sampleIndex], _scales[sampleIndex + 1], progressPercent); transformData.setScale(_compVect1); }
@Override public void setCurrentSample(final int sampleIndex, final double progressPercent, final Object applyTo) { final TransformData transformData = (TransformData) applyTo; // shortcut if we are fully on one sample or the next if (progressPercent == 0.0f) { transformData.setRotation(_rotations[sampleIndex]); transformData.setTranslation(_translations[sampleIndex]); transformData.setScale(_scales[sampleIndex]); return; } else if (progressPercent == 1.0f) { transformData.setRotation(_rotations[sampleIndex + 1]); transformData.setTranslation(_translations[sampleIndex + 1]); transformData.setScale(_scales[sampleIndex + 1]); return; } // Apply (s)lerp and set in transform _compQuat1.slerpLocal(_rotations[sampleIndex], _rotations[sampleIndex + 1], progressPercent, _compQuat2); transformData.setRotation(_compQuat1); _compVect1.lerpLocal(_translations[sampleIndex], _translations[sampleIndex + 1], progressPercent); transformData.setTranslation(_compVect1); _compVect1.lerpLocal(_scales[sampleIndex], _scales[sampleIndex + 1], progressPercent); transformData.setScale(_compVect1); }
quat.slerpLocal(quat2, 1.0); assertTrue(Math.abs(new Vector3(0, -1, 0).distance(quat.apply(Vector3.UNIT_Y, null))) <= Quaternion.ALLOWED_DEVIANCE); quat.slerpLocal(quat2, .5); assertTrue(Math.abs(new Vector3(0, 0, 1).distance(quat.apply(Vector3.UNIT_Y, null))) <= Quaternion.ALLOWED_DEVIANCE); quat.slerpLocal(quat2, 0); assertTrue(Math.abs(new Vector3(0, 1, 0).distance(quat.apply(Vector3.UNIT_Y, null))) <= Quaternion.ALLOWED_DEVIANCE); quat.slerpLocal(quat2, 0.25); assertTrue(Math.abs(new Vector3(0, 1, 0).distance(quat.apply(Vector3.UNIT_Y, null))) <= Quaternion.ALLOWED_DEVIANCE); quat.slerpLocal(quat2, 0.5); assertTrue(Math.abs(new Vector3(0, -Math.sin(MathUtils.QUARTER_PI), Math.sin(MathUtils.QUARTER_PI)) .distance(quat.apply(Vector3.UNIT_Y, null))) <= Quaternion.ALLOWED_DEVIANCE);