Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * jme3 implementation of the c++ quaternion spherical linear interpolation from wikipedia
- * modified by @author JDC, to return v1 if they are close together
- *
- * DOT_THRESHOLD should be something like 0.9995f, adjust per se
- *
- * @param v0 - start quaternion
- * @param v1 - end quaternion
- * @param t - scale between
- * @return
- */
- public static Quaternion jqSlerp2(Quaternion v0, Quaternion v1, float t) {
- v0.normalizeLocal();
- v1.normalizeLocal();
- float dot = v0.dot(v1);
- if (dot < 0.0f) {
- v1.negate();
- dot = -dot;
- }
- if (dot > DOT_THRESHOLD) {
- return v1;
- }
- float theta_0 = FastMath.acos(dot);
- float theta = theta_0 * t;
- float sin_theta = FastMath.sin(theta);
- float sin_theta_0 = FastMath.sin(theta_0);
- float s0 = FastMath.cos(theta) - dot * sin_theta / sin_theta_0;
- float s1 = sin_theta / sin_theta_0;
- return new Quaternion(v0.multLocal(s0)).addLocal(v1.multLocal(s1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement