// creates grid unit grid. public void CreateVertices() { DeleteVertexBuffer(); IGrid grid = this.As <IGrid>(); m_subDiv = grid.Subdivisions; float corner = 0.5f; // grid.Size / 2.0f; float step = 1.0f / (float)m_subDiv; // grid.Size / (float)subDiv; int numLines = (m_subDiv + 1) * 2; int numVerts = numLines * 2; var vertices = new Vec3F[numVerts]; int index = 0; float s = -corner; // Create vertical lines for (int i = 0; i <= m_subDiv; i++) { vertices[index] = new Vec3F(s, 0, corner); vertices[index + 1] = new Vec3F(s, 0, -corner); index += 2; s += step; } // Create horizontal lines s = -corner; for (int i = 0; i <= m_subDiv; i++) { vertices[index] = new Vec3F(corner, 0, s); vertices[index + 1] = new Vec3F(-corner, 0, s); index += 2; s += step; } m_gridVBId = GameEngine.CreateVertexBuffer(vertices); m_gridVertexCount = (uint)vertices.Length; { var vs = new VertexPC[6]; vs[0] = new VertexPC(0.0f, 0.0f, 0.0f, 0xff0000ff); vs[1] = new VertexPC(corner, 0.0f, 0.0f, 0xff0000ff); vs[2] = new VertexPC(0.0f, 0.0f, 0.0f, 0xff00ff00); vs[3] = new VertexPC(0.0f, corner, 0.0f, 0xff00ff00); vs[4] = new VertexPC(0.0f, 0.0f, 0.0f, 0xffff0000); vs[5] = new VertexPC(0.0f, 0.0f, corner, 0xffff0000); m_basisAxesVBId = GameEngine.CreateVertexBuffer(vs); m_basisAxesVertexCount = (uint)vs.Length; } }
// creates grid unit grid. public void CreateVertices() { DeleteVertexBuffer(); IGrid grid = this.As<IGrid>(); m_subDiv = grid.Subdivisions; float corner = 0.5f; // grid.Size / 2.0f; float step = 1.0f / (float)m_subDiv; // grid.Size / (float)subDiv; int numLines = (m_subDiv + 1) * 2; int numVerts = numLines * 2; var vertices = new Vec3F[numVerts]; int index = 0; float s = -corner; // Create vertical lines for (int i = 0; i <= m_subDiv; i++) { vertices[index] = new Vec3F(s, 0, corner); vertices[index + 1] = new Vec3F(s, 0, -corner); index += 2; s += step; } // Create horizontal lines s = -corner; for (int i = 0; i <= m_subDiv; i++) { vertices[index] = new Vec3F(corner, 0, s); vertices[index + 1] = new Vec3F(-corner, 0, s); index += 2; s += step; } m_gridVBId = GameEngine.CreateVertexBuffer(vertices); m_gridVertexCount = (uint)vertices.Length; { var vs = new VertexPC[6]; vs[0] = new VertexPC( 0.0f, 0.0f, 0.0f, 0xff0000ff); vs[1] = new VertexPC(corner, 0.0f, 0.0f, 0xff0000ff); vs[2] = new VertexPC( 0.0f, 0.0f, 0.0f, 0xff00ff00); vs[3] = new VertexPC( 0.0f, corner, 0.0f, 0xff00ff00); vs[4] = new VertexPC( 0.0f, 0.0f, 0.0f, 0xffff0000); vs[5] = new VertexPC( 0.0f, 0.0f, corner, 0xffff0000); m_basisAxesVBId = GameEngine.CreateVertexBuffer(vs); m_basisAxesVertexCount = (uint)vs.Length; } }
public static ulong CreateVertexBuffer(VertexPC[] buffer) { if (buffer == null || buffer.Length < 2) return 0; ulong vbId = 0; fixed (float* ptr = &buffer[0].Position.X) { vbId = NativeCreateVertexBuffer(VertexFormat.VF_PC, ptr, (uint)buffer.Length); } return vbId; }