#include <simgear/debug/logstream.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/sg_path.hxx>
-#include <simgear/scene/model/location.hxx>
#include <simgear/scene/model/placement.hxx>
#include <simgear/xml/easyxml.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
-#include <Model/acmodel.hxx>
#include "FGFDM.hpp"
#include "Atmosphere.hpp"
wind[1] = get_V_east_airmass() * FT2M * -1.0;
wind[2] = get_V_down_airmass() * FT2M * -1.0;
- // Get ground elevation from the FGinterface's FGlocation data
- double ground = getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m();
+ // Get ground elevation
+ double ground = fgGetDouble("/position/ground-elev-m");
// cout << "YASIM: ground = " << ground << endl;
float pressure = fgGetFloat("/environment/pressure-inhg") * INHG2PA;
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/scene/model/location.hxx>
#include <simgear/scene/model/placement.hxx>
#include <simgear/timing/timestamp.hxx>
#include <FDM/LaRCsim/ls_interface.h>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
-#include <Model/acmodel.hxx>
#include "flight.hxx"
sin_latitude=cos_latitude=0;
sin_longitude=cos_longitude=0;
altitude_agl=0;
- _acmodel = 0;
}
void
// stamp();
// set_remainder( 0 );
- // linking in FGAircraft instance...
- // FIXME: when using multiple instances, then there will be more than
- // one model so get_aircraft_model will have to be indexed to the correct
- // model.
- _acmodel = globals->get_aircraft_model();
-
// Set initial position
SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." );
set_Longitude( fgGetDouble("/sim/presets/longitude-deg")
* SGD_DEGREES_TO_RADIANS );
double ground_elev_m = globals->get_scenery()->get_cur_elev();
double ground_elev_ft = ground_elev_m * SG_METER_TO_FEET;
- _acmodel->get3DModel()->getSGLocation()->set_cur_elev_m( ground_elev_m );
+ fgSetDouble("/position/ground-elev-m", ground_elev_m);
_set_Runway_altitude ( ground_elev_ft );
if ( fgGetBool("/sim/presets/onground")
|| fgGetDouble("/sim/presets/altitude-ft") < ground_elev_ft ) {
_set_Geodetic_Position( lat, lon, alt );
_set_Sea_level_radius( sl_radius * SG_METER_TO_FEET );
- if ( getACModel() != NULL ) {
- _set_Runway_altitude( getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m() * SG_METER_TO_FEET );
- }
+ _set_Runway_altitude( fgGetDouble("/position/ground-elev-m") * SG_METER_TO_FEET );
_set_sin_lat_geocentric( lat_geoc );
_set_cos_lat_geocentric( lat_geoc );
_set_Geodetic_Position( lat_geod, lon, alt );
_set_Sea_level_radius( sl_radius2 * SG_METER_TO_FEET );
- _set_Runway_altitude( getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m() * SG_METER_TO_FEET );
+ _set_Runway_altitude( fgGetDouble("/position/ground-elev-m") * SG_METER_TO_FEET );
_set_sin_lat_geocentric( lat_geoc );
_set_cos_lat_geocentric( lat_geoc );
static const SGPropertyNode *groundlevel_nearplane
= fgGetNode("/sim/current-view/ground-level-nearplane-m");
- FGViewer *current__view = globals->get_current_view();
-
FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
static double last_visibility = -9999;
// initializations and are running the main loop, so this will
// now work without seg faulting the system.
+ FGViewer *current__view = globals->get_current_view();
+
// calculate our current position in cartesian space
globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
globals->get_event_mgr()->update(delta_time_sec);
- SGLocation * acmodel_location = 0;
- if(cur_fdm_state->getACModel() != 0) {
- acmodel_location = (SGLocation *) cur_fdm_state->getACModel()->get3DModel()->getSGLocation();
- }
-
SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
double visibility_meters = fgGetDouble("/environment/visibility-m");
FGViewer *current_view = globals->get_current_view();
+ // get the location data for the primary FDM (now hardcoded to ac model)...
+ SGLocation * acmodel_location = 0;
+ acmodel_location = (SGLocation *) globals->get_aircraft_model()->get3DModel()->getSGLocation();
+
// update tile manager for FDM...
- // ...only if location is different than the viewer (to avoid duplicating effort)
- if( acmodel_location != current_view->getSGLocation() ) {
+ // ...only if location is different than the current-view location (to avoid duplicating effort)
+ if( !fgGetBool("/sim/current-view/config/from-model") ) {
if( acmodel_location != 0 ) {
globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
visibility_meters );
if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
acmodel_location->
set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
+ fgSetDouble("/position/ground-elev-m", globals->get_scenery()->get_cur_elev());
}
acmodel_location->
set_tile_center( globals->get_scenery()->get_next_center() );
// If fdm location is same as viewer's then we didn't do the update for fdm location
// above so we need to save the viewer results in the fdm SGLocation as well...
- if( acmodel_location == current_view->getSGLocation() ) {
+ if( fgGetBool("/sim/current-view/config/from-model") ) {
if( acmodel_location != 0 ) {
if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
+ fgSetDouble("/position/ground-elev-m", globals->get_scenery()->get_cur_elev());
}
acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() );
}
view_h = height;
}
- // for all views
- FGViewMgr *viewmgr = globals->get_viewmgr();
- for ( int i = 0; i < viewmgr->size(); ++i ) {
- viewmgr->get_view(i)->
- set_aspect_ratio((float)view_h / (float)width);
- }
-
glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
fgSetInt("/sim/startup/xsize", width);
fgSetInt("/sim/startup/ysize", height);
guiInitMouse(width, height);
- ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
- viewmgr->get_current_view()->get_v_fov() );
+ // 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((float)view_h / (float)width);
+ }
- fgHUDReshape();
+ ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
+ viewmgr->get_current_view()->get_v_fov() );
#ifdef FG_USE_CLOUDS_3D
- sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
- viewmgr->get_current_view()->get_v_fov() );
+ sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
+ viewmgr->get_current_view()->get_v_fov() );
#endif
+ }
+
+ fgHUDReshape();
}
// by considering them to be 3x3 until the very end -- NHV
static void MakeVIEW_OFFSET( sgMat4 dst,
const float angle1, const sgVec3 axis1,
- const float angle2, const sgVec3 axis2 )
+ const float angle2, const sgVec3 axis2,
+ const float angle3, const sgVec3 axis3 )
{
// make rotmatrix1 from angle and axis
float s = (float) sin ( angle1 ) ;
mat2[2][1] = tmp * axis2[1] - s * axis2[0] ;
mat2[2][2] = tmp * axis2[2] + c ;
+
+ // make rotmatrix3 from angle and axis (roll)
+ s = (float) sin ( angle3 ) ;
+ c = (float) cos ( angle3 ) ;
+ t = SG_ONE - c ;
+
+ sgMat3 mat3;
+ tmp = t * axis3[0];
+ mat3[0][0] = tmp * axis3[0] + c ;
+ mat3[0][1] = tmp * axis3[1] + s * axis3[2] ;
+ mat3[0][2] = tmp * axis3[2] - s * axis3[1] ;
+
+ tmp = t * axis2[1];
+ mat3[1][0] = tmp * axis3[0] - s * axis3[2] ;
+ mat3[1][1] = tmp * axis3[1] + c ;
+ mat3[1][2] = tmp * axis3[2] + s * axis3[0] ;
+
+ tmp = t * axis3[2];
+ mat3[2][0] = tmp * axis3[0] + s * axis3[1] ;
+ mat3[2][1] = tmp * axis3[1] - s * axis3[0] ;
+ mat3[2][2] = tmp * axis3[2] + c ;
+
+ sgMat3 matt;
+
// multiply matrices
for ( int j = 0 ; j < 3 ; j++ ) {
- dst[0][j] = mat2[0][0] * mat1[0][j] +
+ matt[0][j] = mat2[0][0] * mat1[0][j] +
mat2[0][1] * mat1[1][j] +
mat2[0][2] * mat1[2][j];
- dst[1][j] = mat2[1][0] * mat1[0][j] +
+ matt[1][j] = mat2[1][0] * mat1[0][j] +
mat2[1][1] * mat1[1][j] +
mat2[1][2] * mat1[2][j];
- dst[2][j] = mat2[2][0] * mat1[0][j] +
+ matt[2][j] = mat2[2][0] * mat1[0][j] +
mat2[2][1] * mat1[1][j] +
mat2[2][2] * mat1[2][j];
}
+
+ // multiply matrices
+ for ( int j = 0 ; j < 3 ; j++ ) {
+ dst[0][j] = mat3[0][0] * matt[0][j] +
+ mat3[0][1] * matt[1][j] +
+ mat3[0][2] * matt[2][j];
+
+ dst[1][j] = mat3[1][0] * matt[0][j] +
+ mat3[1][1] * matt[1][j] +
+ mat3[1][2] * matt[2][j];
+
+ dst[2][j] = mat3[2][0] * matt[0][j] +
+ mat3[2][1] * matt[1][j] +
+ mat3[2][2] * matt[2][j];
+ }
// fill in 4x4 matrix elements
dst[0][3] = SG_ZERO;
dst[1][3] = SG_ZERO;
sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] );
sgSetVec3( forward, -LOCAL[0][0], -LOCAL[0][1], -LOCAL[0][2] );
-
// Note that when in "lookfrom" view the "view up" vector is always applied
// to the viewer. View up is based on verticle of the aircraft itself. (see
// "LOCAL" matrix above)
// Orientation Offsets matrix
MakeVIEW_OFFSET( VIEW_OFFSET,
_heading_offset_deg * SG_DEGREES_TO_RADIANS, _view_up,
- _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right );
+ _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right,
+ _roll_offset_deg * SG_DEGREES_TO_RADIANS, forward );
// Make the VIEW matrix.
sgSetVec4(VIEW[0], right[0], right[1], right[2],SG_ZERO);
FGViewer::recalcLookAt ()
{
- sgVec3 right;
+ sgVec3 right, forward;
sgVec3 eye_pos, at_pos;
sgVec3 position_offset; // eye position offsets (xyz)
sgVec3 target_position_offset; // target position offsets (xyz)
// make sg vectors view up, right and forward vectors from LOCAL
sgSetVec3( _view_up, LOCAL[2][0], LOCAL[2][1], LOCAL[2][2] );
sgSetVec3( right, LOCAL[1][0], LOCAL[1][1], LOCAL[1][2] );
+ sgSetVec3( forward, -LOCAL[0][0], -LOCAL[0][1], -LOCAL[0][2] );
// rotate model or local matrix to get a matrix to apply Eye Position Offsets
sgMat4 VIEW_UP; // L0 forward L1 right L2 up
// get Orientation Offsets matrix
MakeVIEW_OFFSET( VIEW_OFFSET,
(_heading_offset_deg - 180) * SG_DEGREES_TO_RADIANS, _view_up,
- _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right );
+ _pitch_offset_deg * SG_DEGREES_TO_RADIANS, right,
+ _roll_offset_deg * SG_DEGREES_TO_RADIANS, forward );
// add in the position offsets
sgSetVec3( position_offset, _y_offset_m, _x_offset_m, _z_offset_m );
}
}
}
+
+
+ for ( i = 0; i < dt_ms; i++ ) {
+ if ( fabs( _goal_roll_offset_deg - _roll_offset_deg ) < 1 ) {
+ setRollOffset_deg( _goal_roll_offset_deg );
+ break;
+ } else {
+ // move current_view.roll_offset_deg towards
+ // current_view.goal_roll_offset
+ if ( _goal_roll_offset_deg > _roll_offset_deg )
+ {
+ incRollOffset_deg( 1.0 );
+ } else {
+ incRollOffset_deg( -1.0 );
+ }
+ if ( _roll_offset_deg > 90 ) {
+ setRollOffset_deg(90);
+ } else if ( _roll_offset_deg < -90 ) {
+ setRollOffset_deg( -90 );
+ }
+ }
+ }
+
}
_pitch_offset_deg += amt;
}
+ // add to _roll_offset_deg
+ inline void incRollOffset_deg( double amt ) {
+ set_dirty();
+ _roll_offset_deg += amt;
+ }
+
inline void set_reverse_view_offset( bool val ) {
_reverse_view_offset = val;
}
&FGViewMgr::getGoalViewPitchOffset_deg,
&FGViewMgr::setGoalViewPitchOffset_deg);
fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
+ fgTie("/sim/current-view/roll-offset-deg", this,
+ &FGViewMgr::getViewRollOffset_deg,
+ &FGViewMgr::setViewRollOffset_deg);
+ fgSetArchivable("/sim/current-view/roll-offset-deg");
+ fgTie("/sim/current-view/goal-roll-offset-deg", this,
+ &FGViewMgr::getGoalViewRollOffset_deg,
+ &FGViewMgr::setGoalViewRollOffset_deg);
+ fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
fgTie("/sim/current-view/view-number", this,
&FGViewMgr::getView, &FGViewMgr::setView);
fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
fgGetDouble(nodepath.c_str()));
+ nodepath = viewpath;
+ nodepath += "/config/from-model";
+ fgSetBool("/sim/current-view/config/from-model",
+ fgGetBool(nodepath.c_str()));
+
+
// copy view data
fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
get_current_view()->getTargetYOffset_m());
fgSetDouble("/sim/current-view/target-z-offset-m",
get_current_view()->getTargetZOffset_m());
+
+ fgSetBool("/sim/current-view/internal",
+ get_current_view()->getInternal());
+
}
view->setGoalPitchOffset_deg(tilt);
}
+double
+FGViewMgr::getViewRollOffset_deg () const
+{
+ const FGViewer * view = get_current_view();
+ return (view == 0 ? 0 : view->getRollOffset_deg());
+}
+
+void
+FGViewMgr::setViewRollOffset_deg (double tilt)
+{
+ FGViewer * view = get_current_view();
+ if (view != 0) {
+ view->setGoalRollOffset_deg(tilt);
+ view->setRollOffset_deg(tilt);
+ }
+}
+
+double
+FGViewMgr::getGoalViewRollOffset_deg () const
+{
+ const FGViewer * view = get_current_view();
+ return (view == 0 ? 0 : view->getGoalRollOffset_deg());
+}
+
+void
+FGViewMgr::setGoalViewRollOffset_deg (double tilt)
+{
+ FGViewer * view = get_current_view();
+ if (view != 0)
+ view->setGoalRollOffset_deg(tilt);
+}
+
double
FGViewMgr::getViewXOffset_m () const
{
double getViewPitchOffset_deg () const;
void setViewPitchOffset_deg (double tilt);
double getGoalViewPitchOffset_deg () const;
+ void setGoalViewRollOffset_deg (double tilt);
+ double getViewRollOffset_deg () const;
+ void setViewRollOffset_deg (double tilt);
+ double getGoalViewRollOffset_deg () const;
void setGoalViewPitchOffset_deg (double tilt);
double getViewXOffset_m () const;
void setViewXOffset_m (double x);
FGAircraftModel::update (double dt)
{
int view_number = globals->get_viewmgr()->get_current();
- int is_internal = globals->get_current_view()->getInternal();
+ int is_internal = fgGetBool("/sim/current-view/internal");
if (view_number == 0 && !is_internal) {
_aircraft->setVisible(false);