예제 #1
0
            internal TerrainBlock(Terrain owner, List <int> indices, BoundingBox box, int subdivision)
            {
                bounds = box;

                if (subdivision < owner.Subdivisions)
                {
                    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(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset)
                    }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, offset)
                    }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset)
                    }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset)
                    }, subdivision + 1));
                }
                else
                {
                    List <int> mil = new List <int>();
                    for (int i = 0; i < indices.Count; i += 3)
                    {
                        var i1 = indices[i];
                        var i2 = indices[i + 1];
                        var i3 = indices[i + 2];

                        var v1 = owner.vb[i1];
                        var v2 = owner.vb[i2];
                        var v3 = owner.vb[i3];

                        var p1 = new Vector2(box.Position.x - box.Size.x / 2, box.Position.z - box.Size.z / 2);
                        var p2 = new Vector2(box.Position.x + box.Size.x / 2, box.Position.z + box.Size.z / 2);

                        if ((v1.Position.x >= p1.x && v1.Position.x <= p2.x && v1.Position.z >= p1.y && v1.Position.z <= p2.y) ||
                            (v2.Position.x >= p1.x && v2.Position.x <= p2.x && v2.Position.z >= p1.y && v2.Position.z <= p2.y) ||
                            (v3.Position.x >= p1.x && v3.Position.x <= p2.x && v3.Position.z >= p1.y && v3.Position.z <= p2.y))
                        {
                            mil.Add(i1);
                            mil.Add(i2);
                            mil.Add(i3);
                        }
                    }
                    ib = new IndexBuffer <int>();
                    ib.Allocate(mil);
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    //mil.Clear();
                }
            }
예제 #2
0
        public void InitializeGraphics()
        {
            if (mat == null)
            {
                owner.Resources.Load("shaders\\Grid", out mat);
            }
            if (vb == null)
            {
                vb = new VertexBuffer <VertexPositionColor>(VertexPositionColor.Descriptor);
                vb.Allocate(8);
            }
            if (ib == null)
            {
                ib = new IndexBuffer <uint>();
                ib.Allocate(24);
                ib[0] = 0;
                ib[1] = 1;
                ib[2] = 1;
                ib[3] = 2;
                ib[4] = 2;
                ib[5] = 3;
                ib[6] = 3;
                ib[7] = 0;

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

                ib[15] = 0;
                ib[16] = 4;

                ib[17] = 1;
                ib[18] = 5;

                ib[19] = 2;
                ib[20] = 6;

                ib[21] = 3;
                ib[22] = 7;
                ib.BufferData(VboUsage.GL_STATIC_DRAW);
            }

            if (points != null)
            {
                for (int i = 0; i < 8; i++)
                {
                    vb[i] = new VertexPositionColor()
                    {
                        Position = points[i], Color = Colors.Yellow
                    };
                }
            }

            vb.BufferData(VboUsage.GL_DYNAMIC_DRAW);
        }
예제 #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();
                }
            }
예제 #4
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();
        }
예제 #5
0
파일: Box.cs 프로젝트: 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();
        }
예제 #6
0
        public override Model Build()
        {
            Model ret = new Model();

            var w2 = width / 2;
            var h2 = height / 2;
            var d2 = depth / 2;

            ret.VertexBuffer = new VertexBuffer <VertexPositionTexCoordNormal>(VertexPositionTexCoordNormal.Descriptor);
            ret.VertexBuffer.Allocate(24);
            var vb = ret.VertexBuffer;
            var ib = new IndexBuffer <uint>();

            //ib.Allocate(36);

            Vector3[] pos = new Vector3[8];
            pos[0] = new Vector3(-w2, h2, d2);
            pos[1] = new Vector3(w2, h2, d2);
            pos[2] = new Vector3(w2, h2, -d2);
            pos[3] = new Vector3(-w2, h2, -d2);

            pos[4] = new Vector3(-w2, -h2, d2);
            pos[5] = new Vector3(w2, -h2, d2);
            pos[6] = new Vector3(w2, -h2, -d2);
            pos[7] = new Vector3(-w2, -h2, -d2);


            ret.Parts.Add(
                new ModelPart()
            {
                IndexBuffer = ib
            }
                );

            vb[0] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(0, 0)
            };

            vb[1] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(1, 0)
            };

            vb[2] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(1, 1)
            };
            vb[3] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(0, 1)
            };

            vb[4] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(0, 0)
            };

            vb[5] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(1, 0)
            };

            vb[6] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(1, 1)
            };
            vb[7] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(0, 1)
            };

            vb[8] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[9] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[10] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[11] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[12] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[13] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };


            vb[14] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[15] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[16] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[17] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[18] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };
            vb[19] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[23] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[22] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[21] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };
            vb[20] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };

            int offset = 0;

            ib.Allocate(36);
            for (int i = 0; i < 6; i++)
            {
                offset = AddFaces(i * 4, offset, ib);
            }

            vb.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);
            ib.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);

            return(ret);
        }
예제 #7
0
파일: Terrain.cs 프로젝트: r-bel/glorg2
            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();
                }
            }
