public static LFloat Angle(LQuaternion a, LQuaternion b) { LQuaternion q = b * LQuaternion.Inverse(a); q.Normalize(); return(LMath.Acos(q.w)); }
public static LVector3 ToEulerAngles(LQuaternion rotation) { rotation.Normalize(); return(new LVector3( LMath.Atan2(2 * (rotation.w * rotation.z + rotation.x * rotation.y), 1 - 2 * (rotation.z * rotation.z + rotation.x * rotation.x)), LMath.Asin(2 * (rotation.w * rotation.x - rotation.y * rotation.z)), LMath.Atan2(2 * (rotation.w * rotation.y + rotation.z * rotation.x), 1 - 2 * (rotation.x * rotation.x + rotation.y * rotation.y)) )); }
public static LQuaternion Slerp(LQuaternion from, LQuaternion to, LFloat t) { t = LMath.Clamp(t, 0, 1); LFloat diff = Angle(from, to) * LMath.DegToRad; LFloat sind = LMath.Sin(diff); LFloat sintd = LMath.Sin(t * diff); LFloat sin1td = LMath.Sin((1 - t) * diff); return((sin1td / sind) * from + (sintd / sind) * to); }
public static LQuaternion Inverse(LQuaternion rotation) { LQuaternion inv = rotation.conjugation; if (rotation.sqrtMagnitude != 1) { inv *= (1 / rotation.sqrtMagnitude); } return(inv); }
public void Write(LQuaternion val) { Write(val.x); Write(val.y); Write(val.z); Write(val.w); }
public static LQuaternion Lerp(LQuaternion from, LQuaternion to, LFloat t) { t = LMath.Clamp(t, 0, 1); return((1 - t) * from + t * to); }
public static LQuaternion RotateTowards(LQuaternion from, LQuaternion to, LFloat maxDegreesDelta) { LFloat angle = Angle(from, to); return(Slerp(from, to, maxDegreesDelta / angle)); }
public static LFloat Dot(LQuaternion a, LQuaternion b) { return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); }
public static LVector3 operator *(LQuaternion rotation, LVector3 point) { LQuaternion p = rotation * new LQuaternion(point.x, point.y, point.z, 0) * rotation.conjugation; return(new LVector3(p.x, p.y, p.z)); }