Esempio n. 1
0
                public static VFixedPoint acos(VFixedPoint a)
                {
                    int num = (int)a.ValueBar * AcosLookupTable.HALF_COUNT / (1 << VFixedPoint.SHIFT_AMOUNT) + AcosLookupTable.HALF_COUNT;

                    num = Math.Min(Math.Max(num, 0), AcosLookupTable.COUNT);
                    return(VFixedPoint.Create(AcosLookupTable.table[num]) / VFixedPoint.Create(0x2710L));
                }
Esempio n. 2
0
 public VIntQuaternion(Quaternion q)
 {
     this.x = VFixedPoint.Create(q.x);
     this.y = VFixedPoint.Create(q.y);
     this.z = VFixedPoint.Create(q.z);
     this.w = VFixedPoint.Create(q.w);
 }
Esempio n. 3
0
        static bool coarseCullingTri(VInt3 center, VInt3 dir, VFixedPoint t, VFixedPoint radius, VInt3[] triVerts)
        {
            VInt3 triCenter = (triVerts[0] + triVerts[1] + triVerts[2]) / VFixedPoint.Create(3);

            // PT: distance between the triangle center and the swept path (an LSS)
            VFixedPoint d = FMath.Sqrt(squareDistance(center, dir, t, triCenter)) - radius - Globals.EPS;

            if (d < VFixedPoint.Zero)
            {
                return(true);
            }

            d *= d;

            if (d <= (triCenter - triVerts[0]).sqrMagnitude)
            {
                return(true);
            }
            if (d <= (triCenter - triVerts[1]).sqrMagnitude)
            {
                return(true);
            }
            if (d <= (triCenter - triVerts[2]).sqrMagnitude)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
            static VFixedPoint eee(VFixedPoint a)
            {
                if (a > VFixedPoint.Create(0.01f))
                {
                    VFixedPoint ee = eee(a / VFixedPoint.Create(2));
                    return(ee * ee);
                }

                return(VFixedPoint.One + a + a * a / VFixedPoint.Create(2) + Pow(a, 3) / VFixedPoint.Create(6));
            }
Esempio n. 5
0
        protected void stepForwardAndStrafe(CollisionWorld collisionWorld, VInt3 walkMove)
        {
            VIntTransform start = VIntTransform.Identity, end = VIntTransform.Identity;

            targetPosition = currentPosition + walkMove;
            VFixedPoint fraction = VFixedPoint.One;
            int         maxIter  = 10;

            while (fraction > VFixedPoint.Create(0.01f) && maxIter-- > 0)
            {
                start.position = currentPosition;
                end.position   = targetPosition;

                List <CastResult> results = new List <CastResult>();
                me.setWorldTransform(start);
                collisionWorld.SweepTest(me, end.position, results);

                if (results.Count > 0)
                {
                    VFixedPoint closestHitFraction = results[0].fraction;
                    VInt3       hitNormalWorld     = results[0].normal;
                    for (int i = 1; i < results.Count; i++)
                    {
                        VFixedPoint afraction = results[i].fraction;
                        if (afraction <= closestHitFraction)
                        {
                            closestHitFraction = afraction;
                            hitNormalWorld     = results[i].normal;
                        }
                    }

                    fraction -= closestHitFraction;
                    updateTargetPositionBasedOnCollision(hitNormalWorld);
                    VInt3       currentDir = targetPosition - currentPosition;
                    VFixedPoint distance2  = currentDir.sqrMagnitude;
                    if (distance2 > Globals.EPS2)
                    {
                        currentDir = currentDir.Normalize();
                        if (VInt3.Dot(currentDir, normalizedDirection) <= VFixedPoint.Zero)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    currentPosition = targetPosition;
                }
            }
        }
Esempio n. 6
0
        public KinematicCharacterController(CollisionObject me, VFixedPoint stepHeight, int upAxis)
        {
            this.upAxis      = upAxis;
            this.addedMargin = VFixedPoint.Two / VFixedPoint.Create(100);
            this.me          = me;
            this.stepHeight  = stepHeight;
            this.gravity     = VFixedPoint.Create(10); // 1G acceleration
            this.fallSpeed   = VFixedPoint.Create(55); // Terminal velocity of a sky diver in m/s.
            this.jumpSpeed   = VFixedPoint.Create(10);
            this.wasOnGround = false;
            VFixedPoint maxSlopeRadians = VFixedPoint.Create(45) / FMath.Trig.Rag2Deg;

            maxSlopeCosine = FMath.Trig.Cos(maxSlopeRadians);
        }
Esempio n. 7
0
            public static VFixedPoint Exp(VFixedPoint a)
            {
                if (a < VFixedPoint.Zero)
                {
                    return(VFixedPoint.One / Exp(-a));
                }
                int n = (int)a.ToInt;

                a -= VFixedPoint.Create(n);
                VFixedPoint e1 = Pow(e, n);
                VFixedPoint e2 = eee(a);

                return(e1 * e2);
            }
Esempio n. 8
0
        public override bool process(BroadphaseProxy proxy)
        {
            ///terminate further ray tests, once the closestHitFraction reached zero
            if (aabbMin == aabbMax)
            {
                return(false);
            }

            CollisionObject collisionObject = proxy.clientObject;

            SweepAlgorithm algorithm = dispatcher.findSweepAlgorithm(collisionObject, this.collisionObject);

            algorithm(this.collisionObject, end, collisionObject, results, VFixedPoint.Create(0.01f));

            return(true);
        }
Esempio n. 9
0
 /// <summary>
 /// 一个自定的ASin函数,对应Excel中针对Sin的计算公式
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public static VFixedPoint AsinSelfDefine(VFixedPoint a)
 {
     if (a >= VFixedPoint.Create(2))
     {
         return(Pi);
     }
     else if (a > VFixedPoint.One)
     {
         return(Pi + asin(a - VFixedPoint.Create(2)));
     }
     else if (a > VFixedPoint.Zero)
     {
         return(asin(a));
     }
     else
     {
         return(VFixedPoint.Zero);
     }
 }
Esempio n. 10
0
 /// <summary>
 /// 一个自定义的Sin函数,对应Excel中针对Sin的计算公式
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public static VFixedPoint SinSelfDefine(VFixedPoint a)
 {
     if (a >= Pi)
     {
         return(VFixedPoint.Create(2));
     }
     else if (a > Pi * VFixedPoint.Half)
     {
         return(VFixedPoint.Create(2) + Sin(a + Pi));
     }
     else if (a > VFixedPoint.Zero)
     {
         return(Sin(a));
     }
     else
     {
         return(VFixedPoint.Zero);
     }
 }
Esempio n. 11
0
                public static VFixedPoint atan2(VFixedPoint y, VFixedPoint x)
                {
                    int num;
                    int num2;

                    if (x < VFixedPoint.Zero)
                    {
                        if (y < VFixedPoint.Zero)
                        {
                            x    = -x;
                            y    = -y;
                            num2 = 1;
                        }
                        else
                        {
                            x    = -x;
                            num2 = -1;
                        }
                        num = -31416;
                    }
                    else
                    {
                        if (y < VFixedPoint.Zero)
                        {
                            y    = -y;
                            num2 = -1;
                        }
                        else
                        {
                            num2 = 1;
                        }
                        num = 0;
                    }
                    int  dIM  = Atan2LookupTable.DIM;
                    long num4 = dIM - 1;
                    long b    = (x >= y) ? x.ValueBar : y.ValueBar;
                    int  num6 = (int)(x.ValueBar * num4 / b);
                    int  num7 = (int)(y.ValueBar * num4 / b);
                    int  num8 = Atan2LookupTable.table[(num7 * dIM) + num6];

                    return(VFixedPoint.Create((num8 + num) * num2) / VFixedPoint.Create(0x2710L));
                }
Esempio n. 12
0
 VInt3(int _x, int _y, int _z)
 {
     this.x = VFixedPoint.Create(_x);
     this.y = VFixedPoint.Create(_y);
     this.z = VFixedPoint.Create(_z);
 }
Esempio n. 13
0
 public VInt3(Vector3 vec3)
 {
     x = VFixedPoint.Create(vec3.x);
     y = VFixedPoint.Create(vec3.y);
     z = VFixedPoint.Create(vec3.z);
 }
Esempio n. 14
0
                public static VFixedPoint Sin(VFixedPoint theta)
                {
                    int index = SinCosLookupTable.getIndex(theta.ValueBar, 1 << VFixedPoint.SHIFT_AMOUNT);

                    return(VFixedPoint.Create(SinCosLookupTable.sin_table[index]) / VFixedPoint.Create(SinCosLookupTable.FACTOR));
                }
Esempio n. 15
0
 public static VFixedPoint getContactBreakingThreshold()
 {
     return(VFixedPoint.Create(4) / VFixedPoint.Create(100));
 }