Example #1
0
 public void BuildBounds()
 {
     if (this.MyBounds == null)
     {
         this.MyBounds = new Bounder(this);
         this.MyBounds.Offset(ref this.center);
         return;
     }
     this.MyBounds.BuildBounds(false);
     this.MyBounds.Offset(ref this.center);
 }
Example #2
0
        public void Offset(ref Vector2d change)
        {
            Bounder rawValue = this;

            rawValue.xMin = rawValue.xMin + change.x.RawValue;
            Bounder bounder = this;

            bounder.xMax = bounder.xMax + change.x.RawValue;
            Bounder rawValue1 = this;

            rawValue1.yMin = rawValue1.yMin + change.y.RawValue;
            Bounder bounder1 = this;

            bounder1.yMax = bounder1.yMax + change.y.RawValue;
        }
Example #3
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);
        }