예제 #1
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
        public static fint Atan2(fint F1, fint F2)
        {
            if (F2.raw == 0 && F1.raw == 0)
            {
                return(fint.zero);
            }

            fint result = fint.zero;

            if (F2 > fint.zero)
            {
                result = Atan(F1 / F2);
            }
            else if (F2 < fint.zero)
            {
                if (F1 >= fint.zero)
                {
                    result = (PI - Atan(Abs(F1 / F2)));
                }
                else
                {
                    result = -(PI - Atan(Abs(F1 / F2)));
                }
            }
            else
            {
                result = (F1 >= fint.zero ? PI : -PI) / fint.CreateFromInt(2);
            }

            return(result);
        }
예제 #2
0
 public static FVector2 ClampMagnitude(FVector2 vector, fint maxLength)
 {
     if (vector.sqrMagnitude > maxLength * maxLength)
     {
         return(vector.normalized * maxLength);
     }
     return(vector);
 }
예제 #3
0
        public static FVector3 Project(FVector3 vector, FVector3 onNormal)
        {
            fint num = FVector3.Dot(onNormal, onNormal);

            if (num.raw < 1)
            {
                return(FVector3.zero);
            }
            return(onNormal * FVector3.Dot(vector, onNormal) / num);
        }
예제 #4
0
        public static FVector2 Normalize(FVector2 value)
        {
            fint magnitude = FVector2.Magnitude(value);

            if (magnitude.raw > 1)
            {
                return(value / magnitude);
            }
            return(FVector3.zero);
        }
예제 #5
0
파일: FInt.cs 프로젝트: marwahaha/FacCom
        /// <summary>
        /// Create a fixed-int number from parts.  For example, to create 1.5 pass in 1 and 500.
        /// </summary>
        /// <param name="PreDecimal">The number above the decimal.  For 1.5, this would be 1.</param>
        /// <param name="PostDecimal">The number below the decimal, to three digits.
        /// For 1.5, this would be 500. For 1.005, this would be 5.</param>
        /// <returns>A fixed-int representation of the number parts</returns>
        public static fint FromParts(int PreDecimal, int PostDecimal)
        {
            fint f = fint.CreateFromInt(PreDecimal);

            if (PostDecimal != 0)
            {
                f += (fint.CreateFromInt(PostDecimal) / fint.CreateFromInt(1000));
            }
            return(f);
        }
예제 #6
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Abs(fint F)
 {
     if (F.raw < 0)
     {
         return(-F);
     }
     else
     {
         return(F);
     }
 }
예제 #7
0
        public static FVector2 MoveTowards(FVector2 current, FVector2 target, fint maxDistanceDelta)
        {
            FVector2 a         = target - current;
            fint     magnitude = a.magnitude;

            if (magnitude <= maxDistanceDelta || magnitude == fint.zero)
            {
                return(target);
            }
            return(current + a / magnitude * maxDistanceDelta);
        }
예제 #8
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Clamp01(fint value)
 {
     if (value < fint.zero)
     {
         return(fint.zero);
     }
     if (value > fint.one)
     {
         return(fint.one);
     }
     return(value);
 }
예제 #9
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 private static fint sin_lookup(fint i, fint j)
 {
     if (j.raw > 0 && j < fint.CreateRaw(10) && i < fint.CreateRaw(90))
     {
         return(fint.CreateRaw(SIN_TABLE[i.raw]) +
                ((fint.CreateRaw(SIN_TABLE[i.raw + 1]) - fint.CreateRaw(SIN_TABLE[i.raw])) /
                 fint.CreateRaw(10)) * j);
     }
     else
     {
         return(fint.CreateRaw(SIN_TABLE[i.raw]));
     }
 }
예제 #10
0
        public void Normalize()
        {
            fint magnitude = this.magnitude;

            if (magnitude.raw > 1)
            {
                this /= magnitude;
            }
            else
            {
                this = FVector2.Zero;
            }
        }
예제 #11
0
        public void Normalize()
        {
            fint num = FVector3.Magnitude(this);

            if (num.raw > 1)
            {
                this /= num;
            }
            else
            {
                this = FVector3.zero;
            }
        }
예제 #12
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Clamp(fint value, fint min, fint max)
 {
     if (value < min)
     {
         value = min;
     }
     else
     {
         if (value > max)
         {
             value = max;
         }
     }
     return(value);
 }
예제 #13
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Sqrt(fint f)
 {
     if (f.raw > 0x3e8000)
     {
         return(Sqrt(f, 16 * 3 / 4));
     }
     else if (f.raw > 0x64000)
     {
         return(Sqrt(f, 12 * 2 / 3));
     }
     else
     {
         return(Sqrt(f, 8 * 2 / 3));
     }
 }
