Beispiel #1
0
 public void CalculateExtents(ref Matrix3 transform, out Vector2 halfWidth, out Vector2 halfHeight)
 {
     halfWidth  = new Vector2(HalfWidth, 0);
     halfHeight = new Vector2(0, HalfHeight);
     transform.TransformVector(ref halfWidth);
     transform.TransformVector(ref halfHeight);
 }
Beispiel #2
0
 public void CalculateOrientation(ref Matrix3 transform, out Vector2 orientation)
 {
     orientation = Vector2.UnitX;
     transform.TransformVector(ref orientation);
     orientation -= transform.Origin;
     //orientation.X = (float)Math.Cos(transform.Rotation);
     //orientation.Y = (float)Math.Sin(transform.Rotation);
 }
Beispiel #3
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();
        }
Beispiel #4
0
 public void CalculateExtents(ref Matrix3 transform, out Vector2 extents)
 {
     extents = new Vector2(Radius, 0);
     transform.TransformVector(ref extents);
 }