Exemplo n.º 1
0
        //private static Vector2[] uv = new Vector2[]{new Vector2(1,0), new Vector2(0,0), new Vector2(0,1), new Vector2(1,1)};
        public List<Vertex> GetVertices(OctreeNode node, Block block, Chunk chunk, World world)
        {
            List<Vertex> vertices = new List<Vertex>();

            int x = (int)(chunk.GetWorldLocation().X + node.origin.X),
                y = (int)(chunk.GetWorldLocation().Y + node.origin.Y),
                z = (int)(chunk.GetWorldLocation().Z + node.origin.Z);

            for(int face = 0; face < 6; face++){
                Vector2[] uv = block.GetUV(face);
                Block block2 = world.GetBlock(x + (addsX[face] * node.blockSize), y + (addsX[face + 6] * node.blockSize), z + (addsX[face + 12] * node.blockSize));
                if(!block2.material.solid)
                {
                    int baseCorner = face * 4;
                    for(int corner = 0; corner < 4; corner++){
                        Vertex vertex = new Vertex(corners[quadsOrder[baseCorner + corner]] * node.blockSize);
                        vertex.position += node.origin - new Vector3(node.blockSize / 2f, node.blockSize / 2f, node.blockSize / 2f);
                        vertex.color = block.material.color * brightness[face];
                        vertex.normal.X = node.blockSize;
                        vertex.normal.Y = block.GetSheetX(face);
                        vertex.normal.Z = block.GetSheetY(face);
                        vertex.texCoord = uv[corner];
                        vertices.Add(vertex);
                        triangles += 2;
                    }
                }
            }
            return vertices;
        }
        private void SetupVertexbuffer()
        {
            List<Vertex> vertexList = new List<Vertex>(16);
            Vertex[] vertices = new Vertex[4];
            vertices[0].color = vertices[1].color = vertices[2].color = vertices[3].color = Vector3.One;
            vertices[0].position = new Vector3(0, 0, 0);
            vertices[1].position = new Vector3(1, 0, 0);
            vertices[2].position = new Vector3(1, 1, 0);
            vertices[3].position = new Vector3(0, 1, 0);

            vertices[0].texCoord = new Vector2(0, 0);
            vertices[1].texCoord = new Vector2(1, 0);
            vertices[2].texCoord = new Vector2(1, 1);
            vertices[3].texCoord = new Vector2(0, 1);
            vertexList.AddRange(vertices);

            vertices[0].texCoord = new Vector2(0, 1);
            vertices[1].texCoord = new Vector2(1, 1);
            vertices[2].texCoord = new Vector2(1, 0);
            vertices[3].texCoord = new Vector2(0, 0);
            vertexList.AddRange(vertices);

            vertices[0].texCoord = new Vector2(1, 0);
            vertices[1].texCoord = new Vector2(0, 0);
            vertices[2].texCoord = new Vector2(0, 1);
            vertices[3].texCoord = new Vector2(1, 1);
            vertexList.AddRange(vertices);

            vertices[0].texCoord = new Vector2(1, 1);
            vertices[1].texCoord = new Vector2(0, 1);
            vertices[2].texCoord = new Vector2(0, 0);
            vertices[3].texCoord = new Vector2(1, 0);
            vertexList.AddRange(vertices);

            vertexbuffer.SetData(vertexList.ToArray());
        }
Exemplo n.º 3
0
 public VertexBuffer(Vertex[] data, int[] order)
 {
     SetData(data, order);
 }
Exemplo n.º 4
0
 public VertexBuffer(Vertex[] data)
 {
     SetData(data);
 }
Exemplo n.º 5
0
 public void SetData(Vertex[] data, int[] order)
 {
     if(data != null && order != null)
     {
         List<Vertex> vertices = new List<Vertex>();
         foreach(int i in order){
             vertices.Add(data[i]);
         }
         //System.Console.WriteLine( data.Length );
         data = vertices.ToArray();
         this.length = data.Length;
         GL.BindBuffer( BufferTarget.ArrayBuffer, id );
         GL.BufferData( BufferTarget.ArrayBuffer, new IntPtr( data.Length * Vertex.Stride ), data, BufferUsageHint.StaticDraw );
     }
 }
Exemplo n.º 6
0
 public void SetData(Vertex[] data)
 {
     if(data != null)
     {
         //System.Console.WriteLine( data.Length );
         this.length = data.Length;
         GL.BindBuffer( BufferTarget.ArrayBuffer, id );
         GL.BufferData( BufferTarget.ArrayBuffer, new IntPtr( data.Length * Vertex.Stride ), data, BufferUsageHint.StaticDraw );
     }
 }