Esempio n. 1
0
        public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime)
        {
            smoothTime = Mathd.Max(0.0001d, smoothTime);
            double num1 = 2d / smoothTime;
            double num2 = num1 * deltaTime;
            double num3 = (1.0d / (1.0d + num2 + 0.479999989271164d * num2 * num2 + 0.234999999403954d * num2 * num2 * num2));
            double num4 = current - target;
            double num5 = target;
            double max  = maxSpeed * smoothTime;
            double num6 = Mathd.Clamp(num4, -max, max);

            target = current - num6;
            double num7 = (currentVelocity + num1 * num6) * deltaTime;

            currentVelocity = (currentVelocity - num1 * num7) * num3;
            double num8 = target + (num6 + num7) * num3;

            if (num5 - current > 0.0 == num8 > num5)
            {
                num8            = num5;
                currentVelocity = (num8 - num5) / deltaTime;
            }

            return(num8);
        }
Esempio n. 2
0
        public static Vector3d SmoothDamp(Vector3d current, Vector3d target, ref Vector3d currentVelocity,
                                          double smoothTime, double maxSpeed, double deltaTime)
        {
            smoothTime = Mathd.Max(0.0001d, smoothTime);
            var num1 = 2d / smoothTime;
            var num2 = num1 * deltaTime;
            var num3 = 1.0d / (1.0d + num2 + 0.479999989271164d * num2 * num2 +
                               0.234999999403954d * num2 * num2 * num2);
            var vector    = current - target;
            var vector3_1 = target;
            var maxLength = maxSpeed * smoothTime;
            var vector3_2 = ClampMagnitude(vector, maxLength);

            target = current - vector3_2;
            var vector3_3 = (currentVelocity + num1 * vector3_2) * deltaTime;

            currentVelocity = (currentVelocity - num1 * vector3_3) * num3;
            var vector3_4 = target + (vector3_2 + vector3_3) * num3;

            if (Dot(vector3_1 - current, vector3_4 - vector3_1) > 0.0)
            {
                vector3_4       = vector3_1;
                currentVelocity = (vector3_4 - vector3_1) / deltaTime;
            }

            return(vector3_4);
        }
Esempio n. 3
0
        public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
        {
            smoothTime = Mathd.Max(0.0001f, smoothTime);
            float num1 = 2f / smoothTime;
            float num2 = num1 * deltaTime;
            float num3 = (1.0f / (1.0f + num2 + 0.479999989271164f * num2 * num2 + 0.234999999403954f * num2 * num2 * num2));
            float num4 = current - target;
            float num5 = target;
            float max  = maxSpeed * smoothTime;
            float num6 = Mathd.Clamp(num4, -max, max);

            target = current - num6;
            float num7 = (currentVelocity + num1 * num6) * deltaTime;

            currentVelocity = (currentVelocity - num1 * num7) * num3;
            float num8 = target + (num6 + num7) * num3;

            if (num5 - current > 0.0 == num8 > num5)
            {
                num8            = num5;
                currentVelocity = (num8 - num5) / deltaTime;
            }
            return(num8);
        }
Esempio n. 4
0
 public static Vector2d Max(Vector2d lhs, Vector2d rhs)
 {
     return(new Vector2d(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y)));
 }
Esempio n. 5
0
 public static bool Approximately(double a, double b)
 {
     return(Mathd.Abs(b - a) < Mathd.Max(1E-06d * Mathd.Max(Mathd.Abs(a), Mathd.Abs(b)), 1.121039E-44d));
 }
Esempio n. 6
0
 public static Vector3Double Max(Vector3Double lhs, Vector3Double rhs)
 {
     return(new Vector3Double(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y), Mathd.Max(lhs.z, rhs.z)));
 }
Esempio n. 7
0
 public static Vector3d Max(Vector3d lhs, Vector3d rhs)
 {
     return(new Vector3d(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y), Mathd.Max(lhs.z, rhs.z)));
 }
Esempio n. 8
0
 public static DVector2 Max(DVector2 lhs, DVector2 rhs)
 {
     return(new DVector2(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y)));
 }
Esempio n. 9
0
 public static bool Approximately(float a, float b)
 {
     return(Mathd.Abs(b - a) < Mathd.Max(1E-06f * Mathd.Max(Mathd.Abs(a), Mathd.Abs(b)), 1.121039E-44f));
 }
Esempio n. 10
0
 public static DVector3 Max(DVector3 lhs, DVector3 rhs)
 {
     return(new DVector3(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y), Mathd.Max(lhs.z, rhs.z)));
 }