예제 #14
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
        public static fint Sqrt(fint f, int NumberOfIterations)
        {
            if (f.raw < 0)               //NaN in Math.Sqrt
            {
                throw new ArithmeticException("Input Error");
            }

            if (f.raw == 0)
            {
                return(fint.zero);
            }

                        #if USE_OPTIMIZATIONS
            long fraw      = f.raw;
            long frawshift = (fraw << fint.SHIFT_AMOUNT);
            long k         = fraw + fint.one.raw >> 1;

            for (int i = 0; i < NumberOfIterations; i++)
            {
                k = (k + (frawshift / k)) >> 1;
            }

            if (k < 0)
            {
                throw new ArithmeticException("Overflow");
            }

            return(fint.CreateRaw((int)k));
                        #else
            fint k = f + fint.one >> 1;
            for (int i = 0; i < NumberOfIterations; i++)
            {
                k = (k + (f / k)) >> 1;
            }

            if (k.raw < 0)
            {
                throw new ArithmeticException("Overflow");
            }

            return(k);
                        #endif
        }
예제 #15
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
        public static fint Min(params fint[] values)
        {
            int num = values.Length;

            if (num == 0)
            {
                return(fint.zero);
            }
            fint num2 = values[0];

            for (int i = 1; i < num; i++)
            {
                if (values[i] < num2)
                {
                    num2 = values[i];
                }
            }
            return(num2);
        }
예제 #16
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
        public static fint Asin(fint F)
        {
            bool isNegative = F.raw < 0;

            F = Abs(F);

            if (F > fint.one)
            {
                throw new ArithmeticException("Bad Asin Input:" + F.ToFloat());
            }

            fint f1 = mul(mul(mul(mul(
                                      fint.CreateRaw(145103 >> fint.SHIFT_AMOUNT), F) -
                                  fint.CreateRaw(599880 >> fint.SHIFT_AMOUNT), F) +
                              fint.CreateRaw(1420468 >> fint.SHIFT_AMOUNT), F) -
                          fint.CreateRaw(3592413 >> fint.SHIFT_AMOUNT), F) +
                      fint.CreateRaw(26353447 >> fint.SHIFT_AMOUNT);

            fint f2 = HalfPI - (Sqrt(fint.one - F) * f1);

            return(isNegative ? -f2 : f2);
        }
예제 #17
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
        public static fint Sin(fint i)
        {
            fint j = fint.zero;

            for ( ; i.raw < 0; i += fint.CreateRaw(25736))
            {
                ;
            }
            if (i > fint.CreateRaw(25736))
            {
                i %= fint.CreateRaw(25736);
            }
            fint k = (i * fint.CreateRaw(10)) / fint.CreateRaw(714);

            if (i.raw != 0 && i != fint.CreateRaw(6434) && i != fint.CreateRaw(12868) &&
                i != fint.CreateRaw(19302) && i != fint.CreateRaw(25736))
            {
                j = (i * fint.CreateRaw(100)) / fint.CreateRaw(714) - k * fint.CreateRaw(10);
            }
            if (k <= fint.CreateRaw(90))
            {
                return(sin_lookup(k, j));
            }
            if (k <= fint.CreateRaw(180))
            {
                return(sin_lookup(fint.CreateRaw(180) - k, j));
            }
            if (k <= fint.CreateRaw(270))
            {
                return(-sin_lookup(k - fint.CreateRaw(180), j));
            }
            else
            {
                return(-sin_lookup(fint.CreateRaw(360) - k, j));
            }
        }
예제 #18
0
 public void Set(fint new_x, fint new_y)
 {
     this.X = new_x;
     this.Y = new_y;
 }
예제 #19
0
 public void Scale(FVector2 scale)
 {
     this.X *= scale.X;
     this.Y *= scale.Y;
 }
예제 #20
0
 public void Set(fint new_x, fint new_y, fint new_z)
 {
     this.x = new_x;
     this.y = new_y;
     this.z = new_z;
 }
예제 #21
0
 //
 // Constructors
 //
 public FVector2(fint x, fint y)
 {
     this.X = x;
     this.Y = y;
 }
예제 #22
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 private static fint mul(fint F1, fint F2)
 {
     return(F1 * F2);
 }
예제 #23
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Cos(fint i)
 {
     return(Sin(i + fint.CreateRaw(6435)));
 }
예제 #24
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Min(fint a, fint b)
 {
     return((a >= b) ? b : a);
 }
예제 #25
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Max(fint a, fint b)
 {
     return((a <= b) ? b : a);
 }
예제 #26
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Tan(fint i)
 {
     return(Sin(i) / Cos(i));
 }
예제 #27
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Acos(fint F)
 {
     return(HalfPI - Asin(F));
 }
예제 #28
0
 public void Scale(FVector3 scale)
 {
     this.x *= scale.x;
     this.y *= scale.y;
     this.z *= scale.z;
 }
예제 #29
0
 public static FVector2 Lerp(FVector2 from, FVector2 to, fint t)
 {
     t = FMath.Clamp01(t);
     return(new FVector2(from.X + (to.X - from.X) * t, from.Y + (to.Y - from.Y) * t));
 }
예제 #30
0
파일: FMath.cs 프로젝트: marwahaha/FacCom
 public static fint Atan(fint F)
 {
     return(Asin(F / Sqrt(fint.one + (F * F))));
 }