Exemple #1
0
        /// <summary>
        /// Returns the squared distance between the points.
        /// Use this function when the actual distance value is not important.
        /// </summary>
        /// <param name="v1">first position</param>
        /// <param name="v2">second position</param>
        /// <returns>squared distance between the two</returns>
        public static Fix32 DistanceSquared(Vector2F v1, Vector2F v2)
        {
            Fix32 x = v1.x - v2.x;
            Fix32 y = v1.y - v2.y;

            return(x * x + y * y);
        }
Exemple #2
0
 /// <summary>
 /// Creates a new vector using the minimum value components of the given vectors.
 /// </summary>
 /// <param name="v1">first vector</param>
 /// <param name="v2">second vector</param>
 /// <returns>vector containing min x and y from the other two</returns>
 public static Vector2F Min(Vector2F v1, Vector2F v2)
 {
     return(new Vector2F(
                Fix32.Min(v1.x, v2.x),
                Fix32.Min(v1.y, v2.y)
                ));
 }
Exemple #3
0
 /// <summary>
 /// Clamps the x and y components of the given vector inside the min and max components.
 /// </summary>
 /// <param name="value">the vector to clamp</param>
 /// <param name="min">min x and y</param>
 /// <param name="max">max x and y</param>
 /// <returns>clamped vector</returns>
 public static Vector3F Clamp(Vector3F value, Vector3F min, Vector3F max)
 {
     value.x = Fix32.Clamp(value.x, min.x, max.x);
     value.y = Fix32.Clamp(value.y, min.y, max.y);
     value.z = Fix32.Clamp(value.z, min.z, max.z);
     return(value);
 }
Exemple #4
0
 /// <summary>
 /// Creates a new vector using the minimum value components of the given vectors.
 /// </summary>
 /// <param name="v1">first vector</param>
 /// <param name="v2">second vector</param>
 /// <returns>vector containing min x and y from the other two</returns>
 public static Vector3F Min(Vector3F v1, Vector3F v2)
 {
     return(new Vector3F(
                Fix32.Min(v1.x, v2.x),
                Fix32.Min(v1.y, v2.y),
                Fix32.Min(v1.z, v2.z)
                ));
 }
Exemple #5
0
        public static Vector2F operator *(Vector2F v1, float scale)
        {
            Fix32 s = (Fix32)scale;

            v1.x *= s;
            v1.y *= s;
            return(v1);
        }
Exemple #6
0
        /// <summary>
        /// Normalizes this vector, using the inverse square root for faster calculations.
        /// </summary>
        public void Normalize()
        {
            Fix32 sqrMag = this.SqrtMagnitude;
            Fix32 invMag = (sqrMag > Fix32.Zero) ? Fix32.InvSqrt(sqrMag) : Fix32.Zero;

            this.x *= invMag;
            this.y *= invMag;
        }
Exemple #7
0
        /// <summary>
        /// Returns the squared distance between the points.
        /// Use this function when the actual distance value is not important.
        /// </summary>
        /// <param name="v1">first position</param>
        /// <param name="v2">second position</param>
        /// <returns>squared distance between the two</returns>
        public static Fix32 DistanceSquared(Vector3F v1, Vector3F v2)
        {
            Fix32 x = v1.x - v2.x;
            Fix32 y = v1.y - v2.y;
            Fix32 z = v1.z - v2.z;

            return(x * x + y * y + z * z);
        }
