private void DrawDebug(DebugRenderable data) { var pass = _visualizationEffect.RenderScenePass0; _visualizationEffect.World.SetMatrix(Matrix.Identity); _visualizationEffect.View.SetMatrix(this.Camera.View); _visualizationEffect.Projection.SetMatrix(this.Camera.Projection); this.GraphicsDevice.InputAssembler.SetInputLayout(_inputLayout); pass.Apply(); if (data.PointCount > 0) { var points = data.GetDebugPoints(); var vertices = new VertexPositionColor[points.Length]; for (int i = 0; i < data.PointCount; i++) { var point = points[i]; vertices[i * 2 + 0] = new VertexPositionColor(point.Point.As <Vector3>(), Color.FromArgb(point.Color)); } DrawVertices(vertices, PrimitiveTopology.PointList); } if (data.LineCount > 0) { var lines = data.GetDebugLines(); var 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.As <Vector3>(), Color.FromArgb(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1.As <Vector3>(), Color.FromArgb(line.Color)); } DrawVertices(vertices, PrimitiveTopology.LineList); } if (data.TriangleCount > 0) { var triangles = data.GetDebugTriangles(); var 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.As <Vector3>(), Color.FromArgb(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1.As <Vector3>(), Color.FromArgb(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2.As <Vector3>(), Color.FromArgb(triangle.Color)); } DrawVertices(vertices, PrimitiveTopology.TriangleList); } // World axis { var vertices = new[] { // X new VertexPositionColor(new Vector3(0, 0, 0), new Color(1, 0, 0)), new VertexPositionColor(new Vector3(5, 0, 0), new Color(1, 0, 0)), // Y new VertexPositionColor(new Vector3(0, 0, 0), new Color(0, 1, 0)), new VertexPositionColor(new Vector3(0, 5, 0), new Color(0, 1, 0)), // Z new VertexPositionColor(new Vector3(0, 0, 0), new Color(0, 0, 1)), new VertexPositionColor(new Vector3(0, 0, 5), new Color(0, 0, 1)), }; DrawVertices(vertices, PrimitiveTopology.LineList); } }
private void PopulatePrimitivesBuffer(VertexPositionColor[] vertices) { using (var stream = _userPrimitivesBuffer.Map(MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None)) { for (int i = 0; i < vertices.Length; i++) { stream.Write(vertices[i]); } } _userPrimitivesBuffer.Unmap(); }
private void DrawVertices(VertexPositionColor[] vertices, PrimitiveTopology top) { PopulatePrimitivesBuffer(vertices); this.GraphicsDevice.InputAssembler.SetPrimitiveTopology(top); this.GraphicsDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_userPrimitivesBuffer, VertexPositionColor.SizeInBytes, 0)); this.GraphicsDevice.Draw(vertices.Length, 0); }
private void DrawDebug(DebugRenderable data) { var pass = _visualizationEffect.RenderScenePass0; _visualizationEffect.World.SetMatrix(Matrix.Identity); _visualizationEffect.View.SetMatrix(this.Camera.View); _visualizationEffect.Projection.SetMatrix(this.Camera.Projection); this.GraphicsDevice.InputAssembler.SetInputLayout(_inputLayout); pass.Apply(); if (data.PointCount > 0) { var points = data.GetDebugPoints(); var vertices = new VertexPositionColor[points.Length]; for (int i = 0; i < data.PointCount; i++) { var point = points[i]; vertices[i * 2 + 0] = new VertexPositionColor(point.Point.As<Vector3>(), Color.FromArgb(point.Color)); } DrawVertices(vertices, PrimitiveTopology.PointList); } if (data.LineCount > 0) { var lines = data.GetDebugLines(); var 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.As<Vector3>(), Color.FromArgb(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1.As<Vector3>(), Color.FromArgb(line.Color)); } DrawVertices(vertices, PrimitiveTopology.LineList); } if (data.TriangleCount > 0) { var triangles = data.GetDebugTriangles(); var 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.As<Vector3>(), Color.FromArgb(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1.As<Vector3>(), Color.FromArgb(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2.As<Vector3>(), Color.FromArgb(triangle.Color)); } DrawVertices(vertices, PrimitiveTopology.TriangleList); } // World axis { var vertices = new[] { // X new VertexPositionColor(new Vector3(0,0,0), new Color(1, 0, 0)), new VertexPositionColor(new Vector3(5,0,0), new Color(1, 0, 0)), // Y new VertexPositionColor(new Vector3(0,0,0), new Color(0, 1, 0)), new VertexPositionColor(new Vector3(0,5,0), new Color(0, 1, 0)), // Z new VertexPositionColor(new Vector3(0,0,0), new Color(0, 0, 1)), new VertexPositionColor(new Vector3(0,0,5), new Color(0, 0, 1)), }; DrawVertices(vertices, PrimitiveTopology.LineList); } }