1
0
Fork 0

(try to) properly align model and viewer

This commit is contained in:
ehofman 2009-10-06 12:09:50 +00:00 committed by Tim Moore
parent b64259b295
commit 5107a9d07f
3 changed files with 22 additions and 16 deletions

View file

@ -248,6 +248,7 @@ FGViewMgr::update (double dt)
FGViewer *loop_view = (FGViewer *)get_view(current);
SGPropertyNode *n = config_list[current];
double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
SGVec3f velocity = SGVec3f(0,0,0);
// Set up view location and orientation
@ -264,6 +265,10 @@ FGViewMgr::update (double dt)
} else {
// force recalc in viewer
loop_view->set_dirty();
// get the model velocity for the in-cockpit view
FGAircraftModel *aircraft = globals->get_aircraft_model();
velocity = aircraft->getVelocity();
}
// if lookat (type 1) then get target data...
@ -300,7 +305,7 @@ FGViewMgr::update (double dt)
// set the viewer posotion in Cartesian coordinates in meters
smgr->set_position(abs_viewer_position);
smgr->set_orientation(loop_view->getViewOrientation());
smgr->set_velocity(SGVec3f(0,0,0)); // TODO: in meters per second
smgr->set_velocity(velocity);
}
void

View file

@ -36,6 +36,7 @@
FGAircraftModel::FGAircraftModel ()
: _aircraft(0),
_velocity(SGVec3f::zeros()),
_fx(0),
_lon(0),
_lat(0),
@ -43,8 +44,7 @@ FGAircraftModel::FGAircraftModel ()
_pitch(0),
_roll(0),
_heading(0),
_speed_north(0),
_speed_east(0),
_speed(0),
_speed_up(0)
{
SGSoundMgr *smgr;
@ -92,9 +92,8 @@ FGAircraftModel::bind ()
_pitch = fgGetNode("orientation/pitch-deg", true);
_roll = fgGetNode("orientation/roll-deg", true);
_heading = fgGetNode("orientation/heading-deg", true);
_speed_north = fgGetNode("/velocities/speed-north-fps", true);
_speed_east = fgGetNode("/velocities/speed-east-fps", true);
_speed_up = fgGetNode("/velocities/vertical-speed-fps", true);
_speed = fgGetNode("velocities/true-airspeed-kt", true);
_speed_up = fgGetNode("velocities/vertical-speed-fps", true);
}
void
@ -123,7 +122,7 @@ FGAircraftModel::update (double dt)
_heading->getDoubleValue());
_aircraft->update();
// update model's sample group values
// update model's audio sample values
// Get the Cartesian coordinates in meters
SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
_fx->set_position( pos );
@ -132,15 +131,16 @@ FGAircraftModel::update (double dt)
orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
_pitch->getDoubleValue(),
_roll->getDoubleValue());
SGVec3d orient = orient_m.rotateBack(SGVec3d::e1());
SGVec3d orient = -orient_m.rotate(SGVec3d::e1());
_fx->set_orientation( toVec3f(orient) );
SGVec3f vel = SGVec3f( _speed_north->getFloatValue(),
_speed_east->getFloatValue(),
_speed_up->getFloatValue());
// TODO: rotate to properly align with the model orientation
_fx->set_velocity( vel*SG_FEET_TO_METER );
// For now assume the aircraft speed is always along the longitudinal
// axis, so sideslipping is not taken into account. This should be fine
// for audio.
_velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_FPS);
// _velocity[2] = _speed_up->getFloatValue();
_velocity *= SG_FEET_TO_METER;
_fx->set_velocity( _velocity );
}

View file

@ -39,10 +39,12 @@ public:
virtual void unbind ();
virtual void update (double dt);
virtual SGModelPlacement * get3DModel() { return _aircraft; }
virtual SGVec3f getVelocity() { return _velocity; }
private:
SGModelPlacement * _aircraft;
SGVec3f _velocity;
FGFX * _fx;
SGPropertyNode * _lon;
@ -51,8 +53,7 @@ private:
SGPropertyNode * _pitch;
SGPropertyNode * _roll;
SGPropertyNode * _heading;
SGPropertyNode * _speed_north;
SGPropertyNode * _speed_east;
SGPropertyNode * _speed;
SGPropertyNode * _speed_up;
};