Exemple #8
0
        public static Fix32 Sin(Fix32 theta)
        {
            theta = Fix32.Normalized(theta, Fix32.TwoPi);

            bool mirror   = false;
            bool flip     = false;
            int  quadrant = (int)(theta / (Fix32.Pi / (Fix32)2));

            switch (quadrant)
            {
            case 0:
                break;

            case 1:
                mirror = true;
                break;

            case 2:
                flip = true;
                break;

            case 3:
                mirror = true;
                flip   = true;
                break;
            }
            theta = Fix32.Normalized(theta, Fix32.Pi / (Fix32)2);
            if (mirror)
            {
                theta = Fix32.Pi / (Fix32)2 - theta;
            }

            Fix32 thetaSquared = theta * theta;

            Fix32 result = theta;

            Fix32 n          = theta * theta * theta;
            Fix32 Factorial3 = (Fix32)3 * (Fix32)2 * Fix32.One;

            result -= n / Factorial3;

            n *= thetaSquared;
            Fix32 Factorial5 = Factorial3 * (Fix32)4 * (Fix32)5;

            result += (n / Factorial5);

            n *= thetaSquared;
            Fix32 Factorial7 = Factorial5 * (Fix32)6 * (Fix32)7;

            result -= n / Factorial7;

            if (flip)
            {
                result *= -(Fix32)1;
            }
            return(result);
        }
Exemple #9
0
        public static Fix32 Cos(Fix32 theta)
        {
            Fix32 sin = Sin(theta);
            Fix32 cos = Fix32.Sqrt(Fix32.One - (sin * sin));

            if (Fix32.Pi / (Fix32)2 < theta && theta < Fix32.Pi * (Fix32)3 / (Fix32)2)
            {
                cos = -cos;
            }
            else if (-Fix32.Pi * (Fix32)3 / (Fix32)2 < theta && theta < -Fix32.Pi / (Fix32)2)
            {
                cos = -cos;
            }
            return(cos);
        }
Exemple #10
0
 public Vector3F(int x, int y, int z)
 {
     this.x = (Fix32)x;
     this.y = (Fix32)y;
     this.z = (Fix32)z;
 }
Exemple #11
0
 /// <summary>
 /// Returns the euclidean distance between two coordinates.
 /// Note: Heavier than DistanceSquared, because of the Sqrt call.
 /// </summary>
 /// <param name="v1">first position</param>
 /// <param name="v2">second position</param>
 /// <returns>distance between the points</returns>
 public static Fix32 Distance(Vector3F v1, Vector3F v2)
 {
     return(Fix32.Sqrt(DistanceSquared(v1, v2)));
 }
Exemple #12
0
 /// <summary>
 /// Returns a vector containing the absolute value of its components.
 /// </summary>
 public static Vector2F Abs(Vector2F v)
 {
     return(new Vector2F(Fix32.Abs(v.x), Fix32.Abs(v.y)));
 }
Exemple #13
0
 /// <summary>
 /// Returns a vector containing the absolute value of its components.
 /// </summary>
 public static Vector3F Abs(Vector3F v)
 {
     return(new Vector3F(Fix32.Abs(v.x), Fix32.Abs(v.y), Fix32.Abs(v.z)));
 }
Exemple #14
0
 public Vector3F(Fix32 x, Fix32 y, Fix32 z)
 {
     this.x = x;
     this.y = y;
     this.z = z;
 }
Exemple #15
0
 public static Fix32 Tan(Fix32 theta)
 {
     return(Sin(theta) / Cos(theta));
 }
Exemple #16
0
 public Vector2F(Fix32 x, Fix32 y)
 {
     this.x = x;
     this.y = y;
 }
Exemple #17
0
 public Vector3F(Fix32 value)
 {
     this.x = value;
     this.y = value;
     this.z = value;
 }
Exemple #18
0
 public Vector2F(Vector3 v)
 {
     this.x = (Fix32)v.x;
     this.y = (Fix32)v.z;
 }
Exemple #19
0
 public Vector2F(Vector2 v)
 {
     this.x = (Fix32)v.x;
     this.y = (Fix32)v.y;
 }
Exemple #20
0
 public Vector2F(int x, int y)
 {
     this.x = (Fix32)x;
     this.y = (Fix32)y;
 }
Exemple #21
0
 public Vector3F(Vector3 v)
 {
     this.x = (Fix32)v.x;
     this.y = (Fix32)v.y;
     this.z = (Fix32)v.z;
 }
Exemple #22
0
 public static Fix32 SinToCos(Fix32 sin)
 {
     return(Fix32.Sqrt(Fix32.One - (sin * sin)));
 }