public void BuildVBO() { VBO vbo = new VBO() { PrimitiveType = PrimitiveType.Triangles, TextureId = terrain.DARK_GRASS }; List <Vector3> verticesList = new List <Vector3>(); List <uint> indicesList = new List <uint>(); List <Vector3> normalsList = new List <Vector3>(); List <Vector2> texcoordsList = new List <Vector2>(); for (int x = X; x <= (X + WIDTH); x++) { for (int z = Z; z <= (Z + HEIGHT); z++) { verticesList.Add(terrain.HeightVectorAt(x, z)); normalsList.Add(terrain.NormalAt(x, z)); texcoordsList.Add(new Vector2((x - X) / (float)WIDTH, (z - Z) / (float)HEIGHT)); } } int stride = WIDTH + 1; for (int x = 0; x < WIDTH; x++) { for (int z = 0; z < HEIGHT; z++) { indicesList.Add((uint)((x) * stride + (z + 1))); indicesList.Add((uint)((x + 1) * stride + (z + 1))); indicesList.Add((uint)((x) * stride + (z))); indicesList.Add((uint)((x + 1) * stride + (z))); indicesList.Add((uint)((x) * stride + (z))); indicesList.Add((uint)((x + 1) * stride + (z + 1))); } } vbo.SetVerticies(verticesList); vbo.SetIndices(indicesList); vbo.SetNormals(normalsList); vbo.SetTexcoords(texcoordsList); VBO = vbo; Triangles = indicesList.Count / 3; }
public void Load() { vbo = new VBO(); vbo.TextureId = Util.LoadTexture("Terrain.Assets.SKYBOX.jpg"); List <Vector3> verticesList = new List <Vector3>(); List <uint> indicesList = new List <uint>(); List <Vector2> texcoordsList = new List <Vector2>(); //forward verticesList.Add(new Vector3(-1, -1, 1)); verticesList.Add(new Vector3(-1, 1, 1)); verticesList.Add(new Vector3(1, 1, 1)); verticesList.Add(new Vector3(1, -1, 1)); texcoordsList.Add(new Vector2(0.25f, 2f / 3f)); texcoordsList.Add(new Vector2(0.25f, 1f / 3f)); texcoordsList.Add(new Vector2(0.5f, 1f / 3f)); texcoordsList.Add(new Vector2(0.5f, 2f / 3f)); indicesList.Add(0); indicesList.Add(1); indicesList.Add(2); indicesList.Add(2); indicesList.Add(3); indicesList.Add(0); //top verticesList.Add(new Vector3(-1, 0.98f, 1)); verticesList.Add(new Vector3(-1, 0.98f, -1)); verticesList.Add(new Vector3(1, 0.98f, -1)); verticesList.Add(new Vector3(1, 0.98f, 1)); texcoordsList.Add(new Vector2(0.255f, 1f / 3f)); texcoordsList.Add(new Vector2(0.255f, 0f / 3f)); texcoordsList.Add(new Vector2(0.495f, 0f / 3f)); texcoordsList.Add(new Vector2(0.495f, 1f / 3f)); indicesList.Add(4); indicesList.Add(5); indicesList.Add(6); indicesList.Add(6); indicesList.Add(7); indicesList.Add(4); //left verticesList.Add(new Vector3(-1, -1, -1)); verticesList.Add(new Vector3(-1, 1, -1)); verticesList.Add(new Vector3(-1, 1, 1)); verticesList.Add(new Vector3(-1, -1, 1)); texcoordsList.Add(new Vector2(0.00f, 2f / 3f)); texcoordsList.Add(new Vector2(0.00f, 1f / 3f)); texcoordsList.Add(new Vector2(0.25f, 1f / 3f)); texcoordsList.Add(new Vector2(0.25f, 2f / 3f)); indicesList.Add(8); indicesList.Add(9); indicesList.Add(10); indicesList.Add(10); indicesList.Add(11); indicesList.Add(8); //right verticesList.Add(new Vector3(1, -1, 1)); verticesList.Add(new Vector3(1, 1, 1)); verticesList.Add(new Vector3(1, 1, -1)); verticesList.Add(new Vector3(1, -1, -1)); texcoordsList.Add(new Vector2(0.50f, 2f / 3f)); texcoordsList.Add(new Vector2(0.50f, 1f / 3f)); texcoordsList.Add(new Vector2(0.75f, 1f / 3f)); texcoordsList.Add(new Vector2(0.75f, 2f / 3f)); indicesList.Add(12); indicesList.Add(13); indicesList.Add(14); indicesList.Add(14); indicesList.Add(15); indicesList.Add(12); //back verticesList.Add(new Vector3(1, -1, -1)); verticesList.Add(new Vector3(1, 1, -1)); verticesList.Add(new Vector3(-1, 1, -1)); verticesList.Add(new Vector3(-1, -1, -1)); texcoordsList.Add(new Vector2(0.75f, 2f / 3f)); texcoordsList.Add(new Vector2(0.75f, 1f / 3f)); texcoordsList.Add(new Vector2(1f, 1f / 3f)); texcoordsList.Add(new Vector2(1f, 2f / 3f)); indicesList.Add(16); indicesList.Add(17); indicesList.Add(18); indicesList.Add(18); indicesList.Add(19); indicesList.Add(16); vbo.SetIndices(indicesList); vbo.SetVerticies(verticesList); vbo.SetTexcoords(texcoordsList); }