public static Fix64 Angle(FPQuaternion a, FPQuaternion b) { FPQuaternion aInv = FPQuaternion.Inverse(a); FPQuaternion f = b * aInv; Fix64 angle = Fix64.Acos(f.w) * 2 * Fix64.Rad2Deg; if (angle > 180) { angle = 360 - angle; } return(angle); }
public static FPQuaternion Slerp(FPQuaternion from, FPQuaternion to, Fix64 t) { t = FPMath.Clamp(t, 0, 1); Fix64 dot = Dot(from, to); if (dot < 0.0f) { to = Multiply(to, -1); dot = -dot; } Fix64 halfTheta = Fix64.Acos(dot); return(Multiply(Multiply(from, Fix64.Sin((1 - t) * halfTheta)) + Multiply(to, Fix64.Sin(t * halfTheta)), 1 / Fix64.Sin(halfTheta))); }
public static FPQuaternion RotateTowards(FPQuaternion from, FPQuaternion to, Fix64 maxDegreesDelta) { Fix64 dot = Dot(from, to); if (dot < 0.0f) { to = Multiply(to, -1); dot = -dot; } Fix64 halfTheta = Fix64.Acos(dot); Fix64 theta = halfTheta * 2; maxDegreesDelta *= Fix64.Deg2Rad; if (maxDegreesDelta >= theta) { return(to); } maxDegreesDelta /= theta; return(Multiply(Multiply(from, Fix64.Sin((1 - maxDegreesDelta) * halfTheta)) + Multiply(to, Fix64.Sin(maxDegreesDelta * halfTheta)), 1 / Fix64.Sin(halfTheta))); }
public static Fix64 Angle(FPVector a, FPVector b) { return(Fix64.Acos(a.normalized * b.normalized) * Fix64.Rad2Deg); }