public bool InitializeGraphics(IRenderManager manager, Device device) { // Compute the bounding box extents. SharpDX.BoundingBox box = new SharpDX.BoundingBox(this.BoundMin.ToVector3(), this.BoundMax.ToVector3()); // Allocate the vertex array. this.vertices = new D3DColoredVertex[8]; // Calculate the half-widths of the box. float halfWidth = box.Width / 2.0f; float halfHeight = box.Height / 2.0f; float halfDepth = box.Depth / 2.0f; // Build the vertex array from the bounding box info. this.vertices[0].Position = new Vector3(box.Center.X - halfWidth, box.Center.Y - halfHeight, box.Center.Z + halfDepth); this.vertices[1].Position = new Vector3(box.Center.X + halfWidth, box.Center.Y - halfHeight, box.Center.Z + halfDepth); this.vertices[2].Position = new Vector3(box.Center.X + halfWidth, box.Center.Y - halfHeight, box.Center.Z - halfDepth); this.vertices[3].Position = new Vector3(box.Center.X - halfWidth, box.Center.Y - halfHeight, box.Center.Z - halfDepth); this.vertices[4].Position = new Vector3(box.Center.X - halfWidth, box.Center.Y + halfHeight, box.Center.Z + halfDepth); this.vertices[5].Position = new Vector3(box.Center.X + halfWidth, box.Center.Y + halfHeight, box.Center.Z + halfDepth); this.vertices[6].Position = new Vector3(box.Center.X + halfWidth, box.Center.Y + halfHeight, box.Center.Z - halfDepth); this.vertices[7].Position = new Vector3(box.Center.X - halfWidth, box.Center.Y + halfHeight, box.Center.Z - halfDepth); // Setup the vertex buffer using the vertex data stream. BufferDescription desc = new BufferDescription(); desc.BindFlags = BindFlags.VertexBuffer; desc.CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write; desc.StructureByteStride = 28; desc.Usage = ResourceUsage.Default; this.vertexBuffer = SharpDX.Direct3D11.Buffer.Create <D3DColoredVertex>(device, BindFlags.VertexBuffer, this.vertices); // Setup the index buffer using the indice data. desc = new BufferDescription(); desc.BindFlags = BindFlags.IndexBuffer; desc.CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write; desc.StructureByteStride = 4; desc.Usage = ResourceUsage.Default; this.indexBuffer = SharpDX.Direct3D11.Buffer.Create <int>(device, BindFlags.IndexBuffer, this.BoxIndices); // Get the wireframe shader. this.shader = manager.GetBuiltInShader(BuiltInShaderType.Wireframe); return(true); }
public bool InitializeGraphics(IRenderManager manager, Device device) { // Allocate vertex array. this.vertices = new D3DColoredVertex[(RingSegments + 1)]; // Setup the vertex buffer using the vertex data stream. BufferDescription desc = new BufferDescription(); desc.BindFlags = BindFlags.VertexBuffer; desc.CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write; desc.StructureByteStride = 28; desc.Usage = ResourceUsage.Default; this.vertexBuffer = SharpDX.Direct3D11.Buffer.Create <D3DColoredVertex>(device, BindFlags.VertexBuffer, this.vertices); // Get the wireframe shader. this.shader = manager.GetBuiltInShader(BuiltInShaderType.Wireframe); return(true); }