Moved to SimGear from FlightGear/src/Model/

This commit is contained in:
curt
2003-05-09 19:37:10 +00:00
parent ef5fb7a98e
commit 835e86ad19
2 changed files with 255 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
// placement.cxx - manage the placment of a 3D model.
// Written by David Megginson, started 2002.
//
// This file is in the Public Domain, and comes with no warranty.
#include <simgear/compiler.h>
#include <string.h> // for strcmp()
#include <vector>
#include <plib/sg.h>
#include <plib/ssg.h>
#include <plib/ul.h>
#include <simgear/scene/model/location.hxx>
#include "placement.hxx"
SG_USING_STD(vector);
////////////////////////////////////////////////////////////////////////
// Implementation of FGModelPlacement.
////////////////////////////////////////////////////////////////////////
FGModelPlacement::FGModelPlacement ()
: _lon_deg(0),
_lat_deg(0),
_elev_ft(0),
_roll_deg(0),
_pitch_deg(0),
_heading_deg(0),
_selector(new ssgSelector),
_position(new ssgTransform),
_location(new FGLocation)
{
}
FGModelPlacement::~FGModelPlacement ()
{
}
void
FGModelPlacement::init( ssgBranch * model )
{
if (model != 0) {
_position->addKid(model);
}
_selector->addKid(_position);
_selector->clrTraversalMaskBits(SSGTRAV_HOT);
}
void
FGModelPlacement::update( const Point3D scenery_center )
{
_location->setPosition( _lon_deg, _lat_deg, _elev_ft );
_location->setOrientation( _roll_deg, _pitch_deg, _heading_deg );
sgCopyMat4( POS, _location->getTransformMatrix(scenery_center) );
sgVec3 trans;
sgCopyVec3(trans, _location->get_view_pos());
for(int i = 0; i < 4; i++) {
float tmp = POS[i][3];
for( int j=0; j<3; j++ ) {
POS[i][j] += (tmp * trans[j]);
}
}
_position->setTransform(POS);
}
bool
FGModelPlacement::getVisible () const
{
return (_selector->getSelect() != 0);
}
void
FGModelPlacement::setVisible (bool visible)
{
_selector->select(visible);
}
void
FGModelPlacement::setLongitudeDeg (double lon_deg)
{
_lon_deg = lon_deg;
}
void
FGModelPlacement::setLatitudeDeg (double lat_deg)
{
_lat_deg = lat_deg;
}
void
FGModelPlacement::setElevationFt (double elev_ft)
{
_elev_ft = elev_ft;
}
void
FGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft)
{
_lon_deg = lon_deg;
_lat_deg = lat_deg;
_elev_ft = elev_ft;
}
void
FGModelPlacement::setRollDeg (double roll_deg)
{
_roll_deg = roll_deg;
}
void
FGModelPlacement::setPitchDeg (double pitch_deg)
{
_pitch_deg = pitch_deg;
}
void
FGModelPlacement::setHeadingDeg (double heading_deg)
{
_heading_deg = heading_deg;
}
void
FGModelPlacement::setOrientation (double roll_deg, double pitch_deg,
double heading_deg)
{
_roll_deg = roll_deg;
_pitch_deg = pitch_deg;
_heading_deg = heading_deg;
}
// end of model.cxx

View File

@@ -0,0 +1,115 @@
// placement.hxx - manage the placment of a 3D model.
// Written by David Megginson, started 2002.
//
// This file is in the Public Domain, and comes with no warranty.
#ifndef _SG_PLACEMENT_HXX
#define _SG_PLACEMENT_HXX 1
#ifndef __cplusplus
# error This library requires C++
#endif
#include <vector>
SG_USING_STD(vector);
#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/math/point3d.hxx>
#include <simgear/props/props.hxx>
// Don't pull in the headers, since we don't need them here.
class FGLocation;
// Has anyone done anything *really* stupid, like making min and max macros?
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
////////////////////////////////////////////////////////////////////////
// Model placement.
////////////////////////////////////////////////////////////////////////
/**
* A wrapper for a model with a definite placement.
*/
class FGModelPlacement
{
public:
FGModelPlacement ();
virtual ~FGModelPlacement ();
virtual void FGModelPlacement::init( ssgBranch * model );
/* virtual void init( const string &fg_root,
const string &path,
SGPropertyNode *prop_root,
double sim_time_sec, int dummy ); */
virtual void update( const Point3D scenery_center );
virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; }
virtual FGLocation * getFGLocation () { return _location; }
virtual bool getVisible () const;
virtual void setVisible (bool visible);
virtual double getLongitudeDeg () const { return _lon_deg; }
virtual double getLatitudeDeg () const { return _lat_deg; }
virtual double getElevationFt () const { return _elev_ft; }
virtual void setLongitudeDeg (double lon_deg);
virtual void setLatitudeDeg (double lat_deg);
virtual void setElevationFt (double elev_ft);
virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
virtual double getRollDeg () const { return _roll_deg; }
virtual double getPitchDeg () const { return _pitch_deg; }
virtual double getHeadingDeg () const { return _heading_deg; }
virtual void setRollDeg (double roll_deg);
virtual void setPitchDeg (double pitch_deg);
virtual void setHeadingDeg (double heading_deg);
virtual void setOrientation (double roll_deg, double pitch_deg,
double heading_deg);
// Addition by Diarmuid Tyson for Multiplayer Support
// Allows multiplayer to get players position transform
virtual const sgVec4 *get_POS() { return POS; }
private:
// Geodetic position
double _lon_deg;
double _lat_deg;
double _elev_ft;
// Orientation
double _roll_deg;
double _pitch_deg;
double _heading_deg;
ssgSelector * _selector;
ssgTransform * _position;
// Location
FGLocation * _location;
// Addition by Diarmuid Tyson for Multiplayer Support
// Moved from update method
// POS for transformation Matrix
sgMat4 POS;
};
#endif // _SG_PLACEMENT_HXX