1
0
Fork 0

Melchior FRANZ:

The current chase view respects heading but ignores roll & pitch. And it follows heading without delay, which makes the viewer behave quite strange. This change makes the chase view feel more natural. You aren't fixed behind the plane, but follow all its movements with a delay.

Erik Hofman:
I've decided not to add the patch to preferences.xml in the base package because something feels funny with that. I think there needs to be some more discussion about it.
This commit is contained in:
ehofman 2003-07-11 08:58:26 +00:00
parent a47f8cabab
commit 6e174947df
3 changed files with 80 additions and 6 deletions

View file

@ -132,7 +132,7 @@ static void MakeVIEW_OFFSET( sgMat4 dst,
// Constructor...
FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
bool at_model, int at_model_index,
bool at_model, int at_model_index, double at_model_damping,
double x_offset_m, double y_offset_m, double z_offset_m,
double heading_offset_deg, double pitch_offset_deg,
double roll_offset_deg, double fov_deg,
@ -148,6 +148,8 @@ 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);
@ -156,6 +158,7 @@ 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;
_x_offset_m = x_offset_m;
_y_offset_m = y_offset_m;
_z_offset_m = z_offset_m;
@ -494,6 +497,38 @@ FGViewer::recalcOurOwnLocation (SGLocation * location, double lon_deg, double la
double roll_deg, double pitch_deg, double heading_deg)
{
// 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;
}
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;
}
location->setPosition( lon_deg, lat_deg, alt_ft );
location->setOrientation( roll_deg, pitch_deg, heading_deg );
sgCopyMat4(LOCAL,
@ -805,4 +840,25 @@ 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 );
}
}
}
}

View file

@ -62,7 +62,7 @@ public:
// Constructor
FGViewer( fgViewType Type, bool from_model, int from_model_index,
bool at_model, int at_model_index,
bool at_model, int at_model_index, double damping,
double x_offset_m, double y_offset_m, double z_offset_m,
double heading_offset_deg, double pitch_offset_deg,
double roll_offset_deg, double fov_deg,
@ -285,6 +285,11 @@ private:
double _target_pitch_deg;
double _target_heading_deg;
double _damp;
double _damped_roll_deg;
double _damped_pitch_deg;
double _damped_heading_deg;
// Position offsets from FDM origin. The X axis is positive
// out the tail, Y is out the right wing, and Z is positive up.
// distance in meters
@ -377,6 +382,12 @@ 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();

View file

@ -51,6 +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 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;
@ -91,7 +92,13 @@ FGViewMgr::init ()
if (at_model) {
nodepath = viewpath;
nodepath += "/config/at-model-idx";
at_model_index = fgGetInt(nodepath.c_str());
at_model_index = fgGetInt(nodepath.c_str());
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;
}
}
@ -138,15 +145,15 @@ FGViewMgr::init ()
// supporting two types now "lookat" = 1 and "lookfrom" = 0
if ( strcmp("lookat",strdata.c_str()) == 0 )
add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
at_model, at_model_index, x_offset_m,
y_offset_m,z_offset_m,
at_model, at_model_index, at_model_damping,
x_offset_m, y_offset_m,z_offset_m,
heading_offset_deg, pitch_offset_deg,
roll_offset_deg, fov_deg,
target_x_offset_m, target_y_offset_m,
target_z_offset_m, near_m ));
else
add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index, false,
0, x_offset_m, y_offset_m, z_offset_m,
0, 0.0, x_offset_m, y_offset_m, z_offset_m,
heading_offset_deg, pitch_offset_deg,
roll_offset_deg, fov_deg, 0, 0, 0, near_m ));
}