Exemplo n.º 1
0
        private unsafe void InitVertexBuffers()
        {
            // http://images.cnblogs.com/cnblogs_com/bitzhuwei/482613/o_Cube-small.jpg
            {
                VR03PositionBuffer positionBuffer = new VR03PositionBuffer(strin_Position);
                positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronPosition *array = (HexahedronPosition *)positionBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x          = ((float)i / (float)xFrameCount - 0.5f) * factor;
                            var y          = ((float)j / (float)yFrameCount - 0.5f) * factor;
                            var z          = (((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f) * factor;
                            var hexahedron = new HexahedronPosition();
                            hexahedron.v0  = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v1  = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v2  = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v3  = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v4  = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v5  = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v6  = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v7  = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            array[index++] = hexahedron;
                        }
                    }
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR03UVBuffer uvBuffer = new VR03UVBuffer(strin_uv);
                uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronUV *array = (HexahedronUV *)uvBuffer.FirstElement();
                int           index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x     = (float)i / (float)xFrameCount;
                            var y     = (float)j / (float)yFrameCount;
                            var z     = (float)k / (float)zFrameCount;
                            var color = new vec3(x, y, z);
                            var uv    = new HexahedronUV();
                            uv.v0          = color;
                            uv.v1          = color;
                            uv.v2          = color;
                            uv.v3          = color;
                            uv.v4          = color;
                            uv.v5          = color;
                            uv.v6          = color;
                            uv.v7          = color;
                            array[index++] = uv;
                        }
                    }
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new VR03IndexBuffer();
                indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronIndex *array = (HexahedronIndex *)indexBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            uint centerIndex = (uint)((i * yFrameCount * zFrameCount + j * zFrameCount + k) * 8);
                            array[index++] = new HexahedronIndex(centerIndex);
                        }
                    }
                }
                this.indexBufferRenderer = indexBuffer.GetRenderer() as IndexBufferPointerBase;
                indexBuffer.Dispose();
            }

            this.vao = new VertexArrayObject(
                this.indexBufferRenderer,
                this.positionBufferRenderer, this.uvBufferRenderer);
        }
Exemplo n.º 2
0
        private unsafe void InitVertexBuffers()
        {
            // http://images.cnblogs.com/cnblogs_com/bitzhuwei/482613/o_Cube-small.jpg
            {
                VR03PositionBuffer positionBuffer = new VR03PositionBuffer(strin_Position);
                positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronPosition* array = (HexahedronPosition*)positionBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x = ((float)i / (float)xFrameCount - 0.5f) * factor;
                            var y = ((float)j / (float)yFrameCount - 0.5f) * factor;
                            var z = (((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f) * factor;
                            var hexahedron = new HexahedronPosition();
                            hexahedron.v0 = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v1 = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v2 = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v3 = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v4 = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v5 = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v6 = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v7 = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            array[index++] = hexahedron;
                        }
                    }
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR03UVBuffer uvBuffer = new VR03UVBuffer(strin_uv);
                uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronUV* array = (HexahedronUV*)uvBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x = (float)i / (float)xFrameCount;
                            var y = (float)j / (float)yFrameCount;
                            var z = (float)k / (float)zFrameCount;
                            var color = new vec3(x, y, z);
                            var uv = new HexahedronUV();
                            uv.v0 = color;
                            uv.v1 = color;
                            uv.v2 = color;
                            uv.v3 = color;
                            uv.v4 = color;
                            uv.v5 = color;
                            uv.v6 = color;
                            uv.v7 = color;
                            array[index++] = uv;
                        }
                    }
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new VR03IndexBuffer();
                indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronIndex* array = (HexahedronIndex*)indexBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            uint centerIndex = (uint)((i * yFrameCount * zFrameCount + j * zFrameCount + k) * 8);
                            array[index++] = new HexahedronIndex(centerIndex);
                        }
                    }
                }
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }

            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }