public static fp3 Slerp(fp3 lhs, fp3 rhs, fp t) { var lhsMag = fpmath.length(lhs); var rhsMag = fpmath.length(rhs); if (lhsMag < VecMath.VECTOR3_EPSILON || rhsMag < VecMath.VECTOR3_EPSILON) { return(VecMath.Lerp(lhs, rhs, t)); } var lerpedMagnitude = fpmath.lerp(lhsMag, rhsMag, t); var dot = fpmath.dot(lhs, rhs) / (lhsMag * rhsMag); // direction is almost the same if (dot > 1.0F - VecMath.VECTOR3_EPSILON) { return(VecMath.Lerp(lhs, rhs, t)); } // directions are almost opposite else if (dot < -1.0F + VecMath.VECTOR3_EPSILON) { var lhsNorm = lhs / lhsMag; var axis = VecMath.OrthoNormalVectorFast(lhsNorm); var m = fpmatrix3x3.zero; m.SetAxisAngle(axis, fpmath.PI * t); var slerped = m.MultiplyVector3(lhsNorm); slerped *= lerpedMagnitude; return(slerped); } // normal case else { var axis = fpmath.cross(lhs, rhs); var lhsNorm = lhs / lhsMag; axis = fpmath.normalizesafe(axis); var angle = fpmath.acos(dot) * t; var m = fpmatrix3x3.zero; m.SetAxisAngle(axis, angle); var slerped = m.MultiplyVector3(lhsNorm); slerped *= lerpedMagnitude; return(slerped); } }
public static Vector2 Lerp(Vector2 lhs, Vector2 rhs, float t) { return(VecMath.Lerp((fp2)lhs, (fp2)rhs, (fp)t)); }
public static Vector3 Lerp(Vector3 lhs, Vector3 rhs, float t) { return(VecMath.Lerp((fp3)lhs, (fp3)rhs, (fp)t)); }