Ejemplo n.º 1
0
            internal TerrainBlock(int x_start, int y_start, int x_count, int y_count, BoundingBox box, int subdivision, Terrain owner)
            {
                bounds = box;
                if (subdivision < owner.Subdivisions)
                {
                    x_count /= 2;
                    y_count /= 2;
                    Vector3 new_size = box.Size / 2;
                    new_size.y = box.Size.y;
                    float offset = box.Size.x / 4;

                    children = new List <TerrainBlock>();

                    children.Add(new TerrainBlock(x_start, y_start, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset)
                    }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, offset)
                    }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start + y_count, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset)
                    }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start, y_start + y_count, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset)
                    }, subdivision + 1, owner));
                }
                else
                {
                    ib = new IndexBuffer <int>();
                    ib.Allocate(6 * (x_count) * (y_count));
                    int index = 0;
                    for (int i = 0; i < y_count; i++)
                    {
                        for (int j = 0; j < x_count; j++)
                        {
                            int i1 = (y_start + i) * owner.heightmap.Width + x_start + j;
                            int i2 = (y_start + i) * owner.heightmap.Width + x_start + j + 1;
                            int i3 = (y_start + i + 1) * owner.heightmap.Width + x_start + j + 1;
                            int i4 = (y_start + i + 1) * owner.heightmap.Width + x_start + j;

                            ib[index++] = i1;
                            ib[index++] = i3;
                            ib[index++] = i2;

                            ib[index++] = i1;
                            ib[index++] = i4;
                            ib[index++] = i3;
                        }
                    }
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    ib.FreeClientData();
                }
            }
Ejemplo n.º 2
0
        protected override void Build()
        {
            vb = new VertexBuffer <Vector3>(Vector3.Descriptor);

            vb.Allocate(8);
            ib = new IndexBuffer <ushort>();
            ib.Allocate(4 * 6);

            vb[0] = new Vector3(-0.5f, -0.5f, -0.5f);
            vb[1] = new Vector3(0.5f, -0.5f, -0.5f);
            vb[2] = new Vector3(0.5f, 0.5f, -0.5f);
            vb[3] = new Vector3(-0.5f, 0.5f, -0.5f);

            vb[4] = new Vector3(-0.5f, -0.5f, 0.5f);
            vb[5] = new Vector3(0.5f, -0.5f, 0.5f);
            vb[6] = new Vector3(0.5f, 0.5f, 0.5f);
            vb[7] = new Vector3(-0.5f, 0.5f, 0.5f);

            ib[0] = 0;
            ib[1] = 1;
            ib[2] = 2;
            ib[3] = 3;

            ib[4] = 4;
            ib[5] = 0;
            ib[6] = 3;
            ib[7] = 7;

            ib[8]  = 5;
            ib[9]  = 4;
            ib[10] = 7;
            ib[11] = 6;

            ib[12] = 1;
            ib[13] = 5;
            ib[14] = 6;
            ib[15] = 2;

            ib[16] = 6;
            ib[17] = 7;
            ib[18] = 3;
            ib[19] = 2;

            ib[20] = 0;
            ib[21] = 4;
            ib[22] = 5;
            ib[23] = 1;

            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            ib.BufferData(VboUsage.GL_STATIC_DRAW);
            // Client data is no longer needed. Free it!
            vb.FreeClientData();
            ib.FreeClientData();
        }
Ejemplo n.º 3
0
            internal TerrainBlock(int x_start, int y_start, int x_count, int y_count,  BoundingBox box, int subdivision, Terrain owner)
            {
                bounds = box;
                if (subdivision < owner.Subdivisions)
                {
                    x_count /= 2;
                    y_count /= 2;
                    Vector3 new_size = box.Size / 2;
                    new_size.y = box.Size.y;
                    float offset = box.Size.x / 4;

                    children = new List<TerrainBlock>();

                    children.Add(new TerrainBlock(x_start, y_start, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset) }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, offset) }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start + y_count, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset) }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start, y_start + y_count, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset) }, subdivision + 1, owner));
                }
                else
                {
                    ib = new IndexBuffer<int>();
                    ib.Allocate(6 * (x_count) * (y_count));
                    int index = 0;
                    for (int i = 0; i < y_count; i++)
                    {
                        for (int j = 0; j < x_count; j++)
                        {
                            int i1 = (y_start + i) * owner.heightmap.Width + x_start + j;
                            int i2 = (y_start + i) * owner.heightmap.Width + x_start + j + 1;
                            int i3 = (y_start + i + 1) * owner.heightmap.Width + x_start + j + 1;
                            int i4 = (y_start + i + 1) * owner.heightmap.Width + x_start + j;

                            ib[index++] = i1;
                            ib[index++] = i3;
                            ib[index++] = i2;

                            ib[index++] = i1;
                            ib[index++] = i4;
                            ib[index++] = i3;
                        }
                    }
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    ib.FreeClientData();
                }
            }
