Ejemplo n.º 1
0
        private void GenVertices(ref VertexBufferObjectBase vbo)
        {
            float splitGridSize = m_farPlaneDistance / 2;
            float xLeft = -splitGridSize, xRight = splitGridSize, zNear = -splitGridSize, zFar = splitGridSize;
            Int32 gridSquareCount = (Int32)Math.Ceiling(m_farPlaneDistance / m_gridSquareSize);
            Int32 nodesCount      = gridSquareCount * 8;

            float[,] vertices = new float[nodesCount, 3];

            float localXLeft = xLeft;

            // Draw Grid at X-axis
            for (Int32 i = 0, j = 0; i < gridSquareCount; i++, j += 4, localXLeft += m_gridSquareSize)
            {
                vertices[j, 0] = localXLeft;
                vertices[j, 1] = 0.0f;
                vertices[j, 2] = zNear;

                vertices[j + 1, 0] = localXLeft;
                vertices[j + 1, 1] = 0.0f;
                vertices[j + 1, 2] = zFar;

                vertices[j + 2, 0] = localXLeft + m_gridSquareSize;
                vertices[j + 2, 1] = 0.0f;
                vertices[j + 2, 2] = zFar;

                vertices[j + 3, 0] = localXLeft + m_gridSquareSize;
                vertices[j + 3, 1] = 0.0f;
                vertices[j + 3, 2] = zNear;
            }

            Int32 verticesContinue = nodesCount / 2;

            // Draw Grid at Z-axis
            for (Int32 i = 0, j = verticesContinue; i < gridSquareCount; i++, j += 4, zNear += m_gridSquareSize)
            {
                vertices[j, 0] = xLeft;
                vertices[j, 1] = 0.0f;
                vertices[j, 2] = zNear;

                vertices[j + 1, 0] = xRight;
                vertices[j + 1, 1] = 0.0f;
                vertices[j + 1, 2] = zNear;

                vertices[j + 2, 0] = xRight;
                vertices[j + 2, 1] = 0.0f;
                vertices[j + 2, 2] = zNear + m_gridSquareSize;

                vertices[j + 3, 0] = xLeft;
                vertices[j + 3, 1] = 0.0f;
                vertices[j + 3, 2] = zNear + m_gridSquareSize;
            }

            vbo = new VertexBufferObjectTwoDimension <float>(vertices, OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, 0, 3, VertexBufferObjectBase.DataCarryFlag.Invalidate);
        }
Ejemplo n.º 2
0
        public WorldGrid(float farPlaneDistance)
        {
            m_farPlaneDistance = farPlaneDistance;
            m_shader           = PoolProxy.GetResource <ObtainShaderPool, ShaderAllocationPolicy <WorldGridShader>, string, WorldGridShader>(string.Format("{0}gridVS.glsl,{0}gridFS.glsl", ProjectFolders.ShadersPath));

            m_vao = new VertexArrayObject();
            VertexBufferObjectBase verticesVBO = null;

            GenVertices(ref verticesVBO);
            m_vao.AddVBO(verticesVBO);
            m_vao.BindBuffersToVao();
        }