more sensible so we can do a more reasonable external view.
// Define a structure containing all the parameters for an aircraft
typedef struct{
- FGInterface *fdm_state;
+ FGInterface *fdm_state;
FGControls *controls;
} fgAIRCRAFT ;
*/
+#include <Include/compiler.h>
+
#include <math.h>
+#include <list>
+
#include <Time/timestamp.hxx>
+FG_USING_STD(list);
+
+
#ifndef __cplusplus
# error This library requires C++
#endif
};
+typedef list < FGInterface > fdm_state_list;
+typedef fdm_state_list::iterator fdm_state_list_iterator;
+typedef fdm_state_list::const_iterator const_fdm_state_list_iterator;
+
+
extern FGInterface cur_fdm_state;
bool fgInitSubsystems( void ) {
FGTime::cur_time_params = new FGTime();
- FGInterface *f; // assigned later
fgLIGHT *l = &cur_light_params;
FGTime *t = FGTime::cur_time_params;
FGView *v = ¤t_view;
// allocates structures so must happen before any of the flight
// model or control parameters are set
fgAircraftInit(); // In the future this might not be the case.
- f = current_aircraft.fdm_state;
// set the initial position
fgInitPosition();
// now handled inside of the fgTileMgrUpdate()
/*
- geod_pos = Point3D( f->get_Longitude(), f->get_Latitude(), 0.0);
+ geod_pos = Point3D( cur_fdm_state.get_Longitude(), cur_fdm_state.get_Latitude(), 0.0);
tmp_abs_view_pos = fgGeodToCart(geod_pos);
FG_LOG( FG_GENERAL, FG_DEBUG,
"Initial abs_view_pos = " << tmp_abs_view_pos );
scenery.cur_elev =
- fgTileMgrCurElev( f->get_Longitude(), f->get_Latitude(),
+ fgTileMgrCurElev( cur_fdm_state.get_Longitude(), cur_fdm_state.get_Latitude(),
tmp_abs_view_pos );
FG_LOG( FG_GENERAL, FG_DEBUG,
"Altitude after update " << scenery.cur_elev );
scenery.cur_elev );
// Reset our altitude if we are below ground
- FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << f->get_Altitude() );
+ FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state.get_Altitude() );
FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
- f->get_Runway_altitude() );
+ cur_fdm_state.get_Runway_altitude() );
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) {
+ cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 );
}
FG_LOG( FG_GENERAL, FG_INFO,
"Updated position (after elevation adj): ("
- << (f->get_Latitude() * RAD_TO_DEG) << ", "
- << (f->get_Longitude() * RAD_TO_DEG) << ", "
- << (f->get_Altitude() * FEET_TO_METER) << ")" );
+ << (cur_fdm_state.get_Latitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state.get_Longitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state.get_Altitude() * FEET_TO_METER) << ")" );
// We need to calculate a few more values here that would normally
// be calculated by the FDM so that the v->UpdateViewMath()
double sea_level_radius_meters;
double lat_geoc;
// Set the FG variables first
- fgGeodToGeoc( f->get_Latitude(), f->get_Altitude(),
+ fgGeodToGeoc( cur_fdm_state.get_Latitude(), cur_fdm_state.get_Altitude(),
&sea_level_radius_meters, &lat_geoc);
- f->set_Geocentric_Position( lat_geoc, f->get_Longitude(),
- f->get_Altitude() +
+ cur_fdm_state.set_Geocentric_Position( lat_geoc, cur_fdm_state.get_Longitude(),
+ cur_fdm_state.get_Altitude() +
(sea_level_radius_meters * METER_TO_FEET) );
- f->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
+ cur_fdm_state.set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
- f->set_sin_cos_longitude(f->get_Longitude());
- f->set_sin_cos_latitude(f->get_Latitude());
+ cur_fdm_state.set_sin_cos_longitude(cur_fdm_state.get_Longitude());
+ cur_fdm_state.set_sin_cos_latitude(cur_fdm_state.get_Latitude());
- f->set_sin_lat_geocentric(sin(lat_geoc));
- f->set_cos_lat_geocentric(cos(lat_geoc));
+ cur_fdm_state.set_sin_lat_geocentric(sin(lat_geoc));
+ cur_fdm_state.set_cos_lat_geocentric(cos(lat_geoc));
// The following section sets up the flight model EOM parameters
// and should really be read in from one or more files.
// Initial Velocity
- f->set_Velocities_Local( current_options.get_uBody(),
+ cur_fdm_state.set_Velocities_Local( current_options.get_uBody(),
current_options.get_vBody(),
current_options.get_wBody());
// Initial Orientation
- f->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
+ cur_fdm_state.set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
current_options.get_pitch() * DEG_TO_RAD,
current_options.get_heading() * DEG_TO_RAD );
// Initial Angular Body rates
- f->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
+ cur_fdm_state.set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
- f->set_Earth_position_angle( 0.0 );
+ cur_fdm_state.set_Earth_position_angle( 0.0 );
// Mass properties and geometry values
- f->set_Inertias( 8.547270E+01,
+ cur_fdm_state.set_Inertias( 8.547270E+01,
1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
// CG position w.r.t. ref. point
- f->set_CG_Position( 0.0, 0.0, 0.0 );
+ cur_fdm_state.set_CG_Position( 0.0, 0.0, 0.0 );
// Initialize the event manager
global_events.Init();
fgEVENT::FG_EVENT_READY, 60000 );
// Initialize the time dependent variables
- t->init(f);
- t->update(f);
+ t->init(cur_fdm_state);
+ t->update(cur_fdm_state);
// Initialize view parameters
FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()");
v->Init();
FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
- v->UpdateViewMath(f);
+ v->UpdateViewMath(cur_fdm_state);
FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << v->get_abs_view_pos());
// v->UpdateWorldToEye(f);
// I'm just sticking this here for now, it should probably move
// eventually
- scenery.cur_elev = f->get_Runway_altitude() * FEET_TO_METER;
+ scenery.cur_elev = cur_fdm_state.get_Runway_altitude() * FEET_TO_METER;
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) {
+ cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 );
}
FG_LOG( FG_GENERAL, FG_INFO,
"Updated position (after elevation adj): ("
- << (f->get_Latitude() * RAD_TO_DEG) << ", "
- << (f->get_Longitude() * RAD_TO_DEG) << ", "
- << (f->get_Altitude() * FEET_TO_METER) << ")" );
+ << (cur_fdm_state.get_Latitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state.get_Longitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state.get_Altitude() * FEET_TO_METER) << ")" );
// end of thing that I just stuck in that I should probably move
// Joystick support
void fgReInitSubsystems( void )
{
- FGInterface *f = current_aircraft.fdm_state;
FGView *v = ¤t_view;
FGTime *t = FGTime::cur_time_params;
scenery.cur_elev );
// Reset our altitude if we are below ground
- FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << f->get_Altitude() );
+ FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state.get_Altitude() );
FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
- f->get_Runway_altitude() );
+ cur_fdm_state.get_Runway_altitude() );
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) {
+ cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 );
}
double sea_level_radius_meters;
double lat_geoc;
// Set the FG variables first
- fgGeodToGeoc( f->get_Latitude(), f->get_Altitude(),
+ fgGeodToGeoc( cur_fdm_state.get_Latitude(), cur_fdm_state.get_Altitude(),
&sea_level_radius_meters, &lat_geoc);
- f->set_Geocentric_Position( lat_geoc, f->get_Longitude(),
- f->get_Altitude() +
+ cur_fdm_state.set_Geocentric_Position( lat_geoc, cur_fdm_state.get_Longitude(),
+ cur_fdm_state.get_Altitude() +
(sea_level_radius_meters * METER_TO_FEET) );
- f->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
+ cur_fdm_state.set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
- f->set_sin_cos_longitude(f->get_Longitude());
- f->set_sin_cos_latitude(f->get_Latitude());
+ cur_fdm_state.set_sin_cos_longitude(cur_fdm_state.get_Longitude());
+ cur_fdm_state.set_sin_cos_latitude(cur_fdm_state.get_Latitude());
- f->set_sin_lat_geocentric(sin(lat_geoc));
- f->set_cos_lat_geocentric(cos(lat_geoc));
+ cur_fdm_state.set_sin_lat_geocentric(sin(lat_geoc));
+ cur_fdm_state.set_cos_lat_geocentric(cos(lat_geoc));
// The following section sets up the flight model EOM parameters
// and should really be read in from one or more files.
// Initial Velocity
- f->set_Velocities_Local( current_options.get_uBody(),
+ cur_fdm_state.set_Velocities_Local( current_options.get_uBody(),
current_options.get_vBody(),
current_options.get_wBody());
// Initial Orientation
- f->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
+ cur_fdm_state.set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
current_options.get_pitch() * DEG_TO_RAD,
current_options.get_heading() * DEG_TO_RAD );
// Initial Angular Body rates
- f->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
+ cur_fdm_state.set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
- f->set_Earth_position_angle( 0.0 );
+ cur_fdm_state.set_Earth_position_angle( 0.0 );
// Mass properties and geometry values
- f->set_Inertias( 8.547270E+01,
+ cur_fdm_state.set_Inertias( 8.547270E+01,
1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
// CG position w.r.t. ref. point
- f->set_CG_Position( 0.0, 0.0, 0.0 );
+ cur_fdm_state.set_CG_Position( 0.0, 0.0, 0.0 );
// Initialize view parameters
FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()");
v->Init();
FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
- v->UpdateViewMath(f);
+ v->UpdateViewMath(cur_fdm_state);
FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << v->get_abs_view_pos());
// v->UpdateWorldToEye(f);
fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
1.0 / current_options.get_model_hz() );
- scenery.cur_elev = f->get_Runway_altitude() * FEET_TO_METER;
+ scenery.cur_elev = cur_fdm_state.get_Runway_altitude() * FEET_TO_METER;
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ if ( cur_fdm_state.get_Altitude() < cur_fdm_state.get_Runway_altitude() + 3.758099) {
+ cur_fdm_state.set_Altitude( cur_fdm_state.get_Runway_altitude() + 3.758099 );
}
controls.reset_all();
local_update_sky_and_lighting_params();
return;
case 118: // v key
- v->cycle_view_mode();
+ current_options.cycle_view_mode();
return;
case 120: // x key
fov = current_options.get_fov();
static void fgRenderFrame( void ) {
fgLIGHT *l = &cur_light_params;
FGTime *t = FGTime::cur_time_params;
- FGView *v = ¤t_view;
+ // FGView *v = ¤t_view;
double angle;
// GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
// end of hack
// update view volume parameters
- v->UpdateViewParams();
+ current_view.UpdateViewParams(cur_fdm_state);
// set the sun position
xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
xglMatrixMode(GL_MODELVIEW);
xglLoadIdentity();
sgMat4 vm_tmp, view_mat;
- sgTransposeNegateMat4 ( vm_tmp, v->sgVIEW ) ;
+ sgTransposeNegateMat4 ( vm_tmp, current_view.sgVIEW ) ;
sgCopyMat4( view_mat, copy_of_ssgOpenGLAxisSwapMatrix ) ;
sgPreMultMat4( view_mat, vm_tmp ) ;
xglLoadMatrixf( (float *)view_mat );
// setup transformation for drawing astronomical objects
xglPushMatrix();
// Translate to view position
- Point3D view_pos = v->get_view_pos();
+ Point3D view_pos = current_view.get_view_pos();
xglTranslatef( view_pos.x(), view_pos.y(), view_pos.z() );
// Rotate based on gst (sidereal time)
// note: constant should be 15.041085, Curt thought it was 15
ssgSetNearFar( 0.5f, 100000.0f );
}
- sgMat4 sgVIEW;
+ // sgMat4 sgVIEW;
+ // while ( current_view.follow.size() > 25 ) {
+ // current_view.follow.pop_front();
+ // }
- while ( current_view.follow.size() > 400 ) {
- current_view.follow.pop_front();
- }
-
- if ( current_view.view_mode == FGView::FG_VIEW_FIRST_PERSON ) {
+ if ( current_options.get_view_mode() ==
+ fgOPTIONS::FG_VIEW_FIRST_PERSON )
+ {
// select current view matrix
- sgCopyMat4( sgVIEW, current_view.sgVIEW );
+ // sgCopyMat4( sgVIEW, current_view.sgVIEW );
// disable TuX
penguin_sel->select(0);
- } else if ( current_view.view_mode == FGView::FG_VIEW_FOLLOW ) {
+ } else if ( current_options.get_view_mode() ==
+ fgOPTIONS::FG_VIEW_FOLLOW )
+ {
// select view matrix from front of view matrix queue
- FGMat4Wrapper tmp = current_view.follow.front();
- sgCopyMat4( sgVIEW, tmp.m );
+ // FGMat4Wrapper tmp = current_view.follow.front();
+ // sgCopyMat4( sgVIEW, tmp.m );
// enable TuX and set up his position and orientation
penguin_sel->select(1);
penguin_pos->setTransform( &tuxpos );
}
- ssgSetCamera( sgVIEW );
+ ssgSetCamera( current_view.sgVIEW );
// position tile nodes and update range selectors
global_tile_mgr.prep_ssg_nodes();
// Update internal time dependent calculations (i.e. flight model)
void fgUpdateTimeDepCalcs(int multi_loop, int remainder) {
- FGInterface *f = current_aircraft.fdm_state;
+ static fdm_state_list fdm_list;
+ FGInterface fdm_state;
fgLIGHT *l = &cur_light_params;
FGTime *t = FGTime::cur_time_params;
- FGView *v = ¤t_view;
+ // FGView *v = ¤t_view;
int i;
// update the flight model
multi_loop = 1;
}
+ fdm_state = cur_fdm_state;
+
if ( !t->getPause() ) {
// run Autopilot system
fgAPRun();
// printf("updating flight model x %d\n", multi_loop);
fgFDMUpdate( current_options.get_flight_model(),
- cur_fdm_state,
+ fdm_state,
multi_loop * current_options.get_speed_up(),
remainder );
} else {
fgFDMUpdate( current_options.get_flight_model(),
- cur_fdm_state, 0, remainder );
+ fdm_state, 0, remainder );
+ }
+
+ fdm_list.push_back( fdm_state );
+ while ( fdm_list.size() > 25 ) {
+ fdm_list.pop_front();
+ }
+
+ if ( current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FIRST_PERSON ) {
+ cur_fdm_state = fdm_state;
+ } else if ( current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW ) {
+ cur_fdm_state = fdm_list.front();
}
// update the view angle
for ( i = 0; i < multi_loop; i++ ) {
- if ( fabs(v->get_goal_view_offset() - v->get_view_offset()) < 0.05 ) {
- v->set_view_offset( v->get_goal_view_offset() );
+ if ( fabs(current_view.get_goal_view_offset() -
+ current_view.get_view_offset()) < 0.05 )
+ {
+ current_view.set_view_offset( current_view.get_goal_view_offset() );
break;
} else {
- // move v->view_offset towards v->goal_view_offset
- if ( v->get_goal_view_offset() > v->get_view_offset() ) {
- if ( v->get_goal_view_offset() - v->get_view_offset() < FG_PI ){
- v->inc_view_offset( 0.01 );
+ // move current_view.view_offset towards current_view.goal_view_offset
+ if ( current_view.get_goal_view_offset() >
+ current_view.get_view_offset() )
+ {
+ if ( current_view.get_goal_view_offset() -
+ current_view.get_view_offset() < FG_PI )
+ {
+ current_view.inc_view_offset( 0.01 );
} else {
- v->inc_view_offset( -0.01 );
+ current_view.inc_view_offset( -0.01 );
}
} else {
- if ( v->get_view_offset() - v->get_goal_view_offset() < FG_PI ){
- v->inc_view_offset( -0.01 );
+ if ( current_view.get_view_offset() -
+ current_view.get_goal_view_offset() < FG_PI )
+ {
+ current_view.inc_view_offset( -0.01 );
} else {
- v->inc_view_offset( 0.01 );
+ current_view.inc_view_offset( 0.01 );
}
}
- if ( v->get_view_offset() > FG_2PI ) {
- v->inc_view_offset( -FG_2PI );
- } else if ( v->get_view_offset() < 0 ) {
- v->inc_view_offset( FG_2PI );
+ if ( current_view.get_view_offset() > FG_2PI ) {
+ current_view.inc_view_offset( -FG_2PI );
+ } else if ( current_view.get_view_offset() < 0 ) {
+ current_view.inc_view_offset( FG_2PI );
}
}
}
double tmp = -(l->sun_rotation + FG_PI)
- - (f->get_Psi() - v->get_view_offset() );
+ - (cur_fdm_state.get_Psi() - current_view.get_view_offset() );
while ( tmp < 0.0 ) {
tmp += FG_2PI;
}
tmp -= FG_2PI;
}
/* printf("Psi = %.2f, viewoffset = %.2f sunrot = %.2f rottosun = %.2f\n",
- FG_Psi * RAD_TO_DEG, v->view_offset * RAD_TO_DEG,
+ FG_Psi * RAD_TO_DEG, current_view.view_offset * RAD_TO_DEG,
-(l->sun_rotation+FG_PI) * RAD_TO_DEG, tmp * RAD_TO_DEG); */
l->UpdateAdjFog();
}
// What should we do when we have nothing else to do? Let's get ready
// for the next move and update the display?
static void fgMainLoop( void ) {
- FGInterface *f;
FGTime *t;
static long remainder = 0;
long elapsed, multi_loop;
static int frames = 0;
#endif // FANCY_FRAME_COUNTER
- f = current_aircraft.fdm_state;
t = FGTime::cur_time_params;
FG_LOG( FG_ALL, FG_DEBUG, "Running Main Loop");
/* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
scenery.cur_elev,
- f->get_Runway_altitude() * FEET_TO_METER,
- f->get_Altitude() * FEET_TO_METER); */
+ cur_fdm_state.get_Runway_altitude() * FEET_TO_METER,
+ cur_fdm_state.get_Altitude() * FEET_TO_METER); */
if ( scenery.cur_elev > -9990 ) {
- if ( f->get_Altitude() * FEET_TO_METER <
+ if ( cur_fdm_state.get_Altitude() * FEET_TO_METER <
(scenery.cur_elev + alt_adjust_m - 3.0) ) {
// now set aircraft altitude above ground
printf("Current Altitude = %.2f < %.2f forcing to %.2f\n",
- f->get_Altitude() * FEET_TO_METER,
+ cur_fdm_state.get_Altitude() * FEET_TO_METER,
scenery.cur_elev + alt_adjust_m - 3.0,
scenery.cur_elev + alt_adjust_m );
fgFDMForceAltitude( current_options.get_flight_model(),
FG_LOG( FG_ALL, FG_DEBUG,
"<*> resetting altitude to "
- << f->get_Altitude() * FEET_TO_METER << " meters" );
+ << cur_fdm_state.get_Altitude() * FEET_TO_METER << " meters" );
}
fgFDMSetGroundElevation( current_options.get_flight_model(),
scenery.cur_elev ); // meters
/* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
scenery.cur_elev,
- f->get_Runway_altitude() * FEET_TO_METER,
- f->get_Altitude() * FEET_TO_METER); */
+ cur_fdm_state.get_Runway_altitude() * FEET_TO_METER,
+ cur_fdm_state.get_Altitude() * FEET_TO_METER); */
// update "time"
- t->update(f);
+ t->update(cur_fdm_state);
// Get elapsed time (in usec) for this past frame
elapsed = fgGetTimeInterval();
double pitch = log((controls.get_throttle(0) * 14.0) + 1.0);
//fprintf(stderr, "pitch1: %f ", pitch);
- if (controls.get_throttle(0) > 0.0 || f->v_rel_wind > 40.0) {
- //fprintf(stderr, "rel_wind: %f ", f->v_rel_wind);
+ if (controls.get_throttle(0) > 0.0 || cur_fdm_state.v_rel_wind > 40.0) {
+ //fprintf(stderr, "rel_wind: %f ", cur_fdm_state.v_rel_wind);
// only add relative wind and AoA if prop is moving
// or we're really flying at idle throttle
if (pitch < 5.4) { // this needs tuning
// prop tips not breaking sound barrier
- pitch += log(f->v_rel_wind + 0.8)/2;
+ pitch += log(cur_fdm_state.v_rel_wind + 0.8)/2;
} else {
// prop tips breaking sound barrier
- pitch += log(f->v_rel_wind + 0.8)/10;
+ pitch += log(cur_fdm_state.v_rel_wind + 0.8)/10;
}
//fprintf(stderr, "pitch2: %f ", pitch);
//fprintf(stderr, "AoA: %f ", FG_Gamma_vert_rad);
// Angle of Attack next... -x^3(e^x) is my best guess Just
// need to calculate some reasonable scaling factor and
// then clamp it on the positive aoa (neg adj) side
- double aoa = f->get_Gamma_vert_rad() * 2.2;
+ double aoa = cur_fdm_state.get_Gamma_vert_rad() * 2.2;
double tmp = 3.0;
double aoa_adj = pow(-aoa, tmp) * pow(M_E, aoa);
if (aoa_adj < -0.8) aoa_adj = -0.8;
//fprintf(stderr, "pitch4: %f\n", pitch);
double volume = controls.get_throttle(0) * 1.15 + 0.3 +
- log(f->v_rel_wind + 1.0)/14.0;
+ log(cur_fdm_state.v_rel_wind + 1.0)/14.0;
// fprintf(stderr, "volume: %f\n", volume);
pitch_envelope.setStep ( 0, 0.01, pitch );
// yes we've finished all our initializations and are running
// the main loop, so this will now work without seg faulting
// the system.
- current_view.UpdateViewParams();
+ current_view.UpdateViewParams(cur_fdm_state);
if ( current_options.get_panel_status() ) {
FGPanel::OurPanel->ReInit(0, 0, 1024, 768);
}
wireframe(0),
xsize(640),
ysize(480),
+ view_mode(FG_VIEW_FIRST_PERSON),
// Scenery options
tile_diameter(5),
FG_MOUSE = 2
};
+ enum fgViewMode
+ {
+ FG_VIEW_FIRST_PERSON = 0,
+ FG_VIEW_FOLLOW = 1
+ };
+
private:
// The flight gear "root" directory
bool textures; // Textures enabled/disabled
bool wireframe; // Wireframe mode enabled/disabled
int xsize, ysize; // window size derived from geometry string
+ fgViewMode view_mode; // view mode
// Scenery options
int tile_radius; // Square radius of rendered tiles (around center
inline bool get_wireframe() const { return wireframe; }
inline int get_xsize() const { return xsize; }
inline int get_ysize() const { return ysize; }
+ inline fgViewMode get_view_mode() const { return view_mode; }
inline int get_tile_radius() const { return tile_radius; }
inline int get_tile_diameter() const { return tile_diameter; }
}
}
void toggle_panel();
- inline void set_xsize( int x ) { xsize= x; }
- inline void set_ysize( int y ) { xsize= y; }
+ inline void set_xsize( int x ) { xsize = x; }
+ inline void set_ysize( int y ) { ysize = y; }
+ inline void cycle_view_mode() {
+ if ( view_mode == FG_VIEW_FIRST_PERSON ) {
+ view_mode = FG_VIEW_FOLLOW;
+ } else if ( view_mode == FG_VIEW_FOLLOW ) {
+ view_mode = FG_VIEW_FIRST_PERSON;
+ }
+ }
+
inline void set_net_id( const string id ) { net_id = id; }
private:
static const bool use_larcsim_local_to_body = false;
-// This is a record containing current view parameters
+// This is a record containing current view parameters for the current
+// aircraft position
+FGView pilot_view;
+
+// This is a record containing current view parameters for the current
+// view position
FGView current_view;
void FGView::Init( void ) {
FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" );
- view_mode = FG_VIEW_FIRST_PERSON;
view_offset = 0.0;
goal_view_offset = 0.0;
}
-// Cycle view mode
-void FGView::cycle_view_mode() {
- if ( view_mode == FG_VIEW_FIRST_PERSON ) {
- view_mode = FG_VIEW_FOLLOW;
- } else if ( view_mode == FG_VIEW_FOLLOW ) {
- view_mode = FG_VIEW_FIRST_PERSON;
- }
-}
-
-
// Update the view volume, position, and orientation
-void FGView::UpdateViewParams( void ) {
- FGInterface *f = current_aircraft.fdm_state;
-
+void FGView::UpdateViewParams( const FGInterface& f ) {
UpdateViewMath(f);
if ((current_options.get_panel_status() != panel_hist) && (current_options.get_panel_status()))
// Update the view parameters
-void FGView::UpdateViewMath( FGInterface *f ) {
+void FGView::UpdateViewMath( const FGInterface& f ) {
Point3D p;
MAT3vec vec, forward, v0, minus_z;
MAT3mat R, TMP, UP, LOCAL, VIEW;
// scenery.center.y, scenery.center.z);
// calculate the cartesion coords of the current lat/lon/0 elev
- p = Point3D( f->get_Longitude(),
- f->get_Lat_geocentric(),
- f->get_Sea_level_radius() * FEET_TO_METER );
+ p = Point3D( f.get_Longitude(),
+ f.get_Lat_geocentric(),
+ f.get_Sea_level_radius() * FEET_TO_METER );
cur_zero_elev = fgPolarToCart3d(p) - scenery.center;
// calculate view position in current FG view coordinate system
// p.lon & p.lat are already defined earlier, p.radius was set to
// the sea level radius, so now we add in our altitude.
- if ( f->get_Altitude() * FEET_TO_METER >
+ if ( f.get_Altitude() * FEET_TO_METER >
(scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
- p.setz( p.radius() + f->get_Altitude() * FEET_TO_METER );
+ p.setz( p.radius() + f.get_Altitude() * FEET_TO_METER );
} else {
p.setz( p.radius() + scenery.cur_elev + 0.5 * METER_TO_FEET );
}
#else // FG_VIEW_INLINE_OPTIMIZATIONS
- double tmp_radius = f->get_Sea_level_radius() * FEET_TO_METER;
- double tmp = f->get_cos_lat_geocentric() * tmp_radius;
+ double tmp_radius = f.get_Sea_level_radius() * FEET_TO_METER;
+ double tmp = f.get_cos_lat_geocentric() * tmp_radius;
- cur_zero_elev.setx(f->get_cos_longitude()*tmp - scenery.center.x());
- cur_zero_elev.sety(f->get_sin_longitude()*tmp - scenery.center.y());
- cur_zero_elev.setz(f->get_sin_lat_geocentric()*tmp_radius - scenery.center.z());
+ cur_zero_elev.setx(f.get_cos_longitude()*tmp - scenery.center.x());
+ cur_zero_elev.sety(f.get_sin_longitude()*tmp - scenery.center.y());
+ cur_zero_elev.setz(f.get_sin_lat_geocentric()*tmp_radius - scenery.center.z());
// calculate view position in current FG view coordinate system
// p.lon & p.lat are already defined earlier, p.radius was set to
// the sea level radius, so now we add in our altitude.
- if ( f->get_Altitude() * FEET_TO_METER >
+ if ( f.get_Altitude() * FEET_TO_METER >
(scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
- tmp_radius += f->get_Altitude() * FEET_TO_METER;
+ tmp_radius += f.get_Altitude() * FEET_TO_METER;
} else {
tmp_radius += scenery.cur_elev + 0.5 * METER_TO_FEET ;
}
- tmp = f->get_cos_lat_geocentric() * tmp_radius;
- abs_view_pos.setx(f->get_cos_longitude()*tmp);
- abs_view_pos.sety(f->get_sin_longitude()*tmp);
- abs_view_pos.setz(f->get_sin_lat_geocentric()*tmp_radius);
+ tmp = f.get_cos_lat_geocentric() * tmp_radius;
+ abs_view_pos.setx(f.get_cos_longitude()*tmp);
+ abs_view_pos.sety(f.get_sin_longitude()*tmp);
+ abs_view_pos.setz(f.get_sin_lat_geocentric()*tmp_radius);
#endif // FG_VIEW_INLINE_OPTIMIZATIONS
// Answer (I think): The LaRCsim matrix is generated in a
// different reference frame than we've set up for our world
- LOCAL[0][0] = f->get_T_local_to_body_33();
- LOCAL[0][1] = -f->get_T_local_to_body_32();
- LOCAL[0][2] = -f->get_T_local_to_body_31();
+ LOCAL[0][0] = f.get_T_local_to_body_33();
+ LOCAL[0][1] = -f.get_T_local_to_body_32();
+ LOCAL[0][2] = -f.get_T_local_to_body_31();
LOCAL[0][3] = 0.0;
- LOCAL[1][0] = -f->get_T_local_to_body_23();
- LOCAL[1][1] = f->get_T_local_to_body_22();
- LOCAL[1][2] = f->get_T_local_to_body_21();
+ LOCAL[1][0] = -f.get_T_local_to_body_23();
+ LOCAL[1][1] = f.get_T_local_to_body_22();
+ LOCAL[1][2] = f.get_T_local_to_body_21();
LOCAL[1][3] = 0.0;
- LOCAL[2][0] = -f->get_T_local_to_body_13();
- LOCAL[2][1] = f->get_T_local_to_body_12();
- LOCAL[2][2] = f->get_T_local_to_body_11();
+ LOCAL[2][0] = -f.get_T_local_to_body_13();
+ LOCAL[2][1] = f.get_T_local_to_body_12();
+ LOCAL[2][2] = f.get_T_local_to_body_11();
LOCAL[2][3] = 0.0;
LOCAL[3][0] = LOCAL[3][1] = LOCAL[3][2] = LOCAL[3][3] = 0.0;
LOCAL[3][3] = 1.0;
// flight model
MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
- MAT3rotate(R, vec, f->get_Phi());
+ MAT3rotate(R, vec, f.get_Phi());
// cout << "Roll matrix" << endl;
// MAT3print(R, stdout);
sgVec3 sgrollvec;
sgSetVec3( sgrollvec, 0.0, 0.0, 1.0 );
sgMat4 sgPHI; // roll
- sgMakeRotMat4( sgPHI, f->get_Phi() * RAD_TO_DEG, sgrollvec );
+ sgMakeRotMat4( sgPHI, f.get_Phi() * RAD_TO_DEG, sgrollvec );
MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
- MAT3rotate(TMP, vec, f->get_Theta());
+ MAT3rotate(TMP, vec, f.get_Theta());
// cout << "Pitch matrix" << endl;;
// MAT3print(TMP, stdout);
MAT3mult(R, R, TMP);
sgVec3 sgpitchvec;
sgSetVec3( sgpitchvec, 0.0, 1.0, 0.0 );
sgMat4 sgTHETA; // pitch
- sgMakeRotMat4( sgTHETA, f->get_Theta() * RAD_TO_DEG,
+ sgMakeRotMat4( sgTHETA, f.get_Theta() * RAD_TO_DEG,
sgpitchvec );
sgMat4 sgROT;
MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
- MAT3rotate(TMP, vec, -f->get_Psi());
+ MAT3rotate(TMP, vec, -f.get_Psi());
// cout << "Yaw matrix" << endl;
// MAT3print(TMP, stdout);
MAT3mult(LOCAL, R, TMP);
sgVec3 sgyawvec;
sgSetVec3( sgyawvec, 1.0, 0.0, 0.0 );
sgMat4 sgPSI; // pitch
- sgMakeRotMat4( sgPSI, -f->get_Psi() * RAD_TO_DEG, sgyawvec );
+ sgMakeRotMat4( sgPSI, -f.get_Psi() * RAD_TO_DEG, sgyawvec );
sgMultMat4( sgLOCAL, sgROT, sgPSI );
// Derive the local UP transformation matrix based on *geodetic*
// coordinates
MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
- MAT3rotate(R, vec, f->get_Longitude()); // R = rotate about Z axis
+ MAT3rotate(R, vec, f.get_Longitude()); // R = rotate about Z axis
// printf("Longitude matrix\n");
// MAT3print(R, stdout);
MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
MAT3mult_vec(vec, vec, R);
- MAT3rotate(TMP, vec, -f->get_Latitude()); // TMP = rotate about X axis
+ MAT3rotate(TMP, vec, -f.get_Latitude()); // TMP = rotate about X axis
// printf("Latitude matrix\n");
// MAT3print(TMP, stdout);
// MAT3print(UP, stdout);
sgMakeRotMat4( sgUP,
- f->get_Longitude() * RAD_TO_DEG,
+ f.get_Longitude() * RAD_TO_DEG,
0.0,
- -f->get_Latitude() * RAD_TO_DEG );
+ -f.get_Latitude() * RAD_TO_DEG );
/*
cout << "FG derived UP matrix using sg routines" << endl;
MAT3mat print;
sgMultMat4( sgVIEW, sgVIEW_ROT, sgTRANS );
- FGMat4Wrapper tmp;
- sgCopyMat4( tmp.m, sgVIEW );
- follow.push_back( tmp );
+ // FGMat4Wrapper tmp;
+ // sgCopyMat4( tmp.m, sgVIEW );
+ // follow.push_back( tmp );
// generate the current up, forward, and fwrd-view vectors
MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
#else // FG_VIEW_INLINE_OPTIMIZATIONS
// // Build spherical to cartesian transform matrix directly
- double cos_lat = f->get_cos_latitude(); // cos(-f->get_Latitude());
- double sin_lat = -f->get_sin_latitude(); // sin(-f->get_Latitude());
- double cos_lon = f->get_cos_longitude(); //cos(f->get_Longitude());
- double sin_lon = f->get_sin_longitude(); //sin(f->get_Longitude());
+ double cos_lat = f.get_cos_latitude(); // cos(-f.get_Latitude());
+ double sin_lat = -f.get_sin_latitude(); // sin(-f.get_Latitude());
+ double cos_lon = f.get_cos_longitude(); //cos(f.get_Longitude());
+ double sin_lon = f.get_sin_longitude(); //sin(f.get_Longitude());
double *mat = (double *)UP;
FG_USING_STD(list);
-class FGMat4Wrapper {
-public:
- sgMat4 m;
-};
+// class FGMat4Wrapper {
+// public:
+// sgMat4 m;
+// };
-typedef list < FGMat4Wrapper > sgMat4_list;
-typedef sgMat4_list::iterator sgMat4_list_iterator;
-typedef sgMat4_list::const_iterator const_sgMat4_list_iterator;
+// typedef list < FGMat4Wrapper > sgMat4_list;
+// typedef sgMat4_list::iterator sgMat4_list_iterator;
+// typedef sgMat4_list::const_iterator const_sgMat4_list_iterator;
// used in views.cxx and tilemgr.cxx
public:
- enum fgViewMode
- {
- FG_VIEW_FIRST_PERSON = 0,
- FG_VIEW_FOLLOW = 1
- };
-
// the current offset from forward for viewing
double view_offset;
// Current model view matrix;
GLfloat MODEL_VIEW[16];
- // view mode
- fgViewMode view_mode;
-
// sg versions of our friendly matrices
sgMat4 sgLOCAL, sgUP, sgVIEW_ROT, sgTRANS, sgVIEW, sgLARC_TO_SSG;
// queue of view matrices so we can have a follow view
- sgMat4_list follow;
+ // sgMat4_list follow;
public:
void Init( void );
// Update the view volume, position, and orientation
- void UpdateViewParams( void );
+ void UpdateViewParams( const FGInterface& f );
// Flag to request that UpdateFOV() be called next time
// UpdateViewMath() is run.
inline void force_update_fov_math() { update_fov = true; }
// Update the view parameters
- void UpdateViewMath( FGInterface *f );
+ void UpdateViewMath( const FGInterface& f );
// Update the field of view coefficients
void UpdateFOV( const fgOPTIONS& o );
- // Cycle view mode
- void cycle_view_mode();
-
// accessor functions
inline double get_view_offset() const { return view_offset; }
inline void set_view_offset( double a ) { view_offset = a; }
};
+extern FGView pilot_view;
extern FGView current_view;