void fgUpdateHUD( void ) {
static const float normal_aspect = float(640) / float(480);
- // note: win_ratio is Y/X
- float current_aspect = 1.0f/globals->get_current_view()->get_win_ratio();
+ // note: aspect_ratio is Y/X
+ float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
if( current_aspect > normal_aspect ) {
float aspect_adjust = current_aspect / normal_aspect;
float adjust = 320.0f*aspect_adjust - 320.0f;
}
xvvr = (((atan2(Vyy,Vxx)*SGD_RADIANS_TO_DEGREES)-psi)*
- (factor/globals->get_current_view()->get_win_ratio()));
+ (factor/globals->get_current_view()->get_aspect_ratio()));
drift = ((atan2(Vyy,Vxx)*SGD_RADIANS_TO_DEGREES)-psi);
yvvr = ((actslope - pitch_value)*factor);
vel_y = ((actslope -pitch_value) * cos(roll_value) + drift*sin(roll_value))*factor;
vel_x = (-(actslope -pitch_value)*sin(roll_value) + drift*cos(roll_value))*
- (factor/globals->get_current_view()->get_win_ratio());
+ (factor/globals->get_current_view()->get_aspect_ratio());
// printf("%f %f %f %f\n",vel_x,vel_y,drift,psi);
//****************************************************************
// OBJECT MOVING RETICLE
glLoadIdentity();
ssgSetCamera( (sgVec4 *)globals->get_current_view()->get_VIEW() );
float fov = globals->get_current_view()->get_fov();
- ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
+ ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
// ssgSetNearFar( 10.0f, 120000.0f );
ssgSetNearFar( 0.5f, 1200000.0f );
// Initialize the view manager subsystem.
////////////////////////////////////////////////////////////////////
+#if 0 /* As this wrongly does an integer division and gets x and y the wrong way around, I guess it's not needed. JAF */
// Initialize win_ratio parameters
for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
globals->get_viewmgr()->get_view(i)->
set_win_ratio( fgGetInt("/sim/startup/xsize") /
fgGetInt("/sim/startup/ysize") );
}
+#endif
// Initialize pilot view
FGViewerRPH *pilot_view =
static void
setFOV (double fov)
{
- globals->get_current_view()->set_fov( fov );
+ if ( fov < 180 ) {
+ globals->get_current_view()->set_fov( fov );
+ }
}
static long
// glMatrixMode( GL_PROJECTION );
// glLoadIdentity();
float fov = globals->get_current_view()->get_fov();
- ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
+ ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- scenery.cur_elev;
// options.cxx needs to see this for toggle_panel()
// Handle new window size or exposure
void fgReshape( int width, int height ) {
+ int view_h;
+
+ if ( fgPanelVisible() && idle_state == 1000 ) {
+ view_h = (int)(height * (current_panel->getViewHeight() -
+ current_panel->getYOffset()) / 768.0);
+ } else {
+ view_h = height;
+ }
+
// for all views
for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
- if ( ! fgPanelVisible() || idle_state != 1000 ) {
- globals->get_viewmgr()->get_view(i)->
- set_win_ratio( (float)height / (float)width );
- } else {
- int view_h =
- int((current_panel->getViewHeight() -
- current_panel->getYOffset())
- * (height / 768.0)) + 1;
- globals->get_viewmgr()->get_view(i)->
- set_win_ratio( (float)view_h / (float)width );
- }
+ globals->get_viewmgr()->get_view(i)->
+ set_aspect_ratio((float)view_h / (float)width);
}
- if ( ! fgPanelVisible() || idle_state != 1000 ) {
- glViewport(0, 0 , (GLint)(width), (GLint)(height) );
- } else {
- int view_h =
- int((current_panel->getViewHeight() - current_panel->getYOffset())
- * (height / 768.0)) + 1;
- glViewport(0, (GLint)(height - view_h),
- (GLint)(width), (GLint)(view_h) );
- }
+ glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
fgSetInt("/sim/startup/xsize", width);
fgSetInt("/sim/startup/ysize", height);
float fov = globals->get_current_view()->get_fov();
- ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
+ ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
fgHUDReshape();
}
// the field of view in the x (width) direction
double fov;
- // ratio of x and y fov's; fov(y) = fov(x) * win_ratio
- double win_ratio;
+ // ratio of x and y fov's; fov(y) = fov(x) * fov_ratio
+ double fov_ratio;
+
+ // ratio of window width and height; height = width * aspect_ratio
+ double aspect_ratio;
// the current view offset angle from forward (rotated about the
// view_up vector)
// setter functions
//////////////////////////////////////////////////////////////////////
inline void set_fov( double amount ) { fov = amount; }
- inline void set_win_ratio( double r ) { win_ratio = r; }
+ // Don't provide set_fov_ratio explicitely. Use set_aspect_ratio
+ // instead.
+ inline void set_aspect_ratio( double r ) {
+ aspect_ratio = r;
+ fov_ratio = atan(tan(fov/2 * SG_DEGREES_TO_RADIANS) * aspect_ratio) *
+ SG_RADIANS_TO_DEGREES / (fov/2);
+ }
inline void set_view_offset( double a ) {
set_dirty();
view_offset = a;
inline int is_a( int t ) const { return get_type() == t ; }
inline bool is_dirty() const { return dirty; }
inline double get_fov() const { return fov; }
- inline double get_win_ratio() const { return win_ratio; }
+ inline double get_aspect_ratio() const { return aspect_ratio; }
+ inline double get_fov_ratio() const { return fov_ratio; }
inline double get_view_offset() const { return view_offset; }
inline bool get_reverse_view_offset() const { return reverse_view_offset; }
inline double get_goal_view_offset() const { return goal_view_offset; }