Beispiel #1
0
        public static void Simulate()
        {
            Vector2d vector2d;
            FInt     fInt;
            Vector2d vector2d1;
            FInt     fInt1;
            FInt     halfF;
            Vector2d vector2d2;
            Vector2d vector2d3;
            FInt     fInt2;

            Partition.StartPartitioning();
            for (ushort i = 0; i < DPhysicsManager.PeakCount; i = (ushort)(i + 1))
            {
                Body simObjects = DPhysicsManager.SimObjects[i];
                if (!(simObjects == null) && simObjects.Active)
                {
                    Dictionary <ushort, CollisionPair> myPairs = simObjects.MyPairs;
                    for (ushort j = (ushort)(i + 1); j < DPhysicsManager.PeakCount; j = (ushort)(j + 1))
                    {
                        Body body = DPhysicsManager.SimObjects[j];
                        if (body != null)
                        {
                            CollisionPair item = myPairs[j];
                            item.GenerateCollision();
                            CollisionResult myCollisionResult = item.MyCollisionResult;
                            if (myCollisionResult.Intersect && item.SimulatePhysics)
                            {
                                bool actedCount = simObjects.ActedCount > 0;
                                bool flag       = body.ActedCount > 0;
                                if (actedCount)
                                {
                                    Body actedCount1 = simObjects;
                                    actedCount1.ActedCount = actedCount1.ActedCount - 1;
                                }
                                if (flag)
                                {
                                    Body body1 = body;
                                    body1.ActedCount = body1.ActedCount - 1;
                                }
                                bool mass  = simObjects.Mass != 0;
                                bool mass1 = body.Mass != 0;
                                if (!simObjects.IsTrigger && !body.IsTrigger && (mass || mass1))
                                {
                                    bool flag1 = true;
                                    body.Velocity.Subtract(ref simObjects.Velocity, out vector2d);
                                    if (vector2d.x.AbsoluteValueMoreThan(DPhysicsManager.SleepVelocity.RawValue) || vector2d.y.AbsoluteValueMoreThan(DPhysicsManager.SleepVelocity.RawValue))
                                    {
                                        Vector2d.Dot(ref myCollisionResult.PenetrationVector, ref vector2d, out fInt);
                                        if (fInt.RawValue < (long)0)
                                        {
                                            flag1 = false;
                                        }
                                    }
                                    if (flag1)
                                    {
                                        myCollisionResult.PenetrationVector.Multiply(DPhysicsManager.CollisionDamp.RawValue, out vector2d1);
                                        if (mass && mass1)
                                        {
                                            simObjects.Speed.Add(body.Speed.RawValue, out fInt1);
                                            if (!fInt1.AbsoluteValueMoreThan(DPhysicsManager.SleepVelocity.RawValue))
                                            {
                                                halfF = FInt.HalfF;
                                            }
                                            else
                                            {
                                                body.Speed.Divide(fInt1.RawValue, out halfF);
                                            }
                                            Vector2d vector2d4 = Vector2d.zero;
                                            if (!halfF.AbsoluteValueMoreThan(DPhysicsManager.MinimumCollisionOffset.RawValue))
                                            {
                                                vector2d1.Multiply(DPhysicsManager.MinimumCollisionOffset.RawValue, out vector2d4);
                                            }
                                            else
                                            {
                                                vector2d1.Multiply(halfF.RawValue, out vector2d4);
                                            }
                                            simObjects.Offset(ref vector2d4);
                                            halfF = halfF - FInt.OneF;
                                            if (!halfF.AbsoluteValueMoreThan(DPhysicsManager.MinimumCollisionOffset.RawValue))
                                            {
                                                vector2d1.Multiply(DPhysicsManager.MinimumCollisionOffset.RawValue, out vector2d4);
                                            }
                                            else
                                            {
                                                vector2d1.Multiply(halfF.RawValue, out vector2d4);
                                            }
                                            body.Offset(ref vector2d4);
                                        }
                                        else if (mass)
                                        {
                                            simObjects.Offset(ref vector2d1);
                                        }
                                        else
                                        {
                                            myCollisionResult.PenetrationVector.Invert();
                                            body.Offset(ref vector2d1);
                                        }
                                    }
                                    if (actedCount && flag)
                                    {
                                        if (mass)
                                        {
                                            Vector2d.Dot(ref simObjects.Velocity, ref myCollisionResult.PenetrationDirection, out fInt2);
                                            myCollisionResult.PenetrationDirection.Multiply(fInt2.RawValue, out vector2d2);
                                            vector2d2.Multiply((DPhysicsManager.Restitution * simObjects.Mass).RawValue, out vector2d2);
                                        }
                                        else
                                        {
                                            Vector2d.Dot(ref body.Velocity, ref myCollisionResult.PenetrationDirection, out fInt2);
                                            myCollisionResult.PenetrationDirection.Multiply(fInt2.RawValue, out vector2d2);
                                            vector2d2.Multiply(DPhysicsManager.Restitution.RawValue * (long)body.Mass, out vector2d2);
                                            vector2d2.Invert();
                                        }
                                        if (mass1)
                                        {
                                            Vector2d.Dot(ref body.Velocity, ref myCollisionResult.PenetrationDirection, out fInt2);
                                            myCollisionResult.PenetrationDirection.Multiply(fInt2.RawValue, out vector2d3);
                                            vector2d3.Multiply((DPhysicsManager.Restitution * body.Mass).RawValue, out vector2d3);
                                        }
                                        else
                                        {
                                            Vector2d.Dot(ref simObjects.Velocity, ref myCollisionResult.PenetrationDirection, out fInt2);
                                            myCollisionResult.PenetrationDirection.Multiply(fInt2.RawValue, out vector2d3);
                                            vector2d3.Multiply(DPhysicsManager.Restitution.RawValue * (long)simObjects.Mass, out vector2d3);
                                            vector2d3.Invert();
                                        }
                                        simObjects.ApplyForce(ref vector2d3);
                                        body.ApplyForce(ref vector2d2);
                                        vector2d2.Invert();
                                        vector2d3.Invert();
                                        simObjects.ApplyForce(ref vector2d2);
                                        body.ApplyForce(ref vector2d3);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Body[] bodyArray = DPhysicsManager.SimObjects;
            for (int k = 0; k < (int)bodyArray.Length; k++)
            {
                Body body2 = bodyArray[k];
                if (body2 != null)
                {
                    DPhysicsManager.SimulateBody(body2);
                }
            }
            DPhysicsManager.LastSimulateTime = Time.time;
        }
Beispiel #2
0
 public CollisionResult(CollisionPair _pair)
 {
     this.pair = _pair;
 }