Exemplo n.º 1
0
        public void SetNearClipPlane(double fNear)
        {
            m_fNear = fNear;

            // 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);

            // Reset the ModelView matrix
            OpenGLControl.glMatrixMode(OpenGLControl.GL_MODELVIEW);
        }
Exemplo n.º 2
0
        public void PositionCamera()
        {
            if (m_bResetClippingPlanes)
            {
                // Reset our cameras clipping plane
                ResetView(0, 0);
                m_bResetClippingPlanes = false;
            }

            if (m_fRoll != 0)
            {
                msgMatrix       matx = new msgMatrix();
                msgVectorStruct UpVector;

                matx.Rotate(zero_p, x_axe, m_fPitch / 180.0 * Math.PI);
                matx.Rotate(zero_p, y_axe, m_fRoll / 180.0 * Math.PI);
                matx.Rotate(zero_p, z_axe, -m_fYaw / 180.0 * Math.PI);

                UpVector = z_axe;
                matx.ApplyMatrixToVector(zero_p, UpVector);

                // Position the camera using the newly calculated 'Up' vector
                OpenGLControl.gluLookAt(m_fEyePos.x, m_fEyePos.y, m_fEyePos.z,
                                        m_fLookAtPos.x, m_fLookAtPos.y, m_fLookAtPos.z,
                                        UpVector.x, UpVector.y, UpVector.z);
            }
            else
            {
                // Since our 'Up' vector has already been calculated, all we need to do is
                // position the camera..
                OpenGLControl.gluLookAt(m_fEyePos.x, m_fEyePos.y, m_fEyePos.z,
                                        m_fLookAtPos.x, m_fLookAtPos.y, m_fLookAtPos.z,
                                        m_fUpVector.x, m_fUpVector.y, m_fUpVector.z);
            }

            // Save the Model view matrix.  This is used later for
            // conversion of mouse coordinates to world coordinates.
            OpenGLControl.glGetDoublev(OpenGLControl.GL_MODELVIEW_MATRIX, m_dModelViewMatrix);
        }
Exemplo n.º 3
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();
        }