void RAS_FramingManager:: ComputeBestFitViewRect( const RAS_Rect &availableViewport, const float design_aspect_ratio, RAS_Rect &viewport ){ // try and honour the aspect ratio when setting the // drawable area. If we don't do this we are liable // to get a lot of distortion in the rendered image. int width = availableViewport.GetWidth(); int height = availableViewport.GetHeight(); float window_aspect = float(width)/float(height); if (window_aspect < design_aspect_ratio) { int v_height = (int)(width / design_aspect_ratio); int left_over = (height - v_height) / 2; viewport.SetLeft(availableViewport.GetLeft()); viewport.SetBottom(availableViewport.GetBottom() + left_over); viewport.SetRight(availableViewport.GetLeft() + width); viewport.SetTop(availableViewport.GetBottom() + left_over + v_height); } else { int v_width = (int)(height * design_aspect_ratio); int left_over = (width - v_width) / 2; viewport.SetLeft(availableViewport.GetLeft() + left_over); viewport.SetBottom(availableViewport.GetBottom()); viewport.SetRight(availableViewport.GetLeft() + v_width + left_over); viewport.SetTop(availableViewport.GetBottom() + height); } }
void RAS_OpenGLRasterizer::SetRenderArea() { RAS_Rect area; // only above/below stereo method needs viewport adjustment switch (m_stereomode) { case RAS_STEREO_ABOVEBELOW: switch (m_curreye) { case RAS_STEREO_LEFTEYE: // upper half of window area.SetLeft(0); area.SetBottom(m_2DCanvas->GetHeight() - int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2); area.SetRight(int(m_2DCanvas->GetWidth())); area.SetTop(int(m_2DCanvas->GetHeight())); m_2DCanvas->SetDisplayArea(&area); break; case RAS_STEREO_RIGHTEYE: // lower half of window area.SetLeft(0); area.SetBottom(0); area.SetRight(int(m_2DCanvas->GetWidth())); area.SetTop(int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2); m_2DCanvas->SetDisplayArea(&area); break; } break; case RAS_STEREO_SIDEBYSIDE: switch (m_curreye) { case RAS_STEREO_LEFTEYE: // Left half of window area.SetLeft(0); area.SetBottom(0); area.SetRight(m_2DCanvas->GetWidth()/2); area.SetTop(m_2DCanvas->GetHeight()); m_2DCanvas->SetDisplayArea(&area); break; case RAS_STEREO_RIGHTEYE: // Right half of window area.SetLeft(m_2DCanvas->GetWidth()/2); area.SetBottom(0); area.SetRight(m_2DCanvas->GetWidth()); area.SetTop(m_2DCanvas->GetHeight()); m_2DCanvas->SetDisplayArea(&area); break; } break; default: // every available pixel area.SetLeft(0); area.SetBottom(0); area.SetRight(int(m_2DCanvas->GetWidth())); area.SetTop(int(m_2DCanvas->GetHeight())); m_2DCanvas->SetDisplayArea(&area); break; } }
void KX_KetsjiEngine::GetSceneViewport(KX_Scene *scene, KX_Camera* cam, RAS_Rect& area, RAS_Rect& viewport) { // In this function we make sure the rasterizer settings are upto // date. We compute the viewport so that logic // using this information is upto date. // Note we postpone computation of the projection matrix // so that we are using the latest camera position. if (cam->GetViewport()) { RAS_Rect userviewport; userviewport.SetLeft(cam->GetViewportLeft()); userviewport.SetBottom(cam->GetViewportBottom()); userviewport.SetRight(cam->GetViewportRight()); userviewport.SetTop(cam->GetViewportTop()); // Don't do bars on user specified viewport RAS_FrameSettings settings = scene->GetFramingType(); if(settings.FrameType() == RAS_FrameSettings::e_frame_bars) settings.SetFrameType(RAS_FrameSettings::e_frame_extend); RAS_FramingManager::ComputeViewport( scene->GetFramingType(), userviewport, viewport ); area = userviewport; } else if ( !m_overrideCam || (scene->GetName() != m_overrideSceneName) || m_overrideCamUseOrtho ) { RAS_FramingManager::ComputeViewport( scene->GetFramingType(), m_canvas->GetDisplayArea(), viewport ); area = m_canvas->GetDisplayArea(); } else { viewport.SetLeft(0); viewport.SetBottom(0); viewport.SetRight(int(m_canvas->GetWidth())); viewport.SetTop(int(m_canvas->GetHeight())); area = m_canvas->GetDisplayArea(); } }
void RAS_FramingManager:: ComputeViewport( const RAS_FrameSettings &settings, const RAS_Rect &availableViewport, RAS_Rect &viewport ){ RAS_FrameSettings::RAS_FrameType type = settings.FrameType(); const int winx = availableViewport.GetWidth(); const int winy = availableViewport.GetHeight(); const float design_width = float(settings.DesignAspectWidth()); const float design_height = float(settings.DesignAspectHeight()); float design_aspect_ratio = float(1); if (design_height == float(0)) { // well this is ill defined // lets just scale the thing type = RAS_FrameSettings::e_frame_scale; } else { design_aspect_ratio = design_width/design_height; } switch (type) { case RAS_FrameSettings::e_frame_scale : case RAS_FrameSettings::e_frame_extend: { viewport.SetLeft(availableViewport.GetLeft()); viewport.SetBottom(availableViewport.GetBottom()); viewport.SetRight(availableViewport.GetLeft() + int(winx)); viewport.SetTop(availableViewport.GetBottom() + int(winy)); break; } case RAS_FrameSettings::e_frame_bars: { ComputeBestFitViewRect( availableViewport, design_aspect_ratio, viewport ); break; } default : break; } }