Exemplo n.º 1
0
        /*
         * Used to draw the outline of the terrain quads bounding box.
         * See the DrawQuadTree.cs script for more info.
         */
        public void DrawQuadOutline(Camera camera, Material lineMaterial, Color lineColor)
        {
            if (IsLeaf())
            {
                if (m_visible == Frustum.VISIBILTY.INVISIBLE)
                {
                    return;
                }

                Vector3[] verts = new Vector3[8];

                verts[0] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox, m_oy, m_zmin)).ToVector3();
                verts[1] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox + m_length, m_oy, m_zmin)).ToVector3();
                verts[2] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox, m_oy + m_length, m_zmin)).ToVector3();
                verts[3] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox + m_length, m_oy + m_length, m_zmin)).ToVector3();

                verts[4] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox, m_oy, m_zmax)).ToVector3();
                verts[5] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox + m_length, m_oy, m_zmax)).ToVector3();
                verts[6] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox, m_oy + m_length, m_zmax)).ToVector3();
                verts[7] = m_owner.GetDeform().LocalToDeformed(new Vector3d2(m_ox + m_length, m_oy + m_length, m_zmax)).ToVector3();

                GL.PushMatrix();

                GL.LoadIdentity();
                GL.MultMatrix(camera.worldToCameraMatrix * m_owner.GetLocalToWorld().ToMatrix4x4());
                GL.LoadProjectionMatrix(camera.projectionMatrix);

                lineMaterial.SetPass(0);
                GL.Begin(GL.LINES);
                GL.Color(lineColor);

                for (int i = 0; i < 4; i++)
                {
                    //Draw bottom quad
                    GL.Vertex3(verts[ORDER[i, 0]].x, verts[ORDER[i, 0]].y, verts[ORDER[i, 0]].z);
                    GL.Vertex3(verts[ORDER[i, 1]].x, verts[ORDER[i, 1]].y, verts[ORDER[i, 1]].z);
                    //Draw top quad
                    GL.Vertex3(verts[ORDER[i, 0] + 4].x, verts[ORDER[i, 0] + 4].y, verts[ORDER[i, 0] + 4].z);
                    GL.Vertex3(verts[ORDER[i, 1] + 4].x, verts[ORDER[i, 1] + 4].y, verts[ORDER[i, 1] + 4].z);
                    //Draw verticals
                    GL.Vertex3(verts[ORDER[i, 0]].x, verts[ORDER[i, 0]].y, verts[ORDER[i, 0]].z);
                    GL.Vertex3(verts[ORDER[i, 0] + 4].x, verts[ORDER[i, 0] + 4].y, verts[ORDER[i, 0] + 4].z);
                }

                GL.End();

                GL.PopMatrix();
            }

            if (!IsLeaf())
            {
                m_children[0].DrawQuadOutline(camera, lineMaterial, lineColor);
                m_children[1].DrawQuadOutline(camera, lineMaterial, lineColor);
                m_children[2].DrawQuadOutline(camera, lineMaterial, lineColor);
                m_children[3].DrawQuadOutline(camera, lineMaterial, lineColor);
            }
        }