Ejemplo n.º 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)));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }