Replace plain doubles with SGGeod in FGViewer for position and target pos.
This commit is contained in:
parent
6d12675161
commit
2fa160d41a
2 changed files with 22 additions and 102 deletions
|
@ -31,10 +31,6 @@
|
||||||
|
|
||||||
#include "fg_props.hxx"
|
#include "fg_props.hxx"
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/scene/model/placement.hxx>
|
#include <simgear/scene/model/placement.hxx>
|
||||||
|
@ -65,12 +61,6 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
|
||||||
double target_x_offset_m, double target_y_offset_m,
|
double target_x_offset_m, double target_y_offset_m,
|
||||||
double target_z_offset_m, double near_m, bool internal ):
|
double target_z_offset_m, double near_m, bool internal ):
|
||||||
_dirty(true),
|
_dirty(true),
|
||||||
_lon_deg(0),
|
|
||||||
_lat_deg(0),
|
|
||||||
_alt_ft(0),
|
|
||||||
_target_lon_deg(0),
|
|
||||||
_target_lat_deg(0),
|
|
||||||
_target_alt_ft(0),
|
|
||||||
_roll_deg(0),
|
_roll_deg(0),
|
||||||
_pitch_deg(0),
|
_pitch_deg(0),
|
||||||
_heading_deg(0),
|
_heading_deg(0),
|
||||||
|
@ -156,64 +146,18 @@ FGViewer::setInternal ( bool internal )
|
||||||
_internal = internal;
|
_internal = internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
FGViewer::setLongitude_deg (double lon_deg)
|
|
||||||
{
|
|
||||||
_dirty = true;
|
|
||||||
_lon_deg = lon_deg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FGViewer::setLatitude_deg (double lat_deg)
|
|
||||||
{
|
|
||||||
_dirty = true;
|
|
||||||
_lat_deg = lat_deg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FGViewer::setAltitude_ft (double alt_ft)
|
|
||||||
{
|
|
||||||
_dirty = true;
|
|
||||||
_alt_ft = alt_ft;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FGViewer::setPosition (double lon_deg, double lat_deg, double alt_ft)
|
FGViewer::setPosition (double lon_deg, double lat_deg, double alt_ft)
|
||||||
{
|
{
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
_lon_deg = lon_deg;
|
_position = SGGeod::fromDegFt(lon_deg, lat_deg, alt_ft);
|
||||||
_lat_deg = lat_deg;
|
|
||||||
_alt_ft = alt_ft;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FGViewer::setTargetLongitude_deg (double lon_deg)
|
|
||||||
{
|
|
||||||
_dirty = true;
|
|
||||||
_target_lon_deg = lon_deg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FGViewer::setTargetLatitude_deg (double lat_deg)
|
|
||||||
{
|
|
||||||
_dirty = true;
|
|
||||||
_target_lat_deg = lat_deg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FGViewer::setTargetAltitude_ft (double alt_ft)
|
|
||||||
{
|
|
||||||
_dirty = true;
|
|
||||||
_target_alt_ft = alt_ft;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FGViewer::setTargetPosition (double lon_deg, double lat_deg, double alt_ft)
|
FGViewer::setTargetPosition (double lon_deg, double lat_deg, double alt_ft)
|
||||||
{
|
{
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
_target_lon_deg = lon_deg;
|
_target = SGGeod::fromDegFt(lon_deg, lat_deg, alt_ft);
|
||||||
_target_lat_deg = lat_deg;
|
|
||||||
_target_alt_ft = alt_ft;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -413,17 +357,13 @@ FGViewer::recalcLookFrom ()
|
||||||
// Update location data ...
|
// Update location data ...
|
||||||
if ( _from_model ) {
|
if ( _from_model ) {
|
||||||
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
||||||
_lat_deg = placement->getLatitudeDeg();
|
_position = placement->getPosition();
|
||||||
_lon_deg = placement->getLongitudeDeg();
|
|
||||||
_alt_ft = placement->getElevationFt();
|
|
||||||
|
|
||||||
_heading_deg = placement->getHeadingDeg();
|
_heading_deg = placement->getHeadingDeg();
|
||||||
_pitch_deg = placement->getPitchDeg();
|
_pitch_deg = placement->getPitchDeg();
|
||||||
_roll_deg = placement->getRollDeg();
|
_roll_deg = placement->getRollDeg();
|
||||||
}
|
}
|
||||||
double lat = _lat_deg;
|
|
||||||
double lon = _lon_deg;
|
|
||||||
double alt = _alt_ft;
|
|
||||||
double head = _heading_deg;
|
double head = _heading_deg;
|
||||||
double pitch = _pitch_deg;
|
double pitch = _pitch_deg;
|
||||||
double roll = _roll_deg;
|
double roll = _roll_deg;
|
||||||
|
@ -432,18 +372,16 @@ FGViewer::recalcLookFrom ()
|
||||||
dampEyeData(roll, pitch, head);
|
dampEyeData(roll, pitch, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The geodetic position of our base view position
|
|
||||||
SGGeod geodPos = SGGeod::fromDegFt(lon, lat, alt);
|
|
||||||
// The rotation rotating from the earth centerd frame to
|
// The rotation rotating from the earth centerd frame to
|
||||||
// the horizontal local OpenGL frame
|
// the horizontal local OpenGL frame
|
||||||
SGQuatd hlOr = SGQuatd::viewHL(geodPos);
|
SGQuatd hlOr = SGQuatd::viewHL(_position);
|
||||||
|
|
||||||
// the rotation from the horizontal local frame to the basic view orientation
|
// the rotation from the horizontal local frame to the basic view orientation
|
||||||
SGQuatd hlToBody = SGQuatd::fromYawPitchRollDeg(head, pitch, roll);
|
SGQuatd hlToBody = SGQuatd::fromYawPitchRollDeg(head, pitch, roll);
|
||||||
hlToBody = SGQuatd::simToView(hlToBody);
|
hlToBody = SGQuatd::simToView(hlToBody);
|
||||||
|
|
||||||
// The cartesian position of the basic view coordinate
|
// The cartesian position of the basic view coordinate
|
||||||
SGVec3d position = SGVec3d::fromGeod(geodPos);
|
SGVec3d position = SGVec3d::fromGeod(_position);
|
||||||
// the rotation offset, don't know why heading is negative here ...
|
// the rotation offset, don't know why heading is negative here ...
|
||||||
SGQuatd viewOffsetOr = SGQuatd::simToView(
|
SGQuatd viewOffsetOr = SGQuatd::simToView(
|
||||||
SGQuatd::fromYawPitchRollDeg(-_heading_offset_deg, _pitch_offset_deg,
|
SGQuatd::fromYawPitchRollDeg(-_heading_offset_deg, _pitch_offset_deg,
|
||||||
|
@ -462,9 +400,7 @@ FGViewer::recalcLookAt ()
|
||||||
// The geodetic position of our target to look at
|
// The geodetic position of our target to look at
|
||||||
if ( _at_model ) {
|
if ( _at_model ) {
|
||||||
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
||||||
_target_lat_deg = placement->getLatitudeDeg();
|
_target = placement->getPosition();
|
||||||
_target_lon_deg = placement->getLongitudeDeg();
|
|
||||||
_target_alt_ft = placement->getElevationFt();
|
|
||||||
_target_heading_deg = placement->getHeadingDeg();
|
_target_heading_deg = placement->getHeadingDeg();
|
||||||
_target_pitch_deg = placement->getPitchDeg();
|
_target_pitch_deg = placement->getPitchDeg();
|
||||||
_target_roll_deg = placement->getRollDeg();
|
_target_roll_deg = placement->getRollDeg();
|
||||||
|
@ -473,20 +409,16 @@ FGViewer::recalcLookAt ()
|
||||||
dampEyeData(_target_roll_deg, _target_pitch_deg, _target_heading_deg);
|
dampEyeData(_target_roll_deg, _target_pitch_deg, _target_heading_deg);
|
||||||
|
|
||||||
}
|
}
|
||||||
SGGeod geodTargetPos = SGGeod::fromDegFt(_target_lon_deg,
|
|
||||||
_target_lat_deg,
|
|
||||||
_target_alt_ft);
|
|
||||||
SGQuatd geodTargetOr = SGQuatd::fromYawPitchRollDeg(_target_heading_deg,
|
SGQuatd geodTargetOr = SGQuatd::fromYawPitchRollDeg(_target_heading_deg,
|
||||||
_target_pitch_deg,
|
_target_pitch_deg,
|
||||||
_target_roll_deg);
|
_target_roll_deg);
|
||||||
SGQuatd geodTargetHlOr = SGQuatd::fromLonLat(geodTargetPos);
|
SGQuatd geodTargetHlOr = SGQuatd::fromLonLat(_target);
|
||||||
|
|
||||||
|
|
||||||
if ( _from_model ) {
|
if ( _from_model ) {
|
||||||
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
||||||
_lat_deg = placement->getLatitudeDeg();
|
_position = placement->getPosition();
|
||||||
_lon_deg = placement->getLongitudeDeg();
|
|
||||||
_alt_ft = placement->getElevationFt();
|
|
||||||
_heading_deg = placement->getHeadingDeg();
|
_heading_deg = placement->getHeadingDeg();
|
||||||
_pitch_deg = placement->getPitchDeg();
|
_pitch_deg = placement->getPitchDeg();
|
||||||
_roll_deg = placement->getRollDeg();
|
_roll_deg = placement->getRollDeg();
|
||||||
|
@ -494,11 +426,10 @@ FGViewer::recalcLookAt ()
|
||||||
// update from our own data, just the rotation here...
|
// update from our own data, just the rotation here...
|
||||||
dampEyeData(_roll_deg, _pitch_deg, _heading_deg);
|
dampEyeData(_roll_deg, _pitch_deg, _heading_deg);
|
||||||
}
|
}
|
||||||
SGGeod geodEyePos = SGGeod::fromDegFt(_lon_deg, _lat_deg, _alt_ft);
|
|
||||||
SGQuatd geodEyeOr = SGQuatd::fromYawPitchRollDeg(_heading_deg,
|
SGQuatd geodEyeOr = SGQuatd::fromYawPitchRollDeg(_heading_deg,
|
||||||
_pitch_deg,
|
_pitch_deg,
|
||||||
_roll_deg);
|
_roll_deg);
|
||||||
SGQuatd geodEyeHlOr = SGQuatd::fromLonLat(geodEyePos);
|
SGQuatd geodEyeHlOr = SGQuatd::fromLonLat(_position);
|
||||||
|
|
||||||
// the rotation offset, don't know why heading is negative here ...
|
// the rotation offset, don't know why heading is negative here ...
|
||||||
SGQuatd eyeOffsetOr =
|
SGQuatd eyeOffsetOr =
|
||||||
|
@ -508,10 +439,10 @@ FGViewer::recalcLookAt ()
|
||||||
// Offsets to the eye position
|
// Offsets to the eye position
|
||||||
SGVec3d eyeOff(-_offset_m.z(), _offset_m.x(), -_offset_m.y());
|
SGVec3d eyeOff(-_offset_m.z(), _offset_m.x(), -_offset_m.y());
|
||||||
SGQuatd ec2eye = geodEyeHlOr*geodEyeOr;
|
SGQuatd ec2eye = geodEyeHlOr*geodEyeOr;
|
||||||
SGVec3d eyeCart = SGVec3d::fromGeod(geodEyePos);
|
SGVec3d eyeCart = SGVec3d::fromGeod(_position);
|
||||||
eyeCart += (ec2eye*eyeOffsetOr).backTransform(eyeOff);
|
eyeCart += (ec2eye*eyeOffsetOr).backTransform(eyeOff);
|
||||||
|
|
||||||
SGVec3d atCart = SGVec3d::fromGeod(geodTargetPos);
|
SGVec3d atCart = SGVec3d::fromGeod(_target);
|
||||||
|
|
||||||
// add target offsets to at_position...
|
// add target offsets to at_position...
|
||||||
SGVec3d target_pos_off(-_target_offset_m.z(), _target_offset_m.x(),
|
SGVec3d target_pos_off(-_target_offset_m.z(), _target_offset_m.x(),
|
||||||
|
|
|
@ -103,23 +103,16 @@ public:
|
||||||
// pilot view, model in model view).
|
// pilot view, model in model view).
|
||||||
// FIXME: the model view position (ie target positions)
|
// FIXME: the model view position (ie target positions)
|
||||||
// should be in the model class.
|
// should be in the model class.
|
||||||
virtual double getLongitude_deg () const { return _lon_deg; }
|
virtual double getLongitude_deg () const { return _position.getLongitudeDeg(); }
|
||||||
virtual double getLatitude_deg () const { return _lat_deg; }
|
virtual double getLatitude_deg () const { return _position.getLatitudeDeg(); }
|
||||||
virtual double getAltitudeASL_ft () const { return _alt_ft; }
|
|
||||||
virtual void setLongitude_deg (double lon_deg);
|
|
||||||
virtual void setLatitude_deg (double lat_deg);
|
|
||||||
virtual void setAltitude_ft (double alt_ft);
|
|
||||||
virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
|
virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
|
||||||
|
const SGGeod& getPosition() const { return _position; }
|
||||||
|
|
||||||
|
|
||||||
// Reference geodetic target position...
|
// Reference geodetic target position...
|
||||||
virtual double getTargetLongitude_deg () const { return _target_lon_deg; }
|
|
||||||
virtual double getTargetLatitude_deg () const { return _target_lat_deg; }
|
|
||||||
virtual double getTargetAltitudeASL_ft () const { return _target_alt_ft; }
|
|
||||||
virtual void setTargetLongitude_deg (double lon_deg);
|
|
||||||
virtual void setTargetLatitude_deg (double lat_deg);
|
|
||||||
virtual void setTargetAltitude_ft (double alt_ft);
|
|
||||||
virtual void setTargetPosition (double lon_deg, double lat_deg, double alt_ft);
|
virtual void setTargetPosition (double lon_deg, double lat_deg, double alt_ft);
|
||||||
|
const SGGeod& getTargetPosition() const { return _target; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -265,12 +258,8 @@ private:
|
||||||
SGQuatd mViewOrientation;
|
SGQuatd mViewOrientation;
|
||||||
SGVec3d _absolute_view_pos;
|
SGVec3d _absolute_view_pos;
|
||||||
|
|
||||||
double _lon_deg;
|
SGGeod _position;
|
||||||
double _lat_deg;
|
SGGeod _target;
|
||||||
double _alt_ft;
|
|
||||||
double _target_lon_deg;
|
|
||||||
double _target_lat_deg;
|
|
||||||
double _target_alt_ft;
|
|
||||||
|
|
||||||
double _roll_deg;
|
double _roll_deg;
|
||||||
double _pitch_deg;
|
double _pitch_deg;
|
||||||
|
|
Loading…
Reference in a new issue