public void Load() { vbo = new VBO(); vbo.PrimitiveType = PrimitiveType.Triangles; List <Vector3> verticesList = new List <Vector3>() { new Vector3(-0.5f, 0.5f, 0.5f), // vertex[0] new Vector3(0.5f, 0.5f, 0.5f), // vertex[1] new Vector3(0.5f, -0.5f, 0.5f), // vertex[2] new Vector3(-0.5f, -0.5f, 0.5f), // vertex[3] new Vector3(-0.5f, 0.5f, -0.5f), // vertex[4] new Vector3(0.5f, 0.5f, -0.5f), // vertex[5] new Vector3(0.5f, -0.5f, -0.5f), // vertex[6] new Vector3(-0.5f, -0.5f, -0.5f), // vertex[7] }; List <uint> indicesList = new List <uint>() { 1, 0, 2, // front 3, 2, 0, 6, 4, 5, // back 4, 6, 7, 4, 7, 0, // left 7, 3, 0, 1, 2, 5, //right 2, 6, 5, 0, 1, 5, // top 0, 5, 4, 2, 3, 6, // bottom 3, 7, 6 }; List <int> colorList = new List <int>() { FromRGBA(1.0f, 0.0f, 0.0f, 1.0f).ToRGBA(), FromRGBA(0.0f, 1.0f, 0.0f, 1.0f).ToRGBA(), FromRGBA(0.0f, 0.0f, 1.0f, 1.0f).ToRGBA(), FromRGBA(0.0f, 1.0f, 1.0f, 1.0f).ToRGBA(), FromRGBA(1.0f, 0.0f, 0.0f, 1.0f).ToRGBA(), FromRGBA(0.0f, 1.0f, 0.0f, 1.0f).ToRGBA(), FromRGBA(0.0f, 0.0f, 1.0f, 1.0f).ToRGBA(), FromRGBA(0.0f, 1.0f, 1.0f, 1.0f).ToRGBA() }; vbo.SetVerticies(verticesList); vbo.SetIndices(indicesList); vbo.SetColors(colorList); }
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); }