/// <summary> /// Generates a vertex array from specified components /// </summary> /// <param name="vertices">Vertices</param> /// <param name="colors">Colors</param> /// <returns>Returns the new generated vertex array</returns> public static VertexPositionColor[] Generate(Vector3[] vertices, Color4[] colors) { if (vertices.Length != colors.Length) { throw new ArgumentException("Vertices and colors must have the same length"); } VertexPositionColor[] res = new VertexPositionColor[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { res[i] = new VertexPositionColor() { Position = vertices[i], Color = colors[i] }; } return(res); }
public static void DrawBoundingBox(BoundingBox bBox, GraphicsDevice device, BasicEffect basicEffect, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix) { Vector3 v1 = bBox.Min; Vector3 v2 = bBox.Max; VertexPositionColor[] cubeLineVertices = new VertexPositionColor[8]; cubeLineVertices[0] = new VertexPositionColor(v1, Color.White); cubeLineVertices[1] = new VertexPositionColor(new Vector3(v2.X, v1.Y, v1.Z), Color.Red); cubeLineVertices[2] = new VertexPositionColor(new Vector3(v2.X, v1.Y, v2.Z), Color.Green); cubeLineVertices[3] = new VertexPositionColor(new Vector3(v1.X, v1.Y, v2.Z), Color.Blue); cubeLineVertices[4] = new VertexPositionColor(new Vector3(v1.X, v2.Y, v1.Z), Color.White); cubeLineVertices[5] = new VertexPositionColor(new Vector3(v2.X, v2.Y, v1.Z), Color.Red); cubeLineVertices[6] = new VertexPositionColor(v2, Color.Green); cubeLineVertices[7] = new VertexPositionColor(new Vector3(v1.X, v2.Y, v2.Z), Color.Blue); short[] cubeLineIndices = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; basicEffect.World = Matrix.Identity; // worldMatrix; basicEffect.View = viewMatrix; basicEffect.Projection = projectionMatrix; basicEffect.VertexColorEnabled = true; //device.RenderState.FillMode = FillMode.WireFrame; device.RasterizerState.FillMode = FillMode.WireFrame; //basicEffect.Begin(); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { //pass.Begin(); pass.Apply(); //device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); device.DrawUserIndexedPrimitives <VertexPositionColor>(PrimitiveType.LineList, cubeLineVertices, 0, 8, cubeLineIndices, 0, 12); //pass.End(); } //basicEffect.End(); //device.RenderState.FillMode = device.RasterizerState.FillMode = FillMode.Solid; }