Ejemplo n.º 4
0
        private void GenerateDome()
        {
            int vertices = Segments * Segments * 2 + 1;
            int indices  = Segments * 6 + (Segments - 1) * 2 * Segments * 6;


            vb = new VertexBuffer <SkydomeVertex>(SkydomeVertex.Descriptor);
            ib = new IndexBuffer <uint>();
            vb.Allocate(vertices);
            ib.Allocate(indices);
            int index = 0;

            float vang_inc = (float)(Math.PI / 2) / Segments;
            float hang_inc = (float)(2 * Math.PI) / Segments;

            float hang = hang_inc;
            float vang = vang_inc;

            for (int i = 0; i < Segments; i++, vang += vang_inc)
            {
                float v_c = (float)Math.Cos(vang);
                float v_s = (float)Math.Sin(vang);
                for (int j = 0; j < Segments * 2; j++, hang += hang_inc)
                {
                    float   h_c = (float)Math.Cos(hang);
                    float   h_s = (float)Math.Sin(hang);
                    Vector3 pos = new Vector3(h_c * v_s, v_c, h_s * v_s);
                    vb[index++] = new SkydomeVertex()
                    {
                        Position = pos,
                        Normal   = -pos.Normalize()
                    };
                }
                hang = 0;
            }
            vb[index] = new SkydomeVertex()
            {
                Normal   = Vector3.Down,
                Position = new Vector3(0, 1f, 0)
            };
            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            vb.FreeClientData();
            index = 0;
            for (int i = 0; i < Segments * 2; i++)
            {
                ib[index++] = (uint)vertices - 1;
                ib[index++] = (uint)i;
                ib[index++] = (uint)(i + 1) % (Segments * 2);                 // Wraparound
            }
            for (int i = 0; i < Segments - 1; i++)
            {
                for (int j = 0; j < Segments * 2; j++)
                {
                    int offset_1 = i * Segments * 2;
                    int offset_2 = i * Segments * 2 + Segments * 2;
                    int j2       = (j + 1) % (Segments * 2);

                    ib[index++] = (uint)(offset_1 + j);
                    ib[index++] = (uint)(offset_2 + j);
                    ib[index++] = (uint)(offset_1 + j2);

                    ib[index++] = (uint)(offset_2 + j);
                    ib[index++] = (uint)(offset_2 + j2);
                    ib[index++] = (uint)(offset_1 + j2);
                }
            }
            ib.BufferData(VboUsage.GL_STATIC_DRAW);
            ib.FreeClientData();
        }
Ejemplo n.º 5
0
Archivo: Box.cs Proyecto: r-bel/glorg2
        protected override void Build()
        {
            vb = new VertexBuffer<Vector3>(Vector3.Descriptor);

            vb.Allocate(8);
            ib = new IndexBuffer<ushort>();
            ib.Allocate(4 * 6);

            vb[0] = new Vector3(-0.5f, -0.5f, -0.5f);
            vb[1] = new Vector3(0.5f, -0.5f, -0.5f);
            vb[2] = new Vector3(0.5f, 0.5f, -0.5f);
            vb[3] = new Vector3(-0.5f, 0.5f, -0.5f);

            vb[4] = new Vector3(-0.5f, -0.5f, 0.5f);
            vb[5] = new Vector3(0.5f, -0.5f, 0.5f);
            vb[6] = new Vector3(0.5f, 0.5f, 0.5f);
            vb[7] = new Vector3(-0.5f, 0.5f, 0.5f);

            ib[0] = 0;
            ib[1] = 1;
            ib[2] = 2;
            ib[3] = 3;

            ib[4] = 4;
            ib[5] = 0;
            ib[6] = 3;
            ib[7] = 7;

            ib[8] = 5;
            ib[9] = 4;
            ib[10] = 7;
            ib[11] = 6;

            ib[12] = 1;
            ib[13] = 5;
            ib[14] = 6;
            ib[15] = 2;

            ib[16] = 6;
            ib[17] = 7;
            ib[18] = 3;
            ib[19] = 2;

            ib[20] = 0;
            ib[21] = 4;
            ib[22] = 5;
            ib[23] = 1;

            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            ib.BufferData(VboUsage.GL_STATIC_DRAW);
            // Client data is no longer needed. Free it!
            vb.FreeClientData();
            ib.FreeClientData();
        }