예제 #8
0
파일: Terrain.cs 프로젝트: r-bel/glorg2
            internal TerrainBlock(Terrain owner, List<int> indices, BoundingBox box, int subdivision)
            {
                bounds = box;

                if (subdivision < owner.Subdivisions)
                {
                    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(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset) }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, offset) }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset) }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset) }, subdivision + 1));

                }
                else
                {
                    List<int> mil = new List<int>();
                    for (int i = 0; i < indices.Count; i += 3)
                    {
                        var i1 = indices[i];
                        var i2 = indices[i + 1];
                        var i3 = indices[i + 2];

                        var v1 = owner.vb[i1];
                        var v2 = owner.vb[i2];
                        var v3 = owner.vb[i3];

                        var p1 = new Vector2(box.Position.x - box.Size.x / 2, box.Position.z - box.Size.z / 2);
                        var p2 = new Vector2(box.Position.x + box.Size.x / 2, box.Position.z + box.Size.z / 2);

                        if ((v1.Position.x >= p1.x && v1.Position.x <= p2.x && v1.Position.z >= p1.y && v1.Position.z <= p2.y) ||
                            (v2.Position.x >= p1.x && v2.Position.x <= p2.x && v2.Position.z >= p1.y && v2.Position.z <= p2.y) ||
                            (v3.Position.x >= p1.x && v3.Position.x <= p2.x && v3.Position.z >= p1.y && v3.Position.z <= p2.y))
                        {
                            mil.Add(i1);
                            mil.Add(i2);
                            mil.Add(i3);
                        }
                    }
                    ib = new IndexBuffer<int>();
                    ib.Allocate(mil);
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    //mil.Clear();
                }
            }
예제 #9
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();
        }
예제 #10
0
파일: Camera.cs 프로젝트: r-bel/glorg2
        public void InitializeGraphics()
        {
            if(mat == null)
                owner.Resources.Load("shaders\\Grid", out mat);
            if (vb == null)
            {
                vb = new VertexBuffer<VertexPositionColor>(VertexPositionColor.Descriptor);
                vb.Allocate(8);
            }
            if (ib == null)
            {
                ib = new IndexBuffer<uint>();
                ib.Allocate(24);
                ib[0] = 0;
                ib[1] = 1;
                ib[2] = 1;
                ib[3] = 2;
                ib[4] = 2;
                ib[5] = 3;
                ib[6] = 3;
                ib[7] = 0;

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

                ib[15] = 0;
                ib[16] = 4;

                ib[17] = 1;
                ib[18] = 5;

                ib[19] = 2;
                ib[20] = 6;

                ib[21] = 3;
                ib[22] = 7;
                ib.BufferData(VboUsage.GL_STATIC_DRAW);
            }

            if (points != null)
            {
                for (int i = 0; i < 8; i++)
                {
                    vb[i] = new VertexPositionColor() { Position = points[i], Color = Colors.Yellow };
                }
            }

            vb.BufferData(VboUsage.GL_DYNAMIC_DRAW);
        }
예제 #11
0
파일: BoxBuilder.cs 프로젝트: r-bel/glorg2
        public override Model Build()
        {
            Model ret = new Model();

            var w2 = width / 2;
            var h2 = height / 2;
            var d2 = depth / 2;

            ret.VertexBuffer = new VertexBuffer<VertexPositionTexCoordNormal>(VertexPositionTexCoordNormal.Descriptor);
            ret.VertexBuffer.Allocate(24);
            var vb = ret.VertexBuffer;
            var ib = new IndexBuffer<uint>();
            //ib.Allocate(36);

            Vector3[] pos = new Vector3[8];
            pos[0] = new Vector3(-w2, h2, d2);
            pos[1] = new Vector3(w2, h2, d2);
            pos[2] = new Vector3(w2, h2, -d2);
            pos[3] = new Vector3(-w2, h2, -d2);

            pos[4] = new Vector3(-w2, -h2, d2);
            pos[5] = new Vector3(w2, -h2, d2);
            pos[6] = new Vector3(w2, -h2, -d2);
            pos[7] = new Vector3(-w2, -h2, -d2);

            ret.Parts.Add(
                new ModelPart()
                {
                    IndexBuffer = ib
                }
                );

            vb[0] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal = Vector3.Up,
                TexCoord = new Vector2(0, 0)
            };

            vb[1] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal = Vector3.Up,
                TexCoord = new Vector2(1, 0)
            };

            vb[2] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal = Vector3.Up,
                TexCoord = new Vector2(1, 1)
            };
            vb[3] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal = Vector3.Up,
                TexCoord = new Vector2(0, 1)
            };

            vb[4] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal = Vector3.Down,
                TexCoord = new Vector2(0, 0)
            };

            vb[5] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal = Vector3.Down,
                TexCoord = new Vector2(1, 0)
            };

            vb[6] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal = Vector3.Down,
                TexCoord = new Vector2(1, 1)
            };
            vb[7] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal = Vector3.Down,
                TexCoord = new Vector2(0, 1)
            };

            vb[8] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[9] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[10] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[11] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[12] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[13] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[14] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[15] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[16] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[17] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[18] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };
            vb[19] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[23] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[22] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[21] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };
            vb[20] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };

            int offset = 0;
            ib.Allocate(36);
            for (int i = 0; i < 6; i++)
            {
                offset = AddFaces(i * 4, offset, ib);
            }

            vb.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);
            ib.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);

            return ret;
        }