/** * Adds the float components of another quaternion to this one. * * @param x The x (imaginary) component of the quaternion to add * @param y The y (imaginary) component of the quaternion to add * @param z The z (imaginary) component of the quaternion to add * @param w The w (real) component of the quaternion to add * @return A new quaternion, which is the sum of both */ public Quaterniond add(float x, float y, float z, float w) { return add((double) x, (double) y, (double) z, (double) w); }
/** * Adds another quaternion to this one. * * @param q The quaternion to add * @return A new quaternion, which is the sum of both */ public Quaterniond add(Quaterniond q) { return add(q.x, q.y, q.z, q.w); }
/** * Adds another quaternion to this one. * * @param q The quaternion to add * @return A new quaternion, which is the sum of both */ public Quaterniond add(Quaterniond q) { return add(q.x, q.y, q.z, q.w); }
/** * Adds the float components of another quaternion to this one. * * @param x The x (imaginary) component of the quaternion to add * @param y The y (imaginary) component of the quaternion to add * @param z The z (imaginary) component of the quaternion to add * @param w The w (real) component of the quaternion to add * @return A new quaternion, which is the sum of both */ public Quaterniond add(float x, float y, float z, float w) { return add((double) x, (double) y, (double) z, (double) w); }
/** * Interpolates a quaternion between two others using linear interpolation. * * @param a The first quaternion * @param b The second quaternion * @param percent The percent for the interpolation, between 0 and 1 inclusively * @return The interpolated quaternion */ public static Quaterniond lerp(Quaterniond a, Quaterniond b, double percent) { return a.mul(1 - percent).add(b.mul(percent)); }
/** * Interpolates a quaternion between two others using linear interpolation. * * @param a The first quaternion * @param b The second quaternion * @param percent The percent for the interpolation, between 0 and 1 inclusively * @return The interpolated quaternion */ public static Quaterniond lerp(Quaterniond a, Quaterniond b, double percent) { return a.mul(1 - percent).add(b.mul(percent)); }
/** * Interpolates a quaternion between two others using spherical linear interpolation. * * @param a The first quaternion * @param b The second quaternion * @param percent The percent for the interpolation, between 0 and 1 inclusively * @return The interpolated quaternion */ public static Quaterniond slerp(Quaterniond a, Quaterniond b, double percent) { final double inverted; double cosineTheta = a.dot(b); if (cosineTheta < 0) { cosineTheta = -cosineTheta; inverted = -1; } else { inverted = 1; } if (1 - cosineTheta < GenericMath.DBL_EPSILON) { return a.mul(1 - percent).add(b.mul(percent * inverted)); } final double theta = (double) TrigMath.acos(cosineTheta); final double sineTheta = TrigMath.sin(theta); final double coefficient1 = TrigMath.sin((1 - percent) * theta) / sineTheta; final double coefficient2 = TrigMath.sin(percent * theta) / sineTheta * inverted; return a.mul(coefficient1).add(b.mul(coefficient2)); }
/** * Interpolates a quaternion between two others using spherical linear interpolation. * * @param a The first quaternion * @param b The second quaternion * @param percent The percent for the interpolation, between 0 and 1 inclusively * @return The interpolated quaternion */ public static Quaterniond slerp(Quaterniond a, Quaterniond b, double percent) { final double inverted; double cosineTheta = a.dot(b); if (cosineTheta < 0) { cosineTheta = -cosineTheta; inverted = -1; } else { inverted = 1; } if (1 - cosineTheta < GenericMath.DBL_EPSILON) { return a.mul(1 - percent).add(b.mul(percent * inverted)); } final double theta = (double) TrigMath.acos(cosineTheta); final double sineTheta = TrigMath.sin(theta); final double coefficient1 = TrigMath.sin((1 - percent) * theta) / sineTheta; final double coefficient2 = TrigMath.sin(percent * theta) / sineTheta * inverted; return a.mul(coefficient1).add(b.mul(coefficient2)); }