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,
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
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;
fgIdleHandler idleFunc = manipulator->getIdleHandler();
if (idleFunc)
(*idleFunc)();
- globals->get_renderer()->update(true);
+ globals->get_renderer()->update();
viewer->frame();
}
// Update all Visuals (redraws anything graphics related)
void
-FGRenderer::update( bool refresh_camera_settings ) {
+FGRenderer::update( ) {
if (!(_scenery_loaded->getBoolValue() ||
_scenery_override->getBoolValue()))
{
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();
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)) {
_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
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 ...
*/
_pitch_deg(0),
_heading_deg(0),
_scaling_type(FG_SCALING_MAX),
- _aspect_ratio(0),
_cameraGroup(CameraGroup::getDefault())
{
_absolute_view_pos = SGVec3d(0, 0, 0);
} 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;
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:
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
_cameraGroup->setCameraParameters(get_v_fov(), get_aspect_ratio());
}
}
+
+double FGViewer::get_aspect_ratio() const
+{
+ return _cameraGroup->getMasterAspectRatio();
+}
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;
// 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;