Zap SGLocation.
Modified Files: projects/VC7.1/SimGear.vcproj projects/VC8/SimGear.vcproj simgear/scene/model/Makefile.am simgear/scene/model/placement.cxx simgear/scene/model/placement.hxx Removed Files: simgear/scene/model/location.cxx simgear/scene/model/location.hxx
This commit is contained in:
@@ -683,12 +683,6 @@
|
||||
<File
|
||||
RelativePath="..\..\simgear\scene\model\CheckSceneryVisitor.hxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\scene\model\location.cxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\scene\model\location.hxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\scene\model\model.cxx">
|
||||
</File>
|
||||
|
||||
@@ -295,10 +295,6 @@
|
||||
RelativePath="..\..\simgear\math\linintp2.inl"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\scene\model\location.hxx"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\debug\logstream.hxx"
|
||||
>
|
||||
@@ -939,10 +935,6 @@
|
||||
RelativePath="..\..\simgear\nasal\lib.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\scene\model\location.cxx"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\debug\logstream.cxx"
|
||||
>
|
||||
|
||||
@@ -7,7 +7,6 @@ noinst_HEADERS =
|
||||
include_HEADERS = \
|
||||
animation.hxx \
|
||||
particles.hxx \
|
||||
location.hxx \
|
||||
model.hxx \
|
||||
modellib.hxx \
|
||||
ModelRegistry.hxx \
|
||||
@@ -28,7 +27,6 @@ include_HEADERS = \
|
||||
libsgmodel_a_SOURCES = \
|
||||
animation.cxx \
|
||||
particles.cxx \
|
||||
location.cxx \
|
||||
model.cxx \
|
||||
modellib.cxx \
|
||||
ModelRegistry.cxx \
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
// location.cxx -- class for determining model location in the flightgear world.
|
||||
//
|
||||
// Written by Jim Wilson, David Megginson, started April 2002.
|
||||
// Based largely on code by Curtis Olson and Norman Vine.
|
||||
//
|
||||
// Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <simgear_config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include <simgear/math/polar3d.hxx>
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
|
||||
#include "location.hxx"
|
||||
|
||||
|
||||
/**
|
||||
* make model transformation Matrix - based on optimizations by NHV
|
||||
*/
|
||||
static void MakeTRANS( sgMat4 dst, const double Theta,
|
||||
const double Phi, const double Psi,
|
||||
const sgMat4 UP)
|
||||
{
|
||||
SGfloat cosTheta = (SGfloat) cos(Theta);
|
||||
SGfloat sinTheta = (SGfloat) sin(Theta);
|
||||
SGfloat cosPhi = (SGfloat) cos(Phi);
|
||||
SGfloat sinPhi = (SGfloat) sin(Phi);
|
||||
SGfloat sinPsi = (SGfloat) sin(Psi) ;
|
||||
SGfloat cosPsi = (SGfloat) cos(Psi) ;
|
||||
|
||||
sgMat4 tmp;
|
||||
|
||||
tmp[0][0] = cosPhi * cosTheta;
|
||||
tmp[0][1] = sinPhi * cosPsi + cosPhi * -sinTheta * -sinPsi;
|
||||
tmp[0][2] = sinPhi * sinPsi + cosPhi * -sinTheta * cosPsi;
|
||||
|
||||
tmp[1][0] = -sinPhi * cosTheta;
|
||||
tmp[1][1] = cosPhi * cosPsi + -sinPhi * -sinTheta * -sinPsi;
|
||||
tmp[1][2] = cosPhi * sinPsi + -sinPhi * -sinTheta * cosPsi;
|
||||
|
||||
tmp[2][0] = sinTheta;
|
||||
tmp[2][1] = cosTheta * -sinPsi;
|
||||
tmp[2][2] = cosTheta * cosPsi;
|
||||
|
||||
float a = UP[0][0];
|
||||
float b = UP[1][0];
|
||||
float c = UP[2][0];
|
||||
dst[2][0] = a*tmp[0][0] + b*tmp[0][1] + c*tmp[0][2] ;
|
||||
dst[1][0] = a*tmp[1][0] + b*tmp[1][1] + c*tmp[1][2] ;
|
||||
dst[0][0] = -(a*tmp[2][0] + b*tmp[2][1] + c*tmp[2][2]) ;
|
||||
dst[3][0] = SG_ZERO ;
|
||||
|
||||
a = UP[0][1];
|
||||
b = UP[1][1];
|
||||
c = UP[2][1];
|
||||
dst[2][1] = a*tmp[0][0] + b*tmp[0][1] + c*tmp[0][2] ;
|
||||
dst[1][1] = a*tmp[1][0] + b*tmp[1][1] + c*tmp[1][2] ;
|
||||
dst[0][1] = -(a*tmp[2][0] + b*tmp[2][1] + c*tmp[2][2]) ;
|
||||
dst[3][1] = SG_ZERO ;
|
||||
|
||||
a = UP[0][2];
|
||||
c = UP[2][2];
|
||||
dst[2][2] = a*tmp[0][0] + c*tmp[0][2] ;
|
||||
dst[1][2] = a*tmp[1][0] + c*tmp[1][2] ;
|
||||
dst[0][2] = -(a*tmp[2][0] + c*tmp[2][2]) ;
|
||||
dst[3][2] = SG_ZERO ;
|
||||
|
||||
dst[2][3] = SG_ZERO ;
|
||||
dst[1][3] = SG_ZERO ;
|
||||
dst[0][3] = SG_ZERO ;
|
||||
dst[3][3] = SG_ONE ;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of SGLocation.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Constructor
|
||||
SGLocation::SGLocation( void ):
|
||||
_orientation_dirty(true),
|
||||
_position_dirty(true),
|
||||
_lon_deg(-1000),
|
||||
_lat_deg(0),
|
||||
_alt_ft(0),
|
||||
_roll_deg(0),
|
||||
_pitch_deg(0),
|
||||
_heading_deg(0),
|
||||
_cur_elev_m(0)
|
||||
{
|
||||
sgdZeroVec3(_absolute_view_pos);
|
||||
sgMakeRotMat4( UP, 0.0, 0.0, 0.0 );
|
||||
sgMakeRotMat4( TRANS, 0.0, 0.0, 0.0 );
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
SGLocation::~SGLocation( void ) {
|
||||
}
|
||||
|
||||
void
|
||||
SGLocation::setPosition (double lon_deg, double lat_deg, double alt_ft)
|
||||
{
|
||||
_position_dirty = true;
|
||||
_lon_deg = lon_deg;
|
||||
_lat_deg = lat_deg;
|
||||
_alt_ft = alt_ft;
|
||||
}
|
||||
|
||||
void
|
||||
SGLocation::setOrientation (double roll_deg, double pitch_deg, double heading_deg)
|
||||
{
|
||||
_orientation_dirty = true;
|
||||
_roll_deg = roll_deg;
|
||||
_pitch_deg = pitch_deg;
|
||||
_heading_deg = heading_deg;
|
||||
}
|
||||
|
||||
double *
|
||||
SGLocation::get_absolute_view_pos()
|
||||
{
|
||||
recalcAbsolutePosition();
|
||||
return _absolute_view_pos;
|
||||
}
|
||||
|
||||
float *
|
||||
SGLocation::get_view_pos( const Point3D& scenery_center )
|
||||
{
|
||||
recalcAbsolutePosition();
|
||||
for (int i = 0; i < 3; i++)
|
||||
_relative_view_pos[i] = _absolute_view_pos[i] - scenery_center[i];
|
||||
return _relative_view_pos;
|
||||
}
|
||||
|
||||
void
|
||||
SGLocation::recalcOrientation() const
|
||||
{
|
||||
if (_orientation_dirty) {
|
||||
// Make sure UP matrix is up-to-date.
|
||||
recalcAbsolutePosition();
|
||||
|
||||
// Create local matrix with current geodetic position. Converting
|
||||
// the orientation (pitch/roll/heading) to vectors.
|
||||
MakeTRANS( TRANS, _pitch_deg * SG_DEGREES_TO_RADIANS,
|
||||
_roll_deg * SG_DEGREES_TO_RADIANS,
|
||||
-_heading_deg * SG_DEGREES_TO_RADIANS,
|
||||
UP );
|
||||
_orientation_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update values derived from the longitude, latitude and altitude parameters
|
||||
* of this instance. This encompasses absolute position in cartesian
|
||||
* coordinates, the local up, east and south vectors and the UP Matrix.
|
||||
*/
|
||||
void
|
||||
SGLocation::recalcAbsolutePosition() const
|
||||
{
|
||||
if (_position_dirty) {
|
||||
double lat = _lat_deg * SGD_DEGREES_TO_RADIANS;
|
||||
double lon = _lon_deg * SGD_DEGREES_TO_RADIANS;
|
||||
double alt = _alt_ft * SG_FEET_TO_METER;
|
||||
|
||||
sgGeodToCart(lat, lon, alt, _absolute_view_pos);
|
||||
|
||||
// Make the world up rotation matrix for eye positioin...
|
||||
sgMakeRotMat4( UP, _lon_deg, 0.0, -_lat_deg );
|
||||
|
||||
// get the world up radial vector from planet center for output
|
||||
sgSetVec3( _world_up, UP[0][0], UP[0][1], UP[0][2] );
|
||||
|
||||
// Calculate the surface east and south vectors using the (normalized)
|
||||
// partial derivatives of the up vector Could also be fetched and
|
||||
// normalized from the UP rotation matrix, but I doubt this would
|
||||
// be more efficient.
|
||||
float sin_lon = sin(_lon_deg * SGD_DEGREES_TO_RADIANS);
|
||||
float sin_lat = sin(_lat_deg * SGD_DEGREES_TO_RADIANS);
|
||||
float cos_lon = cos(_lon_deg * SGD_DEGREES_TO_RADIANS);
|
||||
float cos_lat = cos(_lat_deg * SGD_DEGREES_TO_RADIANS);
|
||||
|
||||
_surface_south[0] = (sin_lat*cos_lon);
|
||||
_surface_south[1] = (sin_lat*sin_lon);
|
||||
_surface_south[2] = - cos_lat;
|
||||
|
||||
_surface_east[0] = -sin_lon;
|
||||
_surface_east[1] = cos_lon;
|
||||
_surface_east[2] = 0.f;
|
||||
|
||||
_position_dirty = false;
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
// location.hxx -- class for determining model location in the flightgear world.
|
||||
//
|
||||
// Written by Jim Wilson, David Megginson, started April 2002.
|
||||
//
|
||||
// Copyright (C) 2002 Jim Wilson, David Megginson
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_LOCATION_HXX
|
||||
#define _SG_LOCATION_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
|
||||
#include <plib/sg.h> // plib include
|
||||
|
||||
|
||||
// Define a structure containing view information
|
||||
class SGLocation
|
||||
{
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
SGLocation( void );
|
||||
|
||||
// Destructor
|
||||
virtual ~SGLocation( void );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Part 2: user settings.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Geodetic position of model...
|
||||
virtual double getLongitude_deg () const { return _lon_deg; }
|
||||
virtual double getLatitude_deg () const { return _lat_deg; }
|
||||
virtual double getAltitudeASL_ft () const { return _alt_ft; }
|
||||
virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
|
||||
|
||||
|
||||
// Reference orientation rotations...
|
||||
// These are rotations that represent the plane attitude effect on
|
||||
// the view (in Pilot view). IE The view frustrum rotates as the plane
|
||||
// turns, pitches, and rolls.
|
||||
// In model view (lookat/chaseview) these end up changing the angle that
|
||||
// the eye is looking at the ojbect (ie the model).
|
||||
// FIXME: the FGModel class should have its own version of these so that
|
||||
// it can generate it's own model rotations.
|
||||
virtual double getRoll_deg () const { return _roll_deg; }
|
||||
virtual double getPitch_deg () const {return _pitch_deg; }
|
||||
virtual double getHeading_deg () const {return _heading_deg; }
|
||||
virtual void setOrientation (double roll_deg, double pitch_deg, double heading_deg);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Part 3: output vectors and matrices in FlightGear coordinates.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Vectors and positions...
|
||||
|
||||
//! Get the absolute view position in fgfs coordinates.
|
||||
virtual double * get_absolute_view_pos( );
|
||||
|
||||
//! Return the position relative to the given scenery center.
|
||||
virtual float * get_view_pos( const Point3D& scenery_center );
|
||||
float * get_view_pos( const SGVec3d& sc )
|
||||
{ return get_view_pos(Point3D(sc[0], sc[1], sc[2])); }
|
||||
|
||||
// Get world up vector
|
||||
virtual float *get_world_up()
|
||||
{ recalcAbsolutePosition(); return _world_up; }
|
||||
|
||||
// Get surface east vector
|
||||
virtual float *get_surface_east()
|
||||
{ recalcAbsolutePosition(); return _surface_east; }
|
||||
|
||||
// Get surface south vector
|
||||
virtual float *get_surface_south()
|
||||
{ recalcAbsolutePosition(); return _surface_south; }
|
||||
|
||||
// Elevation of ground under location (based on scenery output)...
|
||||
void set_cur_elev_m ( double elev ) { _cur_elev_m = elev; }
|
||||
inline double get_cur_elev_m () { return _cur_elev_m; }
|
||||
|
||||
// Matrices...
|
||||
virtual const sgVec4 *getTransformMatrix() {
|
||||
recalcOrientation();
|
||||
return TRANS;
|
||||
}
|
||||
virtual const sgVec4 *getCachedTransformMatrix() { return TRANS; }
|
||||
|
||||
virtual const sgVec4 *getUpMatrix(const Point3D& scenery_center) {
|
||||
recalcAbsolutePosition();
|
||||
return UP;
|
||||
}
|
||||
const sgVec4 *getUpMatrix( const SGVec3d& sc )
|
||||
{ return getUpMatrix(Point3D(sc[0], sc[1], sc[2])); }
|
||||
|
||||
virtual const sgVec4 *getCachedUpMatrix() { return UP; }
|
||||
|
||||
private:
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// private data //
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
// flag forcing a recalc of derived view parameters
|
||||
mutable bool _orientation_dirty, _position_dirty;
|
||||
|
||||
mutable sgdVec3 _absolute_view_pos;
|
||||
mutable sgVec3 _relative_view_pos;
|
||||
|
||||
double _lon_deg;
|
||||
double _lat_deg;
|
||||
double _alt_ft;
|
||||
|
||||
double _roll_deg;
|
||||
double _pitch_deg;
|
||||
double _heading_deg;
|
||||
|
||||
// elevation of ground under this location...
|
||||
double _cur_elev_m;
|
||||
|
||||
// surface vector heading south
|
||||
mutable sgVec3 _surface_south;
|
||||
|
||||
// surface vector heading east (used to unambiguously align sky
|
||||
// with sun)
|
||||
mutable sgVec3 _surface_east;
|
||||
|
||||
// world up vector (normal to the plane tangent to the earth's
|
||||
// surface at the spot we are directly above)
|
||||
mutable sgVec3 _world_up;
|
||||
|
||||
// sg versions of our friendly matrices
|
||||
mutable sgMat4 TRANS, UP;
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// private functions //
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
void recalcOrientation() const;
|
||||
void recalcAbsolutePosition() const;
|
||||
};
|
||||
|
||||
|
||||
#endif // _SG_LOCATION_HXX
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include <simgear/scene/util/SGSceneUserData.hxx>
|
||||
|
||||
#include "location.hxx"
|
||||
#include "placementtrans.hxx"
|
||||
|
||||
#include "placement.hxx"
|
||||
@@ -28,14 +27,12 @@ SGModelPlacement::SGModelPlacement () :
|
||||
_pitch_deg(0),
|
||||
_heading_deg(0),
|
||||
_selector(new osg::Switch),
|
||||
_transform(new SGPlacementTransform),
|
||||
_location(new SGLocation)
|
||||
_transform(new SGPlacementTransform)
|
||||
{
|
||||
}
|
||||
|
||||
SGModelPlacement::~SGModelPlacement ()
|
||||
{
|
||||
delete _location;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -51,18 +48,16 @@ SGModelPlacement::init( osg::Node * model )
|
||||
void
|
||||
SGModelPlacement::update()
|
||||
{
|
||||
_location->setPosition( _position.getLongitudeDeg(),
|
||||
_position.getLatitudeDeg(),
|
||||
_position.getElevationFt() );
|
||||
_location->setOrientation( _roll_deg, _pitch_deg, _heading_deg );
|
||||
// The cartesian position
|
||||
SGVec3d position = SGVec3d::fromGeod(_position);
|
||||
|
||||
const sgVec4 *t = _location->getTransformMatrix();
|
||||
SGMatrixd rotation;
|
||||
for (unsigned i = 0; i < 4; ++i)
|
||||
for (unsigned j = 0; j < 4; ++j)
|
||||
rotation(i, j) = t[j][i];
|
||||
SGVec3d pos(_location->get_absolute_view_pos());
|
||||
_transform->setTransform(pos, rotation);
|
||||
// The orientation, composed from the horizontal local orientation and the
|
||||
// orientation wrt the horizontal local frame
|
||||
SGQuatd orient = SGQuatd::fromLonLat(_position);
|
||||
orient *= SGQuatd::fromAngleAxisDeg(180, SGVec3d(0, 1, 0));
|
||||
orient *= SGQuatd::fromYawPitchRollDeg(-_heading_deg, _pitch_deg, -_roll_deg);
|
||||
SGMatrixd rotation(inverse(orient));
|
||||
_transform->setTransform(position, rotation);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
|
||||
#include "placementtrans.hxx"
|
||||
|
||||
// Don't pull in the headers, since we don't need them here.
|
||||
class SGLocation;
|
||||
|
||||
|
||||
// Has anyone done anything *really* stupid, like making min and max macros?
|
||||
#ifdef min
|
||||
#undef min
|
||||
@@ -52,8 +48,6 @@ public:
|
||||
|
||||
virtual osg::Node* getSceneGraph () { return _selector.get(); }
|
||||
|
||||
virtual SGLocation * getSGLocation () { return _location; }
|
||||
|
||||
virtual bool getVisible () const;
|
||||
virtual void setVisible (bool visible);
|
||||
|
||||
@@ -94,9 +88,6 @@ private:
|
||||
|
||||
osg::ref_ptr<osg::Switch> _selector;
|
||||
osg::ref_ptr<SGPlacementTransform> _transform;
|
||||
|
||||
// Location
|
||||
SGLocation * _location;
|
||||
};
|
||||
|
||||
#endif // _SG_PLACEMENT_HXX
|
||||
|
||||
Reference in New Issue
Block a user