X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2Fplacement.cxx;h=cd38181e212c611cee2ab8fb53a9921f0f697ca2;hb=d04cf4d8978866eb80a1639b6d4ddfe387338c77;hp=37d715f4338ce48fdc183bdaf729135de4127c2a;hpb=fee8d0cf78fac0319ed2383af9f180f97e031754;p=simgear.git diff --git a/simgear/scene/model/placement.cxx b/simgear/scene/model/placement.cxx index 37d715f4..cd38181e 100644 --- a/simgear/scene/model/placement.cxx +++ b/simgear/scene/model/placement.cxx @@ -7,62 +7,56 @@ #include #endif -#include - -#include - -#include "location.hxx" -#include "placementtrans.hxx" - #include "placement.hxx" +#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 osg::Switch), - _position(new SGPlacementTransform), - _location(new SGLocation) + _transform(new osg::PositionAttitudeTransform) { } SGModelPlacement::~SGModelPlacement () { - delete _location; } void SGModelPlacement::init( osg::Node * model ) { if (model != 0) { - _position->addChild(model); + _transform->addChild(model); } - _selector->addChild(_position.get()); + _selector->addChild(_transform.get()); _selector->setValue(0, 1); } void SGModelPlacement::update() { - _location->setPosition( _lon_deg, _lat_deg, _elev_ft ); - _location->setOrientation( _roll_deg, _pitch_deg, _heading_deg ); + // The cartesian position + SGVec3d position = SGVec3d::fromGeod(_position); + _transform->setPosition(toOsg(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()); - _position->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::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)); } bool @@ -80,35 +74,31 @@ SGModelPlacement::setVisible (bool visible) void SGModelPlacement::setLongitudeDeg (double lon_deg) { - _lon_deg = lon_deg; + _position.setLongitudeDeg(lon_deg); } void SGModelPlacement::setLatitudeDeg (double lat_deg) { - _lat_deg = lat_deg; + _position.setLatitudeDeg(lat_deg); } void SGModelPlacement::setElevationFt (double elev_ft) { - _elev_ft = elev_ft; + _position.setElevationFt(elev_ft); } void SGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft) { - _lon_deg = lon_deg; - _lat_deg = lat_deg; - _elev_ft = elev_ft; + _position = SGGeod::fromDegFt(lon_deg, lat_deg, elev_ft); } void SGModelPlacement::setPosition(const SGGeod& position) { - _lon_deg = position.getLongitudeDeg(); - _lat_deg = position.getLatitudeDeg(); - _elev_ft = position.getElevationFt(); + _position = position; } void @@ -144,24 +134,31 @@ 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); + SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity(); + vel->referenceTime = referenceTime; +} + void SGModelPlacement::setBodyLinearVelocity(const SGVec3d& linear) { SGSceneUserData* userData; - userData = SGSceneUserData::getOrCreateSceneUserData(_position); + userData = SGSceneUserData::getOrCreateSceneUserData(_transform); SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity(); - SGQuatd orientation = SGQuatd::fromAngleAxisDeg(180, SGVec3d(0, 1, 0)); - vel->linear = orientation.backTransform(linear); + vel->linear = SGVec3d(-linear[0], linear[1], -linear[2]); } void SGModelPlacement::setBodyAngularVelocity(const SGVec3d& angular) { SGSceneUserData* userData; - userData = SGSceneUserData::getOrCreateSceneUserData(_position); + userData = SGSceneUserData::getOrCreateSceneUserData(_transform); SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity(); - SGQuatd orientation = SGQuatd::fromAngleAxisDeg(180, SGVec3d(0, 1, 0)); - vel->angular = orientation.backTransform(angular); + vel->angular = SGVec3d(-angular[0], angular[1], -angular[2]); } // end of model.cxx