Ejemplo n.º 1
0
        public bool Intersects(AABB2D b)
        {
            if (Math.Abs(this.Pos.X - b.Pos.X) > (this.HalfExtents.X + b.HalfExtents.X)) return false;
            if (Math.Abs(this.Pos.Y - b.Pos.Y) > (this.HalfExtents.Y + b.HalfExtents.Y)) return false;

            return true;
        }
Ejemplo n.º 2
0
        public static AABB2D CreateMerged(AABB2D a, AABB2D b)
        {
            Vector2 min = Vector2.Min(a.Pos - a.HalfExtents, b.Pos - b.HalfExtents);
            Vector2 max = Vector2.Max(a.Pos + a.HalfExtents, b.Pos + b.HalfExtents);

            return(CreateFromMinMax(min, max));
        }
Ejemplo n.º 3
0
        public static AABB2D CreateMerged(AABB2D a, AABB2D b)
        {
            Vector2 min = Vector2.Min(a.Pos - a.HalfExtents, b.Pos - b.HalfExtents);
            Vector2 max = Vector2.Max(a.Pos + a.HalfExtents, b.Pos + b.HalfExtents);

            return CreateFromMinMax(min, max);
        }
Ejemplo n.º 4
0
        public LineBody(Vector2 normal, Vector2 p)
            : base(p, Vector2.Zero, 0f, 0, 0f)
        {
            this.normal = Vector2.Normalize(normal);
            this.p = p;

            //A line extends infinitely, so make our AABB as big as possible
            motionBounds = new AABB2D(Vector2.Zero, new Vector2(float.MaxValue, float.MaxValue));
        }
Ejemplo n.º 5
0
        public override void GenerateMotionAABB(float dt)
        {
            Vector2 predictedPos = Pos + (Vel * dt);

            Vector2 center = (Pos + predictedPos) / 2f;
            Vector2 halfExtents = new Vector2((Math.Abs(predictedPos.X-Pos.X) * 0.5f) + radius, (Math.Abs(predictedPos.Y-Pos.Y) * 0.5f) + radius);

            motionBounds = new AABB2D(center, halfExtents);
        }
Ejemplo n.º 6
0
        public bool Intersects(AABB2D b)
        {
            if (Math.Abs(this.Pos.X - b.Pos.X) > (this.HalfExtents.X + b.HalfExtents.X))
            {
                return(false);
            }
            if (Math.Abs(this.Pos.Y - b.Pos.Y) > (this.HalfExtents.Y + b.HalfExtents.Y))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        public static Circle2D CreateFromPoints(Vector2[] points)
        {
            Circle2D circle = new Circle2D();
            AABB2D   box    = AABB2D.CreateFromPoints(points);

            circle.Pos = box.Pos;
            float maxDist = float.MinValue;

            for (int i = 0; i < points.Length; i++)
            {
                if ((points[i] - circle.Pos).LengthSquared() > maxDist)
                {
                    maxDist = (points[i] - circle.Pos).LengthSquared();
                }
            }

            maxDist = (float)Math.Sqrt(maxDist);

            circle.Radius = maxDist;

            return(circle);
        }
Ejemplo n.º 8
0
        public override void GenerateMotionAABB(float dt)
        {
            if (circles == null)
            {
                return;
            }

            Vector2 predictedPos = Pos + (Vel * dt);

            Vector2 oldMin = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 oldMax = new Vector2(float.MinValue, float.MinValue);
            Vector2 newMin = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 newMax = new Vector2(float.MinValue, float.MinValue);

            float rotDiff = RotVel * dt;
            Vector2 r1 = new Vector2((float)Math.Cos(rotDiff), (float)-Math.Sin(rotDiff));
            Vector2 r2 = new Vector2((float)Math.Sin(rotDiff), (float)Math.Cos(rotDiff));

            foreach (CircleBody c in circles)
            {
                Vector2 oldPos = this.Pos + c.Pos;

                oldMin = new Vector2(Math.Min(oldMin.X, oldPos.X - c.Radius), Math.Min(oldMin.Y, oldPos.Y - c.Radius));
                oldMax = new Vector2(Math.Max(oldMax.X, oldPos.X + c.Radius), Math.Max(oldMax.Y, oldPos.Y + c.Radius));

                Vector2 newPos = predictedPos + new Vector2(Vector2.Dot(r1,c.Pos), Vector2.Dot(r2, c.Pos));

                newMin = new Vector2(Math.Min(newMin.X, newPos.X - c.Radius), Math.Min(newMin.Y, newPos.Y - c.Radius));
                newMax = new Vector2(Math.Max(newMax.X, newPos.X + c.Radius), Math.Max(newMax.Y, newPos.Y + c.Radius));
            }

            Vector2 finalMin = Vector2.Min(oldMin, newMin);
            Vector2 finalMax = Vector2.Max(oldMax, newMax);

            Vector2 center = new Vector2(finalMin.X + (finalMax.X - finalMin.X) / 2f, finalMin.Y + (finalMax.Y - finalMin.Y) / 2f);

            motionBounds = new AABB2D(center, new Vector2((finalMax.X-finalMin.X) / 2f, (finalMax.Y-finalMin.Y)/2f));
        }