示例#1
0
 static public void AssertEquals(fint fvalue, float f)
 {
     if (fvalue.ToFloat() != f)
     {
         throw new Exception(string.Format("Expected {0}, got {1}", f, fvalue.ToFloat().ToString()));
     }
 }
示例#2
0
 static public void AssertEquals(fint fvalue, int i)
 {
     if (fvalue.ToInt() != i)
     {
         throw new Exception(string.Format("Expected {0}, got {1}", i, fvalue.ToInt().ToString()));
     }
 }
示例#3
0
        static public void TestFIntFloating()
        {
            //Test basic value
            fint onePointOne = fint.CreateFromFloat(1.1f);

            AssertAlmostEquals(onePointOne, 1.1f);

            //Test addition
            fint twoPointTwo = onePointOne + onePointOne;

            AssertAlmostEquals(twoPointTwo, 2.2f);

            //Test substraction
            AssertAlmostEquals(twoPointTwo - onePointOne, 1.1f);
            AssertEquals(twoPointTwo - onePointOne, onePointOne);

            //Test negation
            AssertAlmostEquals(-twoPointTwo, -2.2f);

            //Test multiplication
            AssertAlmostEquals(twoPointTwo * twoPointTwo, 2.2f * 2.2f);

            //Test division
            AssertEquals(twoPointTwo / twoPointTwo, 1.0f);
            AssertAlmostEquals(twoPointTwo / (twoPointTwo * fint.CreateFromFloat(2.0f)), 0.5f);
        }
示例#4
0
 static public void AssertAlmostEqualsAngleRadians(fint fvalue, float f)
 {
     if (Math.Abs(fvalue.ToFloat() - f) > (float)(2.0f * Math.PI / 180.0f))
     {
         throw new Exception(string.Format("Expected {0}, got {1}", f, fvalue.ToFloat().ToString()));
     }
 }
示例#5
0
        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);
        }
示例#6
0
        private void MoveAboveFloor(VoxelComponent voxel)
        {
            FVector3 position = voxel.position;
            fint     radius   = voxel.radius;

            FVector3 deltaBottom;

            if (voxel.shape == VoxelShape.Sphere)
            {
                deltaBottom = FVector3.down * radius;
            }
            else
            {
                deltaBottom = FVector3.down * voxel.height * fint.half;
            }

            FVector3 bottom = position + deltaBottom;

            int x = bottom.x.ToInt();
            int y = bottom.y.ToInt();
            int z = bottom.z.ToInt();

            if (IsValidPosition(x, y, z))
            {
                if (GetVoxel(x, y, z) != 0 && IsValidPosition(x, y + 1, z))
                {
                    position.y = fint.CreateFromInt(y + 1);

                    voxel.position.y = position.y - deltaBottom.y;
                }
            }
        }
示例#7
0
 static public void AssertEquals(fint fvalue1, fint fvalue2)
 {
     if (fvalue1 != fvalue2)
     {
         throw new Exception(string.Format("Expected {0}, got {1}", fvalue1.ToFloat(), fvalue2.ToFloat()));
     }
 }
示例#8
0
 static public void AssertAlmostEqualsTrig(fint fvalue, float f)
 {
     if (Math.Abs(fvalue.ToFloat() - f) > 0.09f)
     {
         throw new Exception(string.Format("Expected {0}, got {1}", f, fvalue.ToFloat().ToString()));
     }
 }
示例#9
0
 public static FVector2 ClampMagnitude(FVector2 vector, fint maxLength)
 {
     if (vector.sqrMagnitude > maxLength * maxLength)
     {
         return(vector.normalized * maxLength);
     }
     return(vector);
 }
示例#10
0
 protected override void OnInit(Parameters parameters)
 {
     shape      = parameters.GetParameter <VoxelShape>(PARAMETER_SHAPE, VoxelShape.Sphere);
     radius     = parameters.GetParameter <fint>(PARAMETER_RADIUS, fint.half);
     height     = parameters.GetParameter <fint>(PARAMETER_HEIGHT, fint.two);
     position   = parameters.GetParameter <FVector3>(PARAMETER_POSITION, FVector3.zero);
     useGravity = parameters.GetParameter <bool>(PARAMETER_USE_GRAVITY, true);
     color      = parameters.GetParameter <FVector3>(PARAMETER_COLOR, FVector3.one);
 }
示例#11
0
        static public void BenchmarkFixed(int iterations)
        {
            fint result = fint.zero;

            for (int i = 0; i < iterations; i++)
            {
                result += FVector3.one.magnitude;
            }
        }
示例#12
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);
        }
示例#13
0
        /// <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);
        }
示例#14
0
        public static FVector2 Normalize(FVector2 value)
        {
            fint magnitude = FVector2.Magnitude(value);

            if (magnitude.raw > 1)
            {
                return(value / magnitude);
            }
            return(FVector3.zero);
        }
示例#15
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);
        }
示例#16
0
 public static fint Abs(fint F)
 {
     if (F.raw < 0)
     {
         return(-F);
     }
     else
     {
         return(F);
     }
 }
示例#17
0
 public static fint Clamp01(fint value)
 {
     if (value < fint.zero)
     {
         return(fint.zero);
     }
     if (value > fint.one)
     {
         return(fint.one);
     }
     return(value);
 }
示例#18
0
        public void Normalize()
        {
            fint num = FVector3.Magnitude(this);

            if (num.raw > 1)
            {
                this /= num;
            }
            else
            {
                this = FVector3.zero;
            }
        }
示例#19
0
        public void Normalize()
        {
            fint magnitude = this.magnitude;

            if (magnitude.raw > 1)
            {
                this /= magnitude;
            }
            else
            {
                this = FVector2.zero;
            }
        }
示例#20
0
 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]));
     }
 }
示例#21
0
 public static fint Clamp(fint value, fint min, fint max)
 {
     if (value < min)
     {
         value = min;
     }
     else
     {
         if (value > max)
         {
             value = max;
         }
     }
     return(value);
 }
示例#22
0
 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));
     }
 }
示例#23
0
        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
        }
示例#24
0
        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);
        }
示例#25
0
        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);
        }
示例#26
0
        public void Update(fint realDeltaTime)
        {
            if (!initialized)
            {
                return;
            }

            accumulatedTime += realDeltaTime;

            while (initialized && accumulatedTime >= SimulationTime.deltaTime)
            {
                accumulatedTime -= SimulationTime.deltaTime;

                //Updated components
                for (int i = 0; i < componentManagers.Count; i++)
                {
                    componentManagers[i].Update();
                }

                SimulationTime.simulationTime += SimulationTime.deltaTime;
            }
        }
示例#27
0
        static public void TestFIntBasic()
        {
            //Test basic value
            fint one = fint.one;

            AssertEquals(one, 1);
            AssertEquals(one, 1.0f);

            //Test addition
            fint two = one + one;

            AssertEquals(two, 2);
            AssertEquals(two, 2.0f);

            //Test substraction
            fint zero = two - two;

            AssertEquals(zero, 0);
            AssertEquals(zero, 0.0f);

            //Test negation
            fint minustwo = -two;

            AssertEquals(minustwo, -2);
            AssertEquals(minustwo, -2.0f);

            //Test multiplication
            fint minusfour = two * minustwo;

            AssertEquals(minusfour, -4);
            AssertEquals(minusfour, -4.0f);

            //Test division
            AssertEquals(minusfour / two, -2);
            AssertEquals(minusfour / two, -2.0f);
        }
示例#28
0
        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));
            }
        }
示例#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
 public void Set(fint new_x, fint new_y)
 {
     this.x = new_x;
     this.y = new_y;
 }