/// <summary> /// This method gets the debug geometry from the PhysX scene, and draws it to the screen. This is useful for /// making sure that models are being correctly placed within their PhysX bounding boxes, and for checking to /// see if things are physically working without actually drawing them. /// </summary> /// <param name="scene">The PhysX scene that we want to draw debug geometry for.</param> public void DrawPhysXDebug(StillDesign.PhysX.Scene scene) { Camera cam = (Camera)this.Game.Services.GetService(typeof(ICameraService)); _graphics.VertexDeclaration = new VertexDeclaration(_graphics, VertexPositionColor.VertexElements); BasicEffect debugEffect = new BasicEffect(_graphics, null); debugEffect.World = Matrix.Identity; debugEffect.View = cam.View; debugEffect.Projection = cam.Projection; DebugRenderable data = scene.GetDebugRenderable(); debugEffect.Begin(); foreach (EffectPass pass in debugEffect.CurrentTechnique.Passes) { pass.Begin(); if (data.PointCount > 0) { DebugPoint[] points = data.GetDebugPoints(); _graphics.DrawUserPrimitives<DebugPoint>(PrimitiveType.PointList, points, 0, points.Length); } if (data.LineCount > 0) { DebugLine[] lines = data.GetDebugLines(); VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2]; for (int x = 0; x < data.LineCount; x++) { DebugLine line = lines[x]; vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color)); } _graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length); } if (data.TriangleCount > 0) { DebugTriangle[] triangles = data.GetDebugTriangles(); VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3]; for (int x = 0; x < data.TriangleCount; x++) { DebugTriangle triangle = triangles[x]; vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color)); } _graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length); } pass.End(); } debugEffect.End(); }