Latest changes to the viewer code from Melchior FRANZ
This commit is contained in:
parent
849219ef45
commit
7e15ed39a1
3 changed files with 42 additions and 57 deletions
|
@ -148,8 +148,6 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
|
|||
_roll_deg(0),
|
||||
_pitch_deg(0),
|
||||
_heading_deg(0),
|
||||
_damped_roll_deg(0),
|
||||
_damped_pitch_deg(0),
|
||||
_scaling_type(FG_SCALING_MAX)
|
||||
{
|
||||
sgdZeroVec3(_absolute_view_pos);
|
||||
|
@ -158,7 +156,14 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
|
|||
_from_model_index = from_model_index;
|
||||
_at_model = at_model;
|
||||
_at_model_index = at_model_index;
|
||||
_damp = at_model_damping;
|
||||
|
||||
_damp = _damp_alt = 0.0;
|
||||
if (at_model_damping > 0.0) {
|
||||
_damp = 1 - 1.0 / pow(10, at_model_damping);
|
||||
_damp_alt = _damp * _damp * _damp * _damp;
|
||||
} else if (at_model_damping < 0.0)
|
||||
_damp = 1 - 1.0 / pow(10, -at_model_damping);
|
||||
|
||||
_x_offset_m = x_offset_m;
|
||||
_y_offset_m = y_offset_m;
|
||||
_z_offset_m = z_offset_m;
|
||||
|
@ -498,36 +503,42 @@ FGViewer::recalcOurOwnLocation (SGLocation * location, double lon_deg, double la
|
|||
{
|
||||
// update from our own data...
|
||||
if (_damp > 0.0) {
|
||||
double d;
|
||||
|
||||
d = roll_deg - _damped_roll_deg;
|
||||
if (d > 180.0)
|
||||
_damped_roll_deg += 360.0;
|
||||
else if (d < -180.0)
|
||||
_damped_roll_deg -= 360.0;
|
||||
|
||||
d = pitch_deg - _damped_pitch_deg;
|
||||
if (d > 180.0)
|
||||
_damped_pitch_deg += 360.0;
|
||||
else if (d < -180.0)
|
||||
_damped_pitch_deg -= 360.0;
|
||||
|
||||
d = heading_deg - _damped_heading_deg;
|
||||
if (d > 180.0)
|
||||
_damped_heading_deg += 360.0;
|
||||
else if (d < -180.0)
|
||||
_damped_heading_deg -= 360.0;
|
||||
|
||||
static bool firstrun = true;
|
||||
if (firstrun) {
|
||||
_damped_heading_deg = _target_location->getHeading_deg();
|
||||
firstrun = false;
|
||||
static FGViewer *last = 0;
|
||||
if (last != this) {
|
||||
_damped_alt_ft = alt_ft;
|
||||
_damped_roll_deg = roll_deg;
|
||||
_damped_pitch_deg = pitch_deg;
|
||||
_damped_heading_deg = heading_deg;
|
||||
last = this;
|
||||
}
|
||||
|
||||
double d;
|
||||
d = _damped_roll_deg - roll_deg;
|
||||
if (d >= 180.0)
|
||||
_damped_roll_deg -= 360.0;
|
||||
else if (d < -180.0)
|
||||
_damped_roll_deg += 360.0;
|
||||
|
||||
d = _damped_pitch_deg - pitch_deg;
|
||||
if (d >= 180.0)
|
||||
_damped_pitch_deg -= 360.0;
|
||||
else if (d < -180.0)
|
||||
_damped_pitch_deg += 360.0;
|
||||
|
||||
d = _damped_heading_deg - heading_deg;
|
||||
if (d >= 180.0)
|
||||
_damped_heading_deg -= 360.0;
|
||||
else if (d < -180.0)
|
||||
_damped_heading_deg += 360.0;
|
||||
|
||||
d = 1.0 - _damp;
|
||||
roll_deg = _damped_roll_deg = roll_deg * d + _damped_roll_deg * _damp;
|
||||
pitch_deg = _damped_pitch_deg = pitch_deg * d + _damped_pitch_deg * _damp;
|
||||
heading_deg = _damped_heading_deg = heading_deg * d + _damped_heading_deg * _damp;
|
||||
|
||||
if (_damp_alt > 0.0)
|
||||
alt_ft = _damped_alt_ft = alt_ft * (1 - _damp_alt) + _damped_alt_ft * _damp_alt;
|
||||
}
|
||||
location->setPosition( lon_deg, lat_deg, alt_ft );
|
||||
location->setOrientation( roll_deg, pitch_deg, heading_deg );
|
||||
|
@ -840,25 +851,4 @@ FGViewer::update (double dt)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,6 +289,8 @@ private:
|
|||
double _damped_roll_deg;
|
||||
double _damped_pitch_deg;
|
||||
double _damped_heading_deg;
|
||||
double _damp_alt;
|
||||
double _damped_alt_ft;
|
||||
|
||||
// Position offsets from FDM origin. The X axis is positive
|
||||
// out the tail, Y is out the right wing, and Z is positive up.
|
||||
|
@ -382,12 +384,6 @@ private:
|
|||
void recalcOurOwnLocation (SGLocation * location, double lon_deg, double lat_deg, double alt_ft,
|
||||
double roll_deg, double pitch_deg, double heading_deg);
|
||||
|
||||
// add to _roll_offset_deg
|
||||
inline void incRollOffset_deg( double amt ) {
|
||||
set_dirty();
|
||||
_roll_offset_deg += amt;
|
||||
}
|
||||
|
||||
// add to _heading_offset_deg
|
||||
inline void incHeadingOffset_deg( double amt ) {
|
||||
set_dirty();
|
||||
|
|
|
@ -51,7 +51,7 @@ FGViewMgr::init ()
|
|||
bool at_model = false;
|
||||
int from_model_index = 0;
|
||||
int at_model_index = 0;
|
||||
double at_model_damping = 0.0;
|
||||
double at_model_damping;
|
||||
double x_offset_m, y_offset_m, z_offset_m, fov_deg;
|
||||
double heading_offset_deg, pitch_offset_deg, roll_offset_deg;
|
||||
double target_x_offset_m, target_y_offset_m, target_z_offset_m;
|
||||
|
@ -94,11 +94,10 @@ FGViewMgr::init ()
|
|||
nodepath += "/config/at-model-idx";
|
||||
at_model_index = fgGetInt(nodepath.c_str());
|
||||
|
||||
// view damping (0.0: no damping; <0.0: all but alt; >0.0: damp all)
|
||||
nodepath = viewpath;
|
||||
nodepath += "/config/at-model-damping";
|
||||
at_model_damping = 1 - 1.0 / pow(10, fgGetDouble(nodepath.c_str()));
|
||||
if (at_model_damping < 0.0)
|
||||
at_model_damping = 0.0;
|
||||
at_model_damping = fgGetDouble(nodepath.c_str(), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue