Example #1
0
 public void Initialize(Vector2d position)
 {
     this.leTransform          = base.transform;
     this.leTransform.position = (Vector3)position;
     this.curPosition          = this.leTransform.position;
     this.lastposition         = this.leTransform.position;
     this.dCollider            = base.gameObject.GetComponent <DCollider>();
     this.dCollider.Initialize(this);
     this.Offset(ref position);
     this.Rotation     = Vector2d.up;
     this.rotation     = Vector2d.up;
     this.lastrotation = Quaternion.identity;
     this.currotation  = Quaternion.identity;
     DPhysicsManager.Assimilate(this);
 }
Example #2
0
        public static bool CanIntersect(DCollider polyA, DCollider polyB, ref FInt CombinedSqrRadius, out FInt sqrdistance)
        {
            sqrdistance = new FInt();
            Vector2d vector2d;

            if (polyA.MyBounds.xMax >= polyB.MyBounds.xMin && polyA.MyBounds.xMin <= polyB.MyBounds.xMax && polyA.MyBounds.yMax >= polyB.MyBounds.yMin && polyA.MyBounds.yMin <= polyB.MyBounds.yMax)
            {
                polyA.center.Subtract(ref polyB.center, out vector2d);
                vector2d.SqrMagnitude(out sqrdistance);
                if (sqrdistance.RawValue <= CombinedSqrRadius.RawValue)
                {
                    return(true);
                }
            }
            sqrdistance.RawValue = (long)0;
            return(false);
        }
Example #3
0
 void OnEnable()
 {
     dCollider = (DCollider)target;
 }
Example #4
0
 public Bounder(DCollider pol)
 {
     this.polygon = pol;
     this.BuildBounds(true);
 }
Example #5
0
        public void Calculate()
        {
            FInt     fInt;
            FInt     fInt1;
            Vector2d vector2d;
            Vector2d vector2d1;
            Vector2d vector2d2;
            Vector2d vector2d3;
            Vector2d vector2d4;
            FInt     fInt2;
            int      num;

            this.Intersect         = false;
            this.PenetrationVector = Vector2d.zero;
            DCollider bodyA = this.pair.BodyA.dCollider;
            DCollider bodyB = this.pair.BodyB.dCollider;

            if (bodyA.MyBounds.IsCircle && bodyB.MyBounds.IsCircle)
            {
                if (Bounder.CanIntersect(bodyA, bodyB, ref this.pair.CombinedSqrRadius, out fInt))
                {
                    if (!bodyA.IsCircle || !bodyB.IsCircle)
                    {
                        goto Label0;
                    }
                    this.Intersect = true;
                    Mathd.Sqrt(fInt.RawValue, out fInt1);
                    if (fInt1.RawValue <= (long)0)
                    {
                        bodyA.center.Subtract(ref this.pair.BodyA.Velocity, out vector2d1);
                        bodyB.center.Subtract(ref this.pair.BodyB.Velocity, out vector2d2);
                        vector2d1.Subtract(ref vector2d2, out vector2d);
                        vector2d.Magnitude(out fInt1);
                        vector2d.Normalize();
                    }
                    else
                    {
                        bodyA.center.Subtract(ref bodyB.center, out vector2d);
                        vector2d.Normalize();
                    }
                    FInt fInt3 = (bodyA.radius + bodyB.radius) - fInt1;
                    vector2d.Multiply(fInt3.RawValue, out this.PenetrationVector);
                    this.PenetrationDirection = vector2d;
                }
                return;
            }
            else if (!Bounder.CanIntersect(bodyA, bodyB))
            {
                return;
            }
Label0:
            num = (bodyA.Edges != null ? (int)bodyA.Edges.Length : 0);
            int      num1      = num;
            int      num2      = (bodyB.Edges != null ? (int)bodyB.Edges.Length : 0);
            FInt     maxValue  = FInt.MaxValue;
            Vector2d vector2d5 = new Vector2d();

            this.Intersect = true;
            for (int i = 0; i < num1 + num2; i++)
            {
                vector2d3 = (i >= num1 ? bodyB.Edges[i - num1] : bodyA.Edges[i]);
                Vector2d vector2d6 = vector2d3.localright;
                vector2d6.Normalize();
                FInt zeroF  = FInt.ZeroF;
                FInt zeroF1 = FInt.ZeroF;
                FInt zeroF2 = FInt.ZeroF;
                FInt zeroF3 = FInt.ZeroF;
                CollisionResult.ProjectPolygon(vector2d6, bodyA, out zeroF, out zeroF2);
                CollisionResult.ProjectPolygon(vector2d6, bodyB, out zeroF1, out zeroF3);
                FInt fInt4 = CollisionResult.IntervalDistance(zeroF, zeroF2, zeroF1, zeroF3);
                if (fInt4.RawValue >= (long)0)
                {
                    this.Intersect = false;
                    return;
                }
                fInt4.Inverse(out fInt4);
                if (fInt4.RawValue < maxValue.RawValue)
                {
                    maxValue  = fInt4;
                    vector2d5 = vector2d6;
                    bodyA.center.Subtract(ref bodyB.center, out vector2d4);
                    Vector2d.Dot(ref vector2d4, ref vector2d5, out fInt2);
                    if (fInt2.RawValue < (long)0)
                    {
                        vector2d5.Invert();
                    }
                }
            }
            this.PenetrationDirection = vector2d5;
            vector2d5.Multiply(maxValue.RawValue, out this.PenetrationVector);
        }