X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2Fplacement.cxx;h=c1a7d83badf1a4000dcad9e6df4f1b450949f1f4;hb=32a6bd78d8bf143f40922f1a0bc7a88ea7706a7d;hp=f5c483fc6d583c815dec812c6190e2f1856930aa;hpb=00ab198c9f06e61d3c64ea02d06e9ed9bfa9b13b;p=simgear.git diff --git a/simgear/scene/model/placement.cxx b/simgear/scene/model/placement.cxx index f5c483fc..c1a7d83b 100644 --- a/simgear/scene/model/placement.cxx +++ b/simgear/scene/model/placement.cxx @@ -7,36 +7,26 @@ #include #endif -#include - -#include // for strcmp() - -#include -#include -#include - -#include "location.hxx" -#include "placementtrans.hxx" - #include "placement.hxx" +#include +#include +#include //////////////////////////////////////////////////////////////////////// // Implementation of SGModelPlacement. //////////////////////////////////////////////////////////////////////// -SGModelPlacement::SGModelPlacement () - : _lon_deg(0), - _lat_deg(0), - _elev_ft(0), +SGModelPlacement::SGModelPlacement () : + _position(SGGeod::fromRad(0, 0)), _roll_deg(0), _pitch_deg(0), _heading_deg(0), - _selector(new ssgSelector), - _position(new ssgPlacementTransform), - _location(new SGLocation) + _selector(new osg::Switch), + _transform(new osg::PositionAttitudeTransform) { + _selector->addChild(_transform.get()); } SGModelPlacement::~SGModelPlacement () @@ -44,62 +34,64 @@ SGModelPlacement::~SGModelPlacement () } void -SGModelPlacement::init( ssgBranch * model ) +SGModelPlacement::init( osg::Node * model ) { + // remove previous models (in case of reinit) + _transform->removeChild(0, _transform->getNumChildren()); if (model != 0) { - _position->addKid(model); + _transform->addChild(model); } - _selector->addKid(_position); - _selector->clrTraversalMaskBits(SSGTRAV_HOT); + _selector->setValue(0, 1); } void -SGModelPlacement::update() -{ - _location->setPosition( _lon_deg, _lat_deg, _elev_ft ); - _location->setOrientation( _roll_deg, _pitch_deg, _heading_deg ); - - sgMat4 rotation; - sgCopyMat4( rotation, _location->getTransformMatrix() ); - _position->setTransform(_location->get_absolute_view_pos(), rotation); -} - -bool -SGModelPlacement::getVisible () const +SGModelPlacement::add( osg::Node* model ) { - return (_selector->getSelect() != 0); + if (model != 0) { + _transform->addChild(model); + } } -void -SGModelPlacement::setVisible (bool visible) +void SGModelPlacement::clear() { - _selector->select(visible); + _selector = NULL; + _transform = NULL; } void -SGModelPlacement::setLongitudeDeg (double lon_deg) +SGModelPlacement::update() { - _lon_deg = lon_deg; + // The cartesian position + SGVec3d position = SGVec3d::fromGeod(_position); + _transform->setPosition(toOsg(position)); + + // The orientation, composed from the horizontal local orientation and the + // orientation wrt the horizontal local frame + SGQuatd orient = SGQuatd::fromLonLat(_position); + orient *= SGQuatd::fromYawPitchRollDeg(_heading_deg, _pitch_deg, _roll_deg); + // Convert to the scenegraph orientation where we just rotate around + // the y axis 180 degrees. + orient *= SGQuatd::fromRealImag(0, SGVec3d(0, 1, 0)); + + _transform->setAttitude(toOsg(orient)); } -void -SGModelPlacement::setLatitudeDeg (double lat_deg) +bool +SGModelPlacement::getVisible () const { - _lat_deg = lat_deg; + return _selector->getValue(0); } void -SGModelPlacement::setElevationFt (double elev_ft) +SGModelPlacement::setVisible (bool visible) { - _elev_ft = elev_ft; + _selector->setValue(0, visible); } void -SGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft) +SGModelPlacement::setPosition(const SGGeod& position) { - _lon_deg = lon_deg; - _lat_deg = lat_deg; - _elev_ft = elev_ft; + _position = position; } void @@ -129,4 +121,37 @@ SGModelPlacement::setOrientation (double roll_deg, double pitch_deg, _heading_deg = heading_deg; } +void +SGModelPlacement::setOrientation (const SGQuatd& orientation) +{ + orientation.getEulerDeg(_heading_deg, _pitch_deg, _roll_deg); +} + +void +SGModelPlacement::setReferenceTime(const double& referenceTime) +{ + SGSceneUserData* userData; + userData = SGSceneUserData::getOrCreateSceneUserData(_transform.get()); + SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity(); + vel->referenceTime = referenceTime; +} + +void +SGModelPlacement::setBodyLinearVelocity(const SGVec3d& linear) +{ + SGSceneUserData* userData; + userData = SGSceneUserData::getOrCreateSceneUserData(_transform.get()); + SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity(); + vel->linear = SGVec3d(-linear[0], linear[1], -linear[2]); +} + +void +SGModelPlacement::setBodyAngularVelocity(const SGVec3d& angular) +{ + SGSceneUserData* userData; + userData = SGSceneUserData::getOrCreateSceneUserData(_transform.get()); + SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity(); + vel->angular = SGVec3d(-angular[0], angular[1], -angular[2]); +} + // end of model.cxx