Beispiel #1
0
        //The length of two point is square root of ( x * x + y * y + z * z ).
        public static int SqrDistance(FixVector3 f1, FixVector3 f2)
        {
            long x = f1.x - f2.x;
            long y = f1.y - f2.y;
            long z = f1.z - f2.z;

            return(Fix32Math.Sqrt((x * x) + (y * y) + (z * z)));
        }
Beispiel #2
0
        public static FixVector2 ClampMagnitude(FixVector2 v, int maxLength)
        {
            long sqrMagnitudeLong = v.sqrMagnitudeLong;
            long num2             = maxLength;

            if (sqrMagnitudeLong > (num2 * num2))
            {
                long b = Fix32Math.Sqrt(sqrMagnitudeLong);
                int  x = (int)Fix32Math.Divide((long)(v.x * maxLength), b);
                return(new FixVector2(x, (int)Fix32Math.Divide((long)(v.x * maxLength), b)));
            }
            return(v);
        }
Beispiel #3
0
        public void Normalize()
        {
            long num  = this.x * 100;
            long num2 = this.y * 100;
            long a    = (num * num) + (num2 * num2);

            if (a != 0)
            {
                long b = Fix32Math.Sqrt(a);
                this.x = (int)Fix32Math.Divide((long)(num * 0x3e8L), b);
                this.y = (int)Fix32Math.Divide((long)(num2 * 0x3e8L), b);
            }
        }
Beispiel #4
0
        public FixVector3 RotateY(int degree)
        {
            FixVector3 num;
            FixFactor  factor;
            FixFactor  factor2;

            Fix32Math.sincos(out factor, out factor2, (long)(0x7ab8 * degree), 0x1b7740L);
            long num2 = factor2.nom * factor.den;
            long num3 = factor2.den * factor.nom;
            long b    = factor2.den * factor.den;

            num.x = (int)Fix32Math.Divide((long)((this.x * num2) + (this.z * num3)), b);
            num.z = (int)Fix32Math.Divide((long)((-this.x * num3) + (this.z * num2)), b);
            num.y = 0;
            return(num.NormalizeTo(Precision));
        }
Beispiel #5
0
        public FixVector3 RotateY(ref FixFactor radians)
        {
            FixVector3 num;
            FixFactor  factor;
            FixFactor  factor2;

            Fix32Math.sincos(out factor, out factor2, radians.nom, radians.den);
            long num2 = factor2.nom * factor.den;
            long num3 = factor2.den * factor.nom;
            long b    = factor2.den * factor.den;

            num.x = (int)Fix32Math.Divide((long)((this.x * num2) + (this.z * num3)), b);
            num.z = (int)Fix32Math.Divide((long)((-this.x * num3) + (this.z * num2)), b);
            num.y = 0;
            return(num.NormalizeTo(0x3e8));
        }
Beispiel #6
0
        public FixVector3 NormalizeTo(int newMagn = 1)
        {
            long num  = this.x;
            long num2 = this.y;
            long num3 = this.z;
            long a    = ((num * num) + (num2 * num2)) + (num3 * num3);

            if (a != 0)
            {
                long b    = Fix32Math.Sqrt(a);
                long num6 = newMagn;

                this.x = (int)Fix32Math.Divide((long)(num * num6), b);
                this.y = (int)Fix32Math.Divide((long)(num2 * num6), b);
                this.z = (int)Fix32Math.Divide((long)(num3 * num6), b);
            }
            return(this);
        }
Beispiel #7
0
        public long Normalize()
        {
            long num  = this.x << 7;
            long num2 = this.y << 7;
            long num3 = this.z << 7;
            long a    = ((num * num) + (num2 * num2)) + (num3 * num3);

            if (a == 0)
            {
                return(0L);
            }
            long b    = Fix32Math.Sqrt(a);
            long num6 = 0x3e8L;

            this.x = (int)Fix32Math.Divide((long)(num * num6), b);
            this.y = (int)Fix32Math.Divide((long)(num2 * num6), b);
            this.z = (int)Fix32Math.Divide((long)(num3 * num6), b);
            return(b >> 7);
        }
Beispiel #8
0
 public static int operator *(int i, FixFactor f)
 {
     return((int)Fix32Math.Divide((long)(i * f.nom), f.den));
 }
Beispiel #9
0
 public static FixVector2 operator /(FixVector2 v, FixFactor f)
 {
     return(Fix32Math.Divide(v, f.den, f.nom));
 }
Beispiel #10
0
 public static FixVector3 operator *(FixVector3 v, FixFactor f)
 {
     return(Fix32Math.Divide(v, f.nom, f.den));
 }
Beispiel #11
0
 public static FixVector3 Lerp(FixVector3 a, FixVector3 b, int factorNom, int factorDen)
 {
     return(new FixVector3(Fix32Math.Divide((int)((b.x - a.x) * factorNom), factorDen) + a.x, Fix32Math.Divide((int)((b.y - a.y) * factorNom), factorDen) + a.y, Fix32Math.Divide((int)((b.z - a.z) * factorNom), factorDen) + a.z));
 }
Beispiel #12
0
 public static FixVector3 Lerp(FixVector3 a, FixVector3 b, FixFactor f)
 {
     return(new FixVector3(((int)Fix32Math.Divide((long)((b.x - a.x) * f.nom), f.den)) + a.x, ((int)Fix32Math.Divide((long)((b.y - a.y) * f.nom), f.den)) + a.y, ((int)Fix32Math.Divide((long)((b.z - a.z) * f.nom), f.den)) + a.z));
 }
Beispiel #13
0
 public static FixVector3 Cross(FixVector3 lhs, FixVector3 rhs)
 {
     return(new FixVector3(Fix32Math.Divide((int)((lhs.y * rhs.z) - (lhs.z * rhs.y)), Precision), Fix32Math.Divide((int)((lhs.z * rhs.x) - (lhs.x * rhs.z)), Precision), Fix32Math.Divide((int)((lhs.x * rhs.y) - (lhs.y * rhs.x)), Precision)));
 }
Beispiel #14
0
        public static FixFactor AngleInt(FixVector3 lhs, FixVector3 rhs)
        {
            long den = lhs.magnitude * rhs.magnitude;

            return(Fix32Math.acos((long)Dot(ref lhs, ref rhs), den));
        }