public void SolveCollision(CollisionBody colA, CollisionBody colB, out CollisionResult result)
 {
     result = CollisionResult.NoCollision;
     ICollisionSolver solver = FindCollisionSovler(colA, colB);
     if (solver != null) 
         result = solver.SolveCollision(colA, colB);
 }
Пример #2
0
        public override void DrawDebug(ref Matrix view, ref Matrix projection)
        {
            G.PrimitiveBatch.Begin(ref projection, ref view);
            for (int i = 0; i < _colliders.Count; i++)
            {
                CollisionBody col = _colliders[i];
                if (col.Shape == null || !col.BelongsToGroup(CollisionGlobals.ViewGroups))
                {
                    continue;
                }

                Matrix3 transform = col.WorldTransform;
                if ((CollisionGlobals.ViewFlags & DebugViewFlags.Shape) != 0)
                {
                    Vector2[] transformedVerts = col.Shape.VerticesCopy;
                    for (int j = 0; j < transformedVerts.Length; j++)
                    {
                        transform.TransformVector(ref transformedVerts[j]);
                    }
                    G.PrimitiveBatch.DrawPolygon(transformedVerts, transformedVerts.Length, CollisionGlobals.ShapeColor);
                }

                if ((CollisionGlobals.ViewFlags & DebugViewFlags.Extents) != 0)
                {
                    if (col.Shape is Box)
                    {
                        Box     box = (Box)col.Shape;
                        Vector2 halfwidthX, halfwidthY;
                        box.CalculateExtents(ref transform, out halfwidthX, out halfwidthY);
                        G.PrimitiveBatch.DrawSegment(col.Position, halfwidthX, CollisionGlobals.ExtentsColor);
                        G.PrimitiveBatch.DrawSegment(col.Position, halfwidthY, CollisionGlobals.ExtentsColor);
                    }
                    else if (col.Shape is Circle)
                    {
                        Circle  circle = (Circle)col.Shape;
                        Vector2 extents;
                        circle.CalculateExtents(ref transform, out extents);
                        G.PrimitiveBatch.DrawSegment(col.Position, extents, CollisionGlobals.ExtentsColor);
                    }
                }

                if ((CollisionGlobals.ViewFlags & DebugViewFlags.AABB) != 0)
                {
                    AABB aabb;
                    col.Shape.CalculateAABB(ref transform, out aabb);
                    G.PrimitiveBatch.DrawSegment(new Vector2(aabb.Min.X, aabb.Min.Y), new Vector2(aabb.Max.X, aabb.Min.Y), CollisionGlobals.BoundingColor);
                    G.PrimitiveBatch.DrawSegment(new Vector2(aabb.Max.X, aabb.Min.Y), new Vector2(aabb.Max.X, aabb.Max.Y), CollisionGlobals.BoundingColor);
                    G.PrimitiveBatch.DrawSegment(new Vector2(aabb.Min.X, aabb.Max.Y), new Vector2(aabb.Max.X, aabb.Max.Y), CollisionGlobals.BoundingColor);
                    G.PrimitiveBatch.DrawSegment(new Vector2(aabb.Min.X, aabb.Min.Y), new Vector2(aabb.Min.X, aabb.Max.Y), CollisionGlobals.BoundingColor);
                }
            }
            if ((CollisionGlobals.ViewFlags & DebugViewFlags.CollisionResponse) != 0)
            {
                while (CollisionGlobals.Results.Count > 0)
                {
                    CollisionResult result = CollisionGlobals.Results.Pop();
                    G.PrimitiveBatch.DrawSegment(result.Us.Position, result.Us.Position + 10 * result.CollisionResponse, CollisionGlobals.ResponseColor);
                }
            }
            G.PrimitiveBatch.End();
            //G.SpriteBatch.Begin();
            //G.SpriteBatch.DrawString(G.Font, DebugInfo, new Vector2(0, 50), Color.White);
            //G.SpriteBatch.End();
        }