// 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; m_vertices = new Vec3F[numVerts]; int index = 0; float s = -corner; // Create vertical lines for (int i = 0; i <= m_subDiv; i++) { m_vertices[index] = new Vec3F(s, 0, corner); m_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++) { m_vertices[index] = new Vec3F(corner, 0, s); m_vertices[index + 1] = new Vec3F(-corner, 0, s); index += 2; s += step; } m_gridVBId = GameEngine.CreateVertexBuffer(m_vertices); m_gridVertexCount = (uint)m_vertices.Length; }
public static void Init() { if (s_inited) { return; } List <VertexPN> vertList = new List <VertexPN>(); List <Vector3> spherePositions = new List <Vec3F>(); List <Vector3> sphereNormals = new List <Vec3F>(); List <uint> sphereIndices = new List <uint>(); GeometryHelper.CreateSphere(0.5f, FastSphereSlices, FastSphereStacks, spherePositions , sphereNormals, null, sphereIndices); GeometryHelper.AssembleVertexPN(spherePositions, sphereNormals, vertList); s_sphereVertId = GameEngine.CreateVertexBuffer(vertList.ToArray()); s_sphereIndexId = GameEngine.CreateIndexBuffer(sphereIndices.ToArray()); s_sphereIndexCount = (uint)sphereIndices.Count; List <Vec3F> conePos = new List <Vec3F>(); List <uint> coneIndices = new List <uint>(); List <Vec3F> coneNorms = new List <Vec3F>(); GeometryHelper.CreateCylinder(1.0f, 0.0f, 1.0f, 16, 1, conePos, coneNorms, coneIndices); s_coneIndexCount = (uint)coneIndices.Count; GeometryHelper.AssembleVertexPN(conePos, coneNorms, vertList); s_coneVertId = GameEngine.CreateVertexBuffer(vertList.ToArray()); s_coneIndexId = GameEngine.CreateIndexBuffer(coneIndices.ToArray()); // create unit cylinder List <Vec3F> cyPos = new List <Vec3F>(); List <uint> cyIndices = new List <uint>(); List <Vec3F> cyNorms = new List <Vec3F>(); GeometryHelper.CreateCylinder(0.5f, 0.5f, 1.0f, 16, 2, cyPos, cyNorms, cyIndices); GeometryHelper.AssembleVertexPN(cyPos, cyNorms, vertList); s_cylinderVertId = GameEngine.CreateVertexBuffer(vertList.ToArray()); s_cylinderIndexId = GameEngine.CreateIndexBuffer(cyIndices.ToArray()); s_cylinderIndexCount = (uint)cyIndices.Count; // create slim unit torus. List <Vec3F> torPos = new List <Vec3F>(); List <Vec3F> torNorms = new List <Vec3F>(); List <uint> torIndices = new List <uint>(); GeometryHelper.CreateTorus(RingInnerRadias, RingOuterRadias, 40, 6, torPos, torNorms, null, torIndices); GeometryHelper.AssembleVertexPN(torPos, torNorms, vertList); s_torusVertId = GameEngine.CreateVertexBuffer(vertList.ToArray()); s_torusIndexId = GameEngine.CreateIndexBuffer(torIndices.ToArray()); s_torusIndexCount = (uint)torIndices.Count; List <Vector3> cubePos = new List <Vector3>(); List <Vector3> cubeNormals = new List <Vector3>(); List <uint> cubeIndices = new List <uint>(); GeometryHelper.CreateUnitCube(cubePos, cubeNormals, null, cubeIndices); GeometryHelper.AssembleVertexPN(cubePos, cubeNormals, vertList); s_cubeVertId = GameEngine.CreateVertexBuffer(vertList.ToArray()); s_cubeIndexId = GameEngine.CreateIndexBuffer(cubeIndices.ToArray()); s_cubeIndexCount = (uint)cubeIndices.Count; var linePos = new List <Vec3F>(); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(1, 0, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, 1, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, 0, 1)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(-1, 0, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, -1, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, 0, -1)); s_axisStartVertex = 0; s_axisVertexCount = (uint)linePos.Count; // rect pos; linePos.Add(new Vector3(1, 1, 0)); linePos.Add(new Vector3(-1, 1, 0)); linePos.Add(new Vector3(-1, 1, 0)); linePos.Add(new Vector3(-1, -1, 0)); linePos.Add(new Vector3(-1, -1, 0)); linePos.Add(new Vector3(1, -1, 0)); linePos.Add(new Vector3(1, -1, 0)); linePos.Add(new Vector3(1, 1, 0)); s_rectVertexCount = 8; s_rectStartVertex = (uint)linePos.Count - s_rectVertexCount; // unit square linePos.Add(new Vector3(0.5f, 0.5f, 0)); linePos.Add(new Vector3(-0.5f, 0.5f, 0)); linePos.Add(new Vector3(-0.5f, 0.5f, 0)); linePos.Add(new Vector3(-0.5f, -0.5f, 0)); linePos.Add(new Vector3(-0.5f, -0.5f, 0)); linePos.Add(new Vector3(0.5f, -0.5f, 0)); linePos.Add(new Vector3(0.5f, -0.5f, 0)); linePos.Add(new Vector3(0.5f, 0.5f, 0)); s_unitSquareVertexCount = 8; s_unitSquareStartVertex = (uint)linePos.Count - s_unitSquareVertexCount; s_linesVertId = GameEngine.CreateVertexBuffer(linePos.ToArray()); List <Vec3F> circlePos = new List <Vec3F>(); GeometryHelper.CreateCircle(1.0f, 32, circlePos); s_circleVertexCount = (uint)circlePos.Count; s_circleVerts = GameEngine.CreateVertexBuffer(circlePos.ToArray()); List <Vec3F> boxVerts = new List <Vec3F>(); List <uint> boxIndices = new List <uint>(); GeometryHelper.CreateUnitBox(boxVerts, boxIndices); s_boxVertsId = GameEngine.CreateVertexBuffer(boxVerts.ToArray()); s_boxIndicesId = GameEngine.CreateIndexBuffer(boxIndices.ToArray()); s_boxIndicesCount = (uint)boxIndices.Count; List <Vec3F> arrowCapVerts = new List <Vec3F>(); List <Vec3F> arrowCapNormals = new List <Vec3F>(); List <uint> arrowCapIndices = new List <uint>(); GeometryHelper.CreateArrowCap(arrowCapVerts, arrowCapNormals, arrowCapIndices); GeometryHelper.AssembleVertexPN(arrowCapVerts, arrowCapNormals, vertList); s_arrowCapVertId = GameEngine.CreateVertexBuffer(vertList.ToArray()); s_arrowCapIndexId = GameEngine.CreateIndexBuffer(arrowCapIndices.ToArray()); s_arrowCapIndexCount = (uint)arrowCapIndices.Count; List <Vec3F> pivotVerts = new List <Vec3F>(); GeometryHelper.CreateCircle(0.5f, 16, pivotVerts); GeometryHelper.CreateCircle(0.375f, 16, pivotVerts); GeometryHelper.CreateCircle(0.25f, 16, pivotVerts); GeometryHelper.CreateCircle(0.125f, 16, pivotVerts); s_pivotVerts = GameEngine.CreateVertexBuffer(pivotVerts.ToArray()); s_pivotVertexCount = (uint)pivotVerts.Count; s_captionFont = GameEngine.CreateFont("Arial", 14, FontStyle.BOLD); s_inited = true; }
public static void Init() { if (s_inited) { return; } List <Vector3> sphereVerts = new List <Vec3F>(); List <Vector3> sphereNormals = new List <Vec3F>(); List <uint> sphereIndices = new List <uint>(); GeometryHelper.CreateSphere(0.5f, FastSphereSlices, FastSphereStacks, sphereVerts , sphereNormals, null, sphereIndices); s_triLisVbId = GameEngine.CreateVertexBuffer(sphereVerts.ToArray()); s_triListIbid = GameEngine.CreateIndexBuffer(sphereIndices.ToArray()); s_sphereIndexCount = (uint)sphereIndices.Count; s_sphereStartVertex = 0; s_sphereStartVertex = 0; List <Vec3F> conePos = new List <Vec3F>(); List <uint> coneIndices = new List <uint>(); List <Vec3F> coneNorms = new List <Vec3F>(); GeometryHelper.CreateCylinder(1.0f, 0.0f, 1.0f, 16, 1, conePos, coneNorms, coneIndices); s_coneIndexCount = (uint)coneIndices.Count; VertexPN[] conveVB = new VertexPN[conePos.Count]; for (int i = 0; i < conveVB.Length; i++) { conveVB[i].Position = conePos[i]; conveVB[i].Normal = coneNorms[i]; } s_coneVertId = GameEngine.CreateVertexBuffer(conveVB); s_coneIndexId = GameEngine.CreateIndexBuffer(coneIndices.ToArray()); List <Vector3> cubePos = new List <Vector3>(); List <Vector3> cubeNormals = new List <Vector3>(); List <Vector2> cubeTex = new List <Vector2>(); List <uint> cubeIndices = new List <uint>(); GeometryHelper.CreateUnitCube(cubePos, cubeNormals, cubeTex, cubeIndices); VertexPN[] cubeVerts = new VertexPN[cubePos.Count]; for (int i = 0; i < cubeVerts.Length; i++) { cubeVerts[i].Position = cubePos[i]; cubeVerts[i].Normal = cubeNormals[i]; } s_cubeVertId = GameEngine.CreateVertexBuffer(cubeVerts); s_cubeIndexId = GameEngine.CreateIndexBuffer(cubeIndices.ToArray()); s_cubeIndexCount = (uint)cubeIndices.Count; var linePos = new List <Vec3F>(); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(1, 0, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, 1, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, 0, 1)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(-1, 0, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, -1, 0)); linePos.Add(new Vector3(0, 0, 0)); linePos.Add(new Vector3(0, 0, -1)); s_axisStartVertex = 0; s_axisVertexCount = (uint)linePos.Count; // rect pos; linePos.Add(new Vector3(1, 1, 0)); linePos.Add(new Vector3(-1, 1, 0)); linePos.Add(new Vector3(-1, 1, 0)); linePos.Add(new Vector3(-1, -1, 0)); linePos.Add(new Vector3(-1, -1, 0)); linePos.Add(new Vector3(1, -1, 0)); linePos.Add(new Vector3(1, -1, 0)); linePos.Add(new Vector3(1, 1, 0)); s_rectVertexCount = 8; s_rectStartVertex = (uint)linePos.Count - s_rectVertexCount; // unit square linePos.Add(new Vector3(0.5f, 0.5f, 0)); linePos.Add(new Vector3(-0.5f, 0.5f, 0)); linePos.Add(new Vector3(-0.5f, 0.5f, 0)); linePos.Add(new Vector3(-0.5f, -0.5f, 0)); linePos.Add(new Vector3(-0.5f, -0.5f, 0)); linePos.Add(new Vector3(0.5f, -0.5f, 0)); linePos.Add(new Vector3(0.5f, -0.5f, 0)); linePos.Add(new Vector3(0.5f, 0.5f, 0)); s_unitSquareVertexCount = 8; s_unitSquareStartVertex = (uint)linePos.Count - s_unitSquareVertexCount; s_linesVertId = GameEngine.CreateVertexBuffer(linePos.ToArray()); List <Vec3F> circlePos = new List <Vec3F>(); GeometryHelper.CreateCircle(1.0f, 32, circlePos); s_circleVertexCount = (uint)circlePos.Count; s_circleVerts = GameEngine.CreateVertexBuffer(circlePos.ToArray()); RenderFlag = BasicRendererFlags.WireFrame; List <Vec3F> boxVerts = new List <Vec3F>(); List <uint> boxIndices = new List <uint>(); GeometryHelper.CreateUnitBox(boxVerts, boxIndices); s_boxVertsId = GameEngine.CreateVertexBuffer(boxVerts.ToArray()); s_boxIndicesId = GameEngine.CreateIndexBuffer(boxIndices.ToArray()); s_boxIndicesCount = (uint)boxIndices.Count; List <Vec3F> pivotVerts = new List <Vec3F>(); GeometryHelper.CreateCircle(1.0f, 16, pivotVerts); GeometryHelper.CreateCircle(0.75f, 16, pivotVerts); GeometryHelper.CreateCircle(0.5f, 16, pivotVerts); GeometryHelper.CreateCircle(0.25f, 16, pivotVerts); s_pivotVerts = GameEngine.CreateVertexBuffer(pivotVerts.ToArray()); s_pivotVertexCount = (uint)pivotVerts.Count; s_captionFont = GameEngine.CreateFont("Arial", 14, FontStyle.BOLD); s_inited = true; }