public static TSQuaternion Slerp(TSQuaternion from, TSQuaternion to, FP t) { t = TSMath.Clamp(t, 0, 1); //t = 0.5f; //if (t == 0) // return from; FP dot = Dot(from, to); if (dot < 0.0f) { to = Multiply(to, -1); dot = -dot; } if (dot >= FP.NearOne) { // If the inputs are too close for comfort, linearly interpolate // and normalize the result. TSQuaternion result = Lerp(from, to, t); return(result); } FP halfTheta = FP.Acos(dot); //UnityEngine.Debug.LogWarning("halfTheta:"+ halfTheta+" dot:"+dot+ " FP.Sin(halfTheta):"+ FP.Sin(halfTheta)); return(Multiply(Multiply(from, FP.Sin((1 - t) * halfTheta)) + Multiply(to, FP.Sin(t * halfTheta)), 1 / FP.Sin(halfTheta))); }
public static FP Angle(TSQuaternion a, TSQuaternion b) { TSQuaternion value = TSQuaternion.Inverse(a); TSQuaternion tSQuaternion = b * value; FP result = FP.Acos(tSQuaternion.w) * 2 * FP.Rad2Deg; bool flag = result > 180; if (flag) { result = 360 - result; } return(result); }
public static FP Angle(TSQuaternion a, TSQuaternion b) { TSQuaternion aInv = TSQuaternion.Inverse(a); TSQuaternion f = b * aInv; FP angle = FP.Acos(f.w) * 2 * FP.Rad2Deg; if (angle > 180) { angle = 360 - angle; } return(angle); }
public static TSQuaternion Slerp(TSQuaternion from, TSQuaternion to, FP t) { t = TSMath.Clamp(t, 0, 1); FP dot = Dot(from, to); if (dot < 0.0f) { to = Multiply(to, -1); dot = -dot; } FP halfTheta = FP.Acos(dot); return(Multiply(Multiply(from, FP.Sin((1 - t) * halfTheta)) + Multiply(to, FP.Sin(t * halfTheta)), 1 / FP.Sin(halfTheta))); }
public static TSQuaternion RotateTowards(TSQuaternion from, TSQuaternion to, FP maxDegreesDelta) { FP dot = Dot(from, to); if (dot < 0.0f) { to = Multiply(to, -1); dot = -dot; } FP halfTheta = FP.Acos(dot); FP theta = halfTheta * 2; maxDegreesDelta *= FP.Deg2Rad; if (maxDegreesDelta >= theta) { return(to); } maxDegreesDelta /= theta; return(Multiply(Multiply(from, FP.Sin((1 - maxDegreesDelta) * halfTheta)) + Multiply(to, FP.Sin(maxDegreesDelta * halfTheta)), 1 / FP.Sin(halfTheta))); }
/// <summary> /// Returns the arc cosine of value. /// </summary> public static FP Acos(FP value) { return(FP.Acos(value)); }
public static FP Angle(TSVector a, TSVector b) { return(FP.Acos(a.normalized * b.normalized) * FP.Rad2Deg); }