Push aspect-ratio handling into CameraGroup, so renderer doesn't need to resize viewports each update.
This commit is contained in:
parent
227b3e469c
commit
5a17ccf9eb
8 changed files with 42 additions and 56 deletions
|
@ -322,7 +322,7 @@ void fgHiResDump()
|
|||
int curColumn = trGet(tr, TR_CURRENT_COLUMN);
|
||||
// int curRow = trGet(tr, TR_CURRENT_ROW);
|
||||
|
||||
renderer->update( false );
|
||||
renderer->update();
|
||||
// OSGFIXME
|
||||
// if ( do_hud )
|
||||
// fgUpdateHUD( curColumn*hud_col_step, curRow*hud_row_step,
|
||||
|
|
|
@ -263,6 +263,22 @@ void CameraGroup::setCameraParameters(float vfov, float aspectRatio)
|
|||
1.0f / aspectRatio,
|
||||
_zNear, _zFar);
|
||||
}
|
||||
|
||||
double CameraGroup::getMasterAspectRatio() const
|
||||
{
|
||||
if (_cameras.empty())
|
||||
return 0.0;
|
||||
|
||||
const CameraInfo* info = _cameras.front();
|
||||
|
||||
const osg::Viewport* viewport = info->camera->getViewport();
|
||||
if (!viewport) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return static_cast<double>(viewport->height()) / viewport->width();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace
|
||||
|
|
|
@ -183,6 +183,11 @@ public:
|
|||
|
||||
void buildDistortionCamera(const SGPropertyNode* psNode,
|
||||
osg::Camera* camera);
|
||||
|
||||
/**
|
||||
* get aspect ratio of master camera's viewport
|
||||
*/
|
||||
double getMasterAspectRatio() const;
|
||||
protected:
|
||||
CameraList _cameras;
|
||||
osg::ref_ptr<osgViewer::Viewer> _viewer;
|
||||
|
|
|
@ -281,7 +281,7 @@ int fgOSMainLoop()
|
|||
fgIdleHandler idleFunc = manipulator->getIdleHandler();
|
||||
if (idleFunc)
|
||||
(*idleFunc)();
|
||||
globals->get_renderer()->update(true);
|
||||
globals->get_renderer()->update();
|
||||
viewer->frame();
|
||||
}
|
||||
|
||||
|
|
|
@ -597,7 +597,7 @@ FGRenderer::setupView( void )
|
|||
|
||||
// Update all Visuals (redraws anything graphics related)
|
||||
void
|
||||
FGRenderer::update( bool refresh_camera_settings ) {
|
||||
FGRenderer::update( ) {
|
||||
if (!(_scenery_loaded->getBoolValue() ||
|
||||
_scenery_override->getBoolValue()))
|
||||
{
|
||||
|
@ -649,12 +649,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
|
|||
FGViewer *current__view = globals->get_current_view();
|
||||
// Force update of center dependent values ...
|
||||
current__view->set_dirty();
|
||||
|
||||
if ( refresh_camera_settings ) {
|
||||
// update view port
|
||||
resize( _xsize->getIntValue(),
|
||||
_ysize->getIntValue() );
|
||||
}
|
||||
|
||||
osg::Camera *camera = viewer->getCamera();
|
||||
|
||||
bool skyblend = _skyblend->getBoolValue();
|
||||
|
@ -771,22 +766,9 @@ FGRenderer::update( bool refresh_camera_settings ) {
|
|||
CameraGroup::getDefault()->setCameraCullMasks(cullMask);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// options.cxx needs to see this for toggle_panel()
|
||||
// Handle new window size or exposure
|
||||
void
|
||||
FGRenderer::resize( int width, int height ) {
|
||||
|
||||
// the following breaks aspect-ratio of the main 3D scenery window when 2D panels are moved
|
||||
// in y direction - causing issues for aircraft with 2D panels (/sim/virtual_cockpit=false).
|
||||
// Disabling for now. Seems this useful for the pre-OSG time only.
|
||||
// if ( (!_virtual_cockpit->getBoolValue())
|
||||
// && fgPanelVisible() && idle_state == 1000 ) {
|
||||
// view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
|
||||
// globals->get_current_panel()->getYOffset()) / 768.0);
|
||||
// }
|
||||
|
||||
FGRenderer::resize( int width, int height )
|
||||
{
|
||||
int curWidth = _xsize->getIntValue(),
|
||||
curHeight = _ysize->getIntValue();
|
||||
if ((curHeight != height) || (curWidth != width)) {
|
||||
|
@ -794,18 +776,6 @@ FGRenderer::resize( int width, int height ) {
|
|||
_xsize->setIntValue(width);
|
||||
_ysize->setIntValue(height);
|
||||
}
|
||||
|
||||
// must set view aspect ratio each frame, or initial values are wrong.
|
||||
// should probably be fixed 'smarter' during view setup.
|
||||
double aspect = height / (double) width;
|
||||
|
||||
// for all views
|
||||
FGViewMgr *viewmgr = globals->get_viewmgr();
|
||||
if (viewmgr) {
|
||||
for ( int i = 0; i < viewmgr->size(); ++i ) {
|
||||
viewmgr->get_view(i)->set_aspect_ratio(aspect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -51,10 +51,7 @@ public:
|
|||
|
||||
void resize(int width, int height );
|
||||
|
||||
// calling update( refresh_camera_settings = false ) will not
|
||||
// touch window or camera settings. This is useful for the tiled
|
||||
// renderer which needs to set the view frustum itself.
|
||||
void update( bool refresh_camera_settings);
|
||||
void update();
|
||||
|
||||
/** Just pick into the scene and return the pick callbacks on the way ...
|
||||
*/
|
||||
|
|
|
@ -65,7 +65,6 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
|
|||
_pitch_deg(0),
|
||||
_heading_deg(0),
|
||||
_scaling_type(FG_SCALING_MAX),
|
||||
_aspect_ratio(0),
|
||||
_cameraGroup(CameraGroup::getDefault())
|
||||
{
|
||||
_absolute_view_pos = SGVec3d(0, 0, 0);
|
||||
|
@ -102,7 +101,7 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
|
|||
} else {
|
||||
_fov_deg = 55;
|
||||
}
|
||||
_aspect_ratio = 1;
|
||||
|
||||
_aspect_ratio_multiplier = aspect_ratio_multiplier;
|
||||
_target_offset_m.x() = target_x_offset_m;
|
||||
_target_offset_m.y() = target_y_offset_m;
|
||||
|
@ -539,18 +538,19 @@ FGViewer::updateDampOutput(double dt)
|
|||
double
|
||||
FGViewer::get_h_fov()
|
||||
{
|
||||
double aspectRatio = _cameraGroup->getMasterAspectRatio();
|
||||
switch (_scaling_type) {
|
||||
case FG_SCALING_WIDTH: // h_fov == fov
|
||||
return _fov_deg;
|
||||
case FG_SCALING_MAX:
|
||||
if (_aspect_ratio < 1.0) {
|
||||
if (aspectRatio < 1.0) {
|
||||
// h_fov == fov
|
||||
return _fov_deg;
|
||||
} else {
|
||||
// v_fov == fov
|
||||
return
|
||||
atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
|
||||
/ (_aspect_ratio*_aspect_ratio_multiplier))
|
||||
/ (aspectRatio*_aspect_ratio_multiplier))
|
||||
* SG_RADIANS_TO_DEGREES * 2;
|
||||
}
|
||||
default:
|
||||
|
@ -564,18 +564,19 @@ FGViewer::get_h_fov()
|
|||
double
|
||||
FGViewer::get_v_fov()
|
||||
{
|
||||
double aspectRatio = _cameraGroup->getMasterAspectRatio();
|
||||
switch (_scaling_type) {
|
||||
case FG_SCALING_WIDTH: // h_fov == fov
|
||||
return
|
||||
atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
|
||||
* (_aspect_ratio*_aspect_ratio_multiplier))
|
||||
* (aspectRatio*_aspect_ratio_multiplier))
|
||||
* SG_RADIANS_TO_DEGREES * 2;
|
||||
case FG_SCALING_MAX:
|
||||
if (_aspect_ratio < 1.0) {
|
||||
if (aspectRatio < 1.0) {
|
||||
// h_fov == fov
|
||||
return
|
||||
atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
|
||||
* (_aspect_ratio*_aspect_ratio_multiplier))
|
||||
* (aspectRatio*_aspect_ratio_multiplier))
|
||||
* SG_RADIANS_TO_DEGREES * 2;
|
||||
} else {
|
||||
// v_fov == fov
|
||||
|
@ -671,3 +672,8 @@ FGViewer::update (double dt)
|
|||
_cameraGroup->setCameraParameters(get_v_fov(), get_aspect_ratio());
|
||||
}
|
||||
}
|
||||
|
||||
double FGViewer::get_aspect_ratio() const
|
||||
{
|
||||
return _cameraGroup->getMasterAspectRatio();
|
||||
}
|
||||
|
|
|
@ -215,10 +215,7 @@ public:
|
|||
virtual double get_h_fov(); // Get horizontal fov, in degrees.
|
||||
virtual double get_v_fov(); // Get vertical fov, in degrees.
|
||||
|
||||
virtual void set_aspect_ratio( double r ) {
|
||||
_aspect_ratio = r;
|
||||
}
|
||||
virtual double get_aspect_ratio() const { return _aspect_ratio; }
|
||||
virtual double get_aspect_ratio() const;
|
||||
|
||||
virtual void set_aspect_ratio_multiplier( double m ) {
|
||||
_aspect_ratio_multiplier = m;
|
||||
|
@ -305,11 +302,6 @@ private:
|
|||
// the nominal field of view (angle, in degrees)
|
||||
double _fov_deg;
|
||||
|
||||
// Ratio of window width and height; height = width *
|
||||
// aspect_ratio. This value is automatically calculated based on
|
||||
// window dimentions.
|
||||
double _aspect_ratio;
|
||||
|
||||
// default = 1.0, this value is user configurable and is
|
||||
// multiplied into the aspect_ratio to get the actual vertical fov
|
||||
double _aspect_ratio_multiplier;
|
||||
|
|
Loading…
Add table
Reference in a new issue