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; } }
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:: ComputeOrtho( const RAS_FrameSettings &settings, const RAS_Rect &availableViewport, const RAS_Rect &viewport, const float scale, const float camnear, const float camfar, RAS_FrameFrustum &frustum ) { RAS_FrameSettings::RAS_FrameType type = settings.FrameType(); 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; } ComputeDefaultOrtho( camnear, camfar, scale, design_aspect_ratio, frustum ); switch (type) { case RAS_FrameSettings::e_frame_extend: { RAS_Rect vt; ComputeBestFitViewRect( availableViewport, design_aspect_ratio, vt ); // now scale the calculated frustum by the difference // between vt and the viewport in each axis. // These are always > 1 float x_scale = float(viewport.GetWidth())/float(vt.GetWidth()); float y_scale = float(viewport.GetHeight())/float(vt.GetHeight()); frustum.x1 *= x_scale; frustum.x2 *= x_scale; frustum.y1 *= y_scale; frustum.y2 *= y_scale; break; } case RAS_FrameSettings::e_frame_scale : case RAS_FrameSettings::e_frame_bars: default : break; } }