コード例 #1
0
        public void ResetView(int w, int h)
        {
            if (w != 0 || h != 0)
            {
                m_iScreenWidth  = w;
                m_iScreenHeight = h;
            }

            // calculate the aspect ratio of the screen
            if (m_iScreenHeight == 0)
            {
                m_fAspect = m_iScreenWidth;
            }
            else
            {
                m_fAspect = m_iScreenWidth / m_iScreenHeight;
            }

            // Calculate the clipping volume along the y-axis, then set our
            // right, left, top and bottom clipping volumn
            double viewDepth = GetFocalLength();
            double clipY     = Math.Tan(Utils.Radiansf(m_fFovY / 2)) * viewDepth;

            if (m_iScreenWidth <= m_iScreenHeight)
            {
                m_fLeft   = -clipY;
                m_fRight  = clipY;
                m_fBottom = -clipY * m_iScreenHeight / m_iScreenWidth;
                m_fTop    = clipY * m_iScreenHeight / m_iScreenWidth;
            }
            else
            {
                m_fLeft   = -clipY * m_iScreenWidth / m_iScreenHeight;
                m_fRight  = clipY * m_iScreenWidth / m_iScreenHeight;
                m_fBottom = -clipY;
                m_fTop    = clipY;
            }

            // Set Viewport to window dimensions
            OpenGLControl.glViewport(0, 0, m_iScreenWidth, m_iScreenHeight);

            // Reset the projection matrix (coordinate system)
            OpenGLControl.glMatrixMode(OpenGLControl.GL_PROJECTION);
            OpenGLControl.glLoadIdentity();

            if (m_bPerspective)
            {
                // Perspective transformations.
                OpenGLControl.gluPerspective(m_fFovY, m_fAspect, m_fNear, m_fFar);
            }
            else
            {
                // Orthographic transformations.
                OpenGLControl.glOrtho(m_fLeft, m_fRight, m_fBottom, m_fTop, m_fNear, m_fFar);
            }

            // Save the Projection matrix.  This is used later for
            // conversion of mouse coordinates to world coordinates.
            OpenGLControl.glGetDoublev(OpenGLControl.GL_PROJECTION_MATRIX, m_dProjectionMatrix);

            // Save the Projection matrix.  This is used later for
            // conversion of mouse coordinates to world coordinates.
            OpenGLControl.glGetIntegerv(OpenGLControl.GL_VIEWPORT, m_iViewport);

            // Reset the ModelView matrix
            OpenGLControl.glMatrixMode(OpenGLControl.GL_MODELVIEW);
            OpenGLControl.glLoadIdentity();
        }