Exemplo n.º 1
0
 public static double Repeat(double t, double length)
 {
     return(t - Mathd.Floor(t / length) * length);
 }
Exemplo n.º 2
0
        public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed)
        {
            double deltaTime = (double)Time.deltaTime;

            return(Mathd.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime));
        }
Exemplo n.º 3
0
 public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime)
 {
     target = current + Mathd.DeltaAngle(current, target);
     return(Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime));
 }
Exemplo n.º 4
0
 public static double SmoothStep(double from, double to, double t)
 {
     t = Mathd.Clamp01(t);
     t = (-2.0 * t * t * t + 3.0 * t * t);
     return(to * t + from * (1.0 - t));
 }
Exemplo 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));
 }
Exemplo n.º 6
0
 public static double Angle(Vector2d from, Vector2d to)
 {
     return(Mathd.Acos(Mathd.Clamp(Vector2d.Dot(from.normalized, to.normalized), -1d, 1d)) * 57.29578d);
 }
Exemplo n.º 7
0
 public static DVector3 Lerp(DVector3 from, DVector3 to, double t)
 {
     t = Mathd.Clamp01(t);
     return(new DVector3(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t, from.z + (to.z - from.z) * t));
 }
Exemplo n.º 8
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)));
 }
Exemplo n.º 9
0
 public static double AngleBetween(Vector3d from, Vector3d to)
 {
     return(Mathd.Acos(Mathd.Clamp(Vector3d.Dot(from.normalized, to.normalized), -1d, 1d)));
 }
Exemplo n.º 10
0
 public static double Angle(Vector3d from, Vector3d to)
 {
     //return Mathd.Acos(Mathd.Clamp(Vector3d.Dot(from.normalized, to.normalized), -1d, 1d)) * 57.29578d;
     return(Mathd.Acos(Mathd.Clamp(Vector3d.Dot(from.normalized, to.normalized), -1d, 1d)) * 180.0 / Math.PI);
 }
Exemplo n.º 11
0
        /*
         * public override string ToString()
         * {
         *      string fmt = "({0:F1}, {1:F1}, {2:F1}, {3:F1})";
         *      object[] objArray = new object[4];
         *      int index1 = 0;
         *      // ISSUE: variable of a boxed type
         *      __Boxed<double> local1 = (ValueType) this.x;
         *      objArray[index1] = (object) local1;
         *      int index2 = 1;
         *      // ISSUE: variable of a boxed type
         *      __Boxed<double> local2 = (ValueType) this.y;
         *      objArray[index2] = (object) local2;
         *      int index3 = 2;
         *      // ISSUE: variable of a boxed type
         *      __Boxed<double> local3 = (ValueType) this.z;
         *      objArray[index3] = (object) local3;
         *      int index4 = 3;
         *      // ISSUE: variable of a boxed type
         *      __Boxed<double> local4 = (ValueType) this.w;
         *      objArray[index4] = (object) local4;
         *      return UnityString.Format(fmt, objArray);
         * }
         *
         * public string ToString(string format)
         * {
         *      string fmt = "({0}, {1}, {2}, {3})";
         *      object[] objArray = new object[4];
         *      int index1 = 0;
         *      string str1 = this.x.ToString(format);
         *      objArray[index1] = (object) str1;
         *      int index2 = 1;
         *      string str2 = this.y.ToString(format);
         *      objArray[index2] = (object) str2;
         *      int index3 = 2;
         *      string str3 = this.z.ToString(format);
         *      objArray[index3] = (object) str3;
         *      int index4 = 3;
         *      string str4 = this.w.ToString(format);
         *      objArray[index4] = (object) str4;
         *      return UnityString.Format(fmt, objArray);
         * }
         */

        public static double Angle(QuaternionD a, QuaternionD b)
        {
            return((double)Mathd.Acos(Mathd.Min(Mathd.Abs(QuaternionD.Dot(a, b)), 1.0)) * 2.0 * 57.2957801818848);
        }
Exemplo n.º 12
0
        public Vector3d Rotate(Vector3d axis, double angle)
        {
            Vector3d vectorToRotate = this;
            Vector3d rotatedVector  = Vector3d.zero;

            if (axis.Equals(Vector3d.up) || axis.Equals(Vector3d.down))
            {
                rotatedVector.x = vectorToRotate.x * Mathd.Cos(angle) + vectorToRotate.z * Mathd.Sin(angle);
                rotatedVector.y = y;
                rotatedVector.z = -vectorToRotate.x * Mathd.Sin(angle) + vectorToRotate.z * Mathd.Cos(angle);
            }
            else if (axis.Equals(Vector3d.left) || axis.Equals(Vector3d.right))
            {
                rotatedVector.x = x;
                rotatedVector.y = vectorToRotate.y * Mathd.Cos(angle) - vectorToRotate.z * Mathd.Sin(angle);
                rotatedVector.z = vectorToRotate.y * Mathd.Sin(angle) + vectorToRotate.z * Mathd.Cos(angle);
            }
            else if (axis.Equals(Vector3d.forward) || axis.Equals(Vector3d.back))
            {
                rotatedVector.x = vectorToRotate.x * Mathd.Cos(angle) - vectorToRotate.y * Mathd.Sin(angle);
                rotatedVector.y = vectorToRotate.x * Mathd.Sin(angle) + vectorToRotate.y * Mathd.Cos(angle);
                rotatedVector.z = z;
            }
            return(rotatedVector);
        }
Exemplo n.º 13
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)));
 }
Exemplo n.º 14
0
 public static double Angle(DVector3 from, DVector3 to)
 {
     return(Mathd.Acos(Mathd.Clamp(DVector3.Dot(from.normalized, to.normalized), -1d, 1d)) * 57.29578d);
 }
Exemplo n.º 15
0
 public static double PingPong(double t, double length)
 {
     t = Mathd.Repeat(t, length * 2d);
     return(length - Mathd.Abs(t - length));
 }
Exemplo n.º 16
0
 public static double Lerp(double from, double to, double t)
 {
     return(from + (to - from) * Mathd.Clamp01(t));
 }
Exemplo n.º 17
0
 public static Vector2d Lerp(Vector2d from, Vector2d to, double t)
 {
     t = Mathd.Clamp01(t);
     return(new Vector2d(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t));
 }
Exemplo n.º 18
0
 public static double MoveTowardsAngle(double current, double target, double maxDelta)
 {
     target = current + Mathd.DeltaAngle(current, target);
     return(Mathd.MoveTowards(current, target, maxDelta));
 }
Exemplo n.º 19
0
 public static Vector2d Max(Vector2d lhs, Vector2d rhs)
 {
     return(new Vector2d(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y)));
 }
Exemplo n.º 20
0
 public bool Similar(Vector3d other, double epsilon = EPSILON)
 {
     return(Mathd.Abs(x - other.x) < epsilon && Mathd.Abs(y - other.y) < epsilon && Mathd.Abs(z - other.z) < epsilon);
 }