void OpenGLRenderer::setupCameraPerspective(float pitch, float heading, float fov) { // TODO: Find a correct and exact formula for the FOV GLfloat glFOV = 0.63 * fov; // Approximative and experimental formula if (fov > 79.0 && fov < 81.0) glFOV = 50.5; // Somewhat good value for fov == 80 else if (fov > 59.0 && fov < 61.0) glFOV = 36.0; // Somewhat good value for fov == 60 Common::Rect frame = frameViewport(); glViewport(frame.left, frame.top, frame.width(), frame.height()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); Math::Matrix4 m = Math::makePerspectiveMatrix(glFOV, (GLfloat)kOriginalWidth / (GLfloat)kFrameHeight, 1.0, 10000.0); glMultMatrixf(m.getData()); // Rotate the model to simulate the rotation of the camera glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(pitch, -1.0f, 0.0f, 0.0f); glRotatef(heading - 180.0f, 0.0f, 1.0f, 0.0f); glGetDoublev(GL_MODELVIEW_MATRIX, _cubeModelViewMatrix); glGetDoublev(GL_PROJECTION_MATRIX, _cubeProjectionMatrix); glGetIntegerv(GL_VIEWPORT, (GLint *)_cubeViewport); }
void OpenGLRenderer::setupCameraPerspective(float pitch, float heading, float fov) { BaseRenderer::setupCameraPerspective(pitch, heading, fov); Common::Rect frame = frameViewport(); glViewport(frame.left, frame.top, frame.width(), frame.height()); glMatrixMode(GL_PROJECTION); glLoadMatrixf(_projectionMatrix.getData()); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(_modelViewMatrix.getData()); }
void ShaderRenderer::setupCameraPerspective(float pitch, float heading, float fov) { Renderer::setupCameraPerspective(pitch, heading, fov); Common::Rect frame = frameViewport(); glViewport(frame.left, frame.top, frame.width(), frame.height()); }
void BaseRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) { // Screen coords to 3D coords Math::Vector3d obj; Math::gluMathUnProject(Math::Vector3d(screen.x, _system->getHeight() - screen.y, 0.9f), _mvpMatrix, frameViewport(), obj); // 3D coords to polar coords obj.normalize(); Math::Vector2d horizontalProjection = Math::Vector2d(obj.x(), obj.z()); horizontalProjection.normalize(); pitch = 90 - Math::Angle::arcCosine(obj.y()).getDegrees(); heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees(); if (horizontalProjection.getX() > 0.0) heading = 360 - heading; }
Common::Point BaseRenderer::frameCenter() const { Common::Rect screen = viewport(); Common::Rect frame = frameViewport(); return Common::Point((frame.left + frame.right) / 2, screen.top + screen.bottom - (frame.top + frame.bottom) / 2); }