Пример #1
0
        public static Vector3 Slerp(Vector3 from, Vector3 to, float step)
        {
            if (FezMath.AlmostEqual(step, 0.0f))
            {
                return(from);
            }
            if (FezMath.AlmostEqual(step, 1f))
            {
                return(to);
            }
            float num1 = Vector3.Dot(from, to);

            if ((double)num1 == -1.0)
            {
                Vector3 vector3 = Vector3.Cross(Vector3.Normalize(to - from), Vector3.UnitY);
                if ((double)step < 0.5)
                {
                    return(FezMath.Slerp(from, vector3, step * 2f));
                }
                else
                {
                    return(FezMath.Slerp(vector3, to, (float)(((double)step - 0.5) / 2.0)));
                }
            }
            else
            {
                double a = Math.Acos((double)MathHelper.Clamp(num1, -1f, 1f));
                if (FezMath.AlmostEqual(a, 0.0))
                {
                    return(to);
                }
                double num2 = Math.Sin(a);
                return((float)(Math.Sin((1.0 - (double)step) * a) / num2) * from + (float)(Math.Sin((double)step * a) / num2) * to);
            }
        }
Пример #2
0
 public static bool AlmostEqual(Vector2 a, Vector2 b, float epsilon)
 {
     if (FezMath.AlmostEqual(a.X, b.X, epsilon))
     {
         return(FezMath.AlmostEqual(a.Y, b.Y, epsilon));
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
 public static bool AlmostEqual(Quaternion a, Quaternion b, float epsilon)
 {
     if (FezMath.AlmostEqual(a.X, b.X, epsilon) && FezMath.AlmostEqual(a.Y, b.Y, epsilon) && FezMath.AlmostEqual(a.Z, b.Z, epsilon))
     {
         return(FezMath.AlmostEqual(a.W, b.W, epsilon));
     }
     else
     {
         return(false);
     }
 }
Пример #4
0
        public static float CurveAngle(float from, float to, float step)
        {
            if (FezMath.AlmostEqual(step, 0.0f))
            {
                return(from);
            }
            if (FezMath.AlmostEqual(from, to) || FezMath.AlmostEqual(step, 1f))
            {
                return(to);
            }
            Vector2 vector2 = FezMath.Slerp(new Vector2((float)Math.Cos((double)from), (float)Math.Sin((double)from)), new Vector2((float)Math.Cos((double)to), (float)Math.Sin((double)to)), step);

            return((float)Math.Atan2((double)vector2.Y, (double)vector2.X));
        }
Пример #5
0
 public static float AlmostClamp(float x, float epsilon)
 {
     if (FezMath.AlmostEqual(x, 0.0f, epsilon))
     {
         return(0.0f);
     }
     if (FezMath.AlmostEqual(x, 1f, epsilon))
     {
         return(1f);
     }
     if (FezMath.AlmostEqual(x, -1f, epsilon))
     {
         return(-1f);
     }
     else
     {
         return(x);
     }
 }
Пример #6
0
        public static Vector2 Slerp(Vector2 from, Vector2 to, float step)
        {
            if (FezMath.AlmostEqual(step, 0.0f))
            {
                return(from);
            }
            if (FezMath.AlmostEqual(step, 1f))
            {
                return(to);
            }
            double a = Math.Acos((double)MathHelper.Clamp(Vector2.Dot(from, to), -1f, 1f));

            if (FezMath.AlmostEqual(a, 0.0))
            {
                return(to);
            }
            double num = Math.Sin(a);

            return((float)(Math.Sin((1.0 - (double)step) * a) / num) * from + (float)(Math.Sin((double)step * a) / num) * to);
        }
Пример #7
0
 public static FaceOrientation OrientationFromPhi(float phi)
 {
     phi = FezMath.WrapAngle(phi);
     if (FezMath.AlmostEqual(phi, 0.0f))
     {
         return(FaceOrientation.Front);
     }
     if (FezMath.AlmostEqual(phi, 1.570796f))
     {
         return(FaceOrientation.Right);
     }
     if (FezMath.AlmostEqual(phi, -3.141593f))
     {
         return(FaceOrientation.Back);
     }
     if (FezMath.AlmostEqual(phi, -1.570796f))
     {
         return(FaceOrientation.Left);
     }
     else
     {
         return(FezMath.OrientationFromPhi(FezMath.SnapPhi(phi)));
     }
 }
Пример #8
0
 public static bool AlmostWrapEqual(float a, float b, float epsilon)
 {
     return(FezMath.AlmostEqual(Vector2.Dot(new Vector2((float)Math.Cos((double)a), (float)Math.Sin((double)a)), new Vector2((float)Math.Cos((double)b), (float)Math.Sin((double)b))), 1f, epsilon));
 }
Пример #9
0
 public static bool AlmostEqual(Vector2 a, Vector2 b)
 {
     return(FezMath.AlmostEqual(a, b, 1.0 / 1000.0));
 }
Пример #10
0
 public static bool AlmostEqual(Quaternion a, Quaternion b)
 {
     return(FezMath.AlmostEqual(a, b, 1.0 / 1000.0));
 }