private unsafe void InitVertexBuffers()
        {
            {
                VR02PositionBuffer positionBuffer = new VR02PositionBuffer(strin_Position);
                positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                vec3 *array = (vec3 *)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++)
                        {
                            array[index++] = new vec3(
                                (float)i / (float)xFrameCount - 0.5f,
                                (float)j / (float)yFrameCount - 0.5f,
                                ((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f
                                );
                        }
                    }
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR02UVBuffer uvBuffer = new VR02UVBuffer(strin_uv);
                uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                vec3 *array = (vec3 *)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++)
                        {
                            array[index++] = new vec3(
                                (float)i / (float)xFrameCount,
                                (float)j / (float)yFrameCount,
                                (float)k / (float)zFrameCount
                                );
                        }
                    }
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new ZeroIndexBuffer(DrawMode.Points, 0, xFrameCount * yFrameCount * zFrameCount);
                indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);// this actually does nothing.
                this.indexBufferRenderer = indexBuffer.GetRenderer() as IndexBufferPointerBase;
                indexBuffer.Dispose();
            }
            this.vao = new VertexArrayObject(
                this.indexBufferRenderer,
                this.positionBufferRenderer, this.uvBufferRenderer);
        }
Exemple #2
0
        private unsafe void InitVertexBuffers()
        {
            {
                VR01PositionBuffer positionBuffer = new VR01PositionBuffer(strin_Position);
                positionBuffer.Alloc(zFrameCount);
                QuadPosition *array = (QuadPosition *)positionBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadPosition(
                        new vec3(-xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(-xLength, yLength, (float)i / (float)zFrameCount - 0.5f)
                        );
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR01UVBuffer uvBuffer = new VR01UVBuffer(strin_uv);
                uvBuffer.Alloc(zFrameCount);
                QuadUV *array = (QuadUV *)uvBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadUV(
                        new vec3(0, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 1, (float)i / (float)zFrameCount),
                        new vec3(0, 1, (float)i / (float)zFrameCount)
                        );
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new ZeroIndexBuffer(DrawMode.Quads, 0, zFrameCount * 4);
                indexBuffer.Alloc(zFrameCount);// this actually does nothing.
                this.indexBufferRenderer = indexBuffer.GetRenderer() as IndexBufferPointerBase;
                indexBuffer.Dispose();
            }
            this.vao = new VertexArrayObject(
                this.indexBufferRenderer,
                this.positionBufferRenderer, this.uvBufferRenderer);
        }
        private unsafe void InitVertexBuffers()
        {
            {
                VR02PositionBuffer positionBuffer = new VR02PositionBuffer(strin_Position);
                positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                vec3* array = (vec3*)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++)
                        {
                            array[index++] = new vec3(
                                (float)i / (float)xFrameCount - 0.5f,
                                (float)j / (float)yFrameCount - 0.5f,
                                ((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f
                                );
                        }
                    }
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR02UVBuffer uvBuffer = new VR02UVBuffer(strin_uv);
                uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                vec3* array = (vec3*)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++)
                        {
                            array[index++] = new vec3(
                                (float)i / (float)xFrameCount,
                                (float)j / (float)yFrameCount,
                                (float)k / (float)zFrameCount
                                );
                        }
                    }
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new ZeroIndexBuffer(DrawMode.Points, 0, xFrameCount * yFrameCount * zFrameCount);
                indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);// this actually does nothing.
                this.indexBufferRenderer = indexBuffer.GetRenderer() as ZeroIndexBufferRenderer;
                indexBuffer.Dispose();
            }
            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }
        private unsafe void InitVertexBuffers()
        {
            {
                VR01PositionBuffer positionBuffer = new VR01PositionBuffer(strin_Position);
                positionBuffer.Alloc(zFrameCount);
                QuadPosition* array = (QuadPosition*)positionBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadPosition(
                        new vec3(-xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(-xLength, yLength, (float)i / (float)zFrameCount - 0.5f)
                        );
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR01UVBuffer uvBuffer = new VR01UVBuffer(strin_uv);
                uvBuffer.Alloc(zFrameCount);
                QuadUV* array = (QuadUV*)uvBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadUV(
                        new vec3(0, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 1, (float)i / (float)zFrameCount),
                        new vec3(0, 1, (float)i / (float)zFrameCount)
                        );
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new ZeroIndexBuffer(DrawMode.Quads, 0, zFrameCount * 4);
                indexBuffer.Alloc(zFrameCount);// this actually does nothing.
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }
            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }
Exemple #5
0
        protected unsafe void InitializeVAO()
        {

            vec3[] colors = new vec3[] { new vec3(1, 0, 0), new vec3(0, 1, 0), new vec3(0, 0, 1) };
            // 计算三个坐标轴
            for (int axisIndex = 0; axisIndex < 3; axisIndex++)
            {
                var axisVertexCount = faceCount * 2;

                //  Create a vertex buffer for the vertex data.
                using (var positionBuffer = new AxisPositionBuffer(strin_Position, BufferUsage.StaticDraw))
                {
                    positionBuffer.Alloc(axisVertexCount);
                    vec3* positionArray = (vec3*)positionBuffer.FirstElement();
                    for (int i = 0; i < axisVertexCount; i++)
                    {
                        int face = i / 2;
                        float[] components = new float[]{
                            i % 2 == 1 ? 0 : this.axisLength,
                            (float)(this.radius * Math.Cos(face * (Math.PI * 2) / faceCount)),
                            (float)(this.radius * Math.Sin(face * (Math.PI * 2) / faceCount))};
                        positionArray[i] = new vec3(
                            components[(0 + axisIndex) % 3], components[(2 + axisIndex) % 3], components[(4 + axisIndex) % 3]);
                    }
                    this.positionBufferRenderers[axisIndex] = positionBuffer.GetRenderer();
                }

                //  Now do the same for the color data.
                using (var colorBuffer = new AxisColorBuffer(strin_Color, BufferUsage.StaticDraw))
                {
                    colorBuffer.Alloc(axisVertexCount);
                    vec3* colorArray = (vec3*)colorBuffer.FirstElement();
                    for (int i = 0; i < axisVertexCount; i++)
                    {
                        colorArray[i] = colors[axisIndex];
                    }
                    this.colorBufferRenderers[axisIndex] = colorBuffer.GetRenderer();
                }

                // Now for the index data.
                using (var indexBuffer = new AxisIndexBuffer())
                {
                    int indexLength = axisVertexCount + 2;
                    indexBuffer.Alloc(indexLength);
                    byte* cylinderIndex = (byte*)indexBuffer.FirstElement();
                    for (int i = 0; i < indexLength - 2; i++)
                    {
                        cylinderIndex[i] = (byte)i;
                    }
                    cylinderIndex[indexLength - 2] = 0;
                    cylinderIndex[indexLength - 1] = 1;
                    this.indexBufferRenderers[axisIndex] = indexBuffer.GetRenderer();
                }

            }
            // 计算XZ平面
            {
                int planVertexCount = 4;

                //  Create a vertex buffer for the vertex data.
                using (var positionBuffer = new AxisPositionBuffer(strin_Position, BufferUsage.StaticDraw))
                {
                    positionBuffer.Alloc(planVertexCount);
                    vec3* plan = (vec3*)positionBuffer.FirstElement();
                    {
                        float length = this.axisLength;
                        plan[0] = new vec3(-length, 0, -length);
                        plan[1] = new vec3(-length, 0, length);
                        plan[2] = new vec3(length, 0, length);
                        plan[3] = new vec3(length, 0, -length);
                    }
                    this.planPositionBufferRenderer = positionBuffer.GetRenderer();
                }

                //  Now do the same for the colour data.
                using (var colorBuffer = new AxisColorBuffer(strin_Color, BufferUsage.StaticDraw))
                {
                    colorBuffer.Alloc(planVertexCount);
                    vec3* colorArray = (vec3*)colorBuffer.FirstElement();
                    {
                        for (int i = 0; i < planVertexCount; i++)
                        {
                            colorArray[i] = this.planColor;
                        }
                    }
                    this.planColorBufferRenderer = colorBuffer.GetRenderer();
                }

                using (var indexBuffer = new ZeroIndexBuffer(DrawMode.LineLoop, 0, planVertexCount))
                {
                    indexBuffer.Alloc(planVertexCount);//这句话实际上什么都没有做。
                    this.planIndexBufferRenderer = indexBuffer.GetRenderer();
                }
            }
        }
Exemple #6
0
        unsafe void InitializeVAO()
        {
            vec3[] colors = new vec3[] { new vec3(1, 0, 0), new vec3(0, 1, 0), new vec3(0, 0, 1) };
            // 计算三个坐标轴
            for (int axisIndex = 0; axisIndex < 3; axisIndex++)
            {
                var axisVertexCount = faceCount * 2;

                //  Create a vertex buffer for the vertex data.
                using (var positionBuffer = new AxisPositionBuffer(strin_Position, BufferUsage.StaticDraw))
                {
                    positionBuffer.Alloc(axisVertexCount);
                    vec3 *positionArray = (vec3 *)positionBuffer.FirstElement();
                    for (int i = 0; i < axisVertexCount; i++)
                    {
                        int     face       = i / 2;
                        float[] components = new float[] {
                            i % 2 == 1 ? 0 : this.axisLength,
                            (float)(this.radius * Math.Cos(face * (Math.PI * 2) / faceCount)),
                            (float)(this.radius * Math.Sin(face * (Math.PI * 2) / faceCount))
                        };
                        positionArray[i] = new vec3(
                            components[(0 + axisIndex) % 3], components[(2 + axisIndex) % 3], components[(4 + axisIndex) % 3]);
                    }
                    this.positionBufferRenderers[axisIndex] = positionBuffer.GetRenderer();
                }

                //  Now do the same for the color data.
                using (var colorBuffer = new AxisColorBuffer(strin_Color, BufferUsage.StaticDraw))
                {
                    colorBuffer.Alloc(axisVertexCount);
                    vec3 *colorArray = (vec3 *)colorBuffer.FirstElement();
                    for (int i = 0; i < axisVertexCount; i++)
                    {
                        colorArray[i] = colors[axisIndex];
                    }
                    this.colorBufferRenderers[axisIndex] = colorBuffer.GetRenderer();
                }

                // Now for the index data.
                using (var indexBuffer = new AxisIndexBuffer())
                {
                    int indexLength = axisVertexCount + 2;
                    indexBuffer.Alloc(indexLength);
                    byte *cylinderIndex = (byte *)indexBuffer.FirstElement();
                    for (int i = 0; i < indexLength - 2; i++)
                    {
                        cylinderIndex[i] = (byte)i;
                    }
                    cylinderIndex[indexLength - 2]       = 0;
                    cylinderIndex[indexLength - 1]       = 1;
                    this.indexBufferRenderers[axisIndex] = indexBuffer.GetRenderer() as IndexBufferPointerBase;
                }
            }
            // 计算XZ平面
            {
                int planVertexCount = 4;

                //  Create a vertex buffer for the vertex data.
                using (var positionBuffer = new AxisPositionBuffer(strin_Position, BufferUsage.StaticDraw))
                {
                    positionBuffer.Alloc(planVertexCount);
                    vec3 *plan = (vec3 *)positionBuffer.FirstElement();
                    {
                        float length = this.axisLength;
                        plan[0] = new vec3(-length, 0, -length);
                        plan[1] = new vec3(-length, 0, length);
                        plan[2] = new vec3(length, 0, length);
                        plan[3] = new vec3(length, 0, -length);
                    }
                    this.planPositionBufferRenderer = positionBuffer.GetRenderer();
                }

                //  Now do the same for the colour data.
                using (var colorBuffer = new AxisColorBuffer(strin_Color, BufferUsage.StaticDraw))
                {
                    colorBuffer.Alloc(planVertexCount);
                    vec3 *colorArray = (vec3 *)colorBuffer.FirstElement();
                    {
                        for (int i = 0; i < planVertexCount; i++)
                        {
                            colorArray[i] = this.planColor;
                        }
                    }
                    this.planColorBufferRenderer = colorBuffer.GetRenderer();
                }

                using (var indexBuffer = new ZeroIndexBuffer(DrawMode.LineLoop, 0, planVertexCount))
                {
                    indexBuffer.Alloc(planVertexCount);//这句话实际上什么都没有做。
                    this.planIndexBufferRenderer = indexBuffer.GetRenderer() as IndexBufferPointerBase;
                }
            }
        }