#include <simgear/compiler.h>
-#include <string.h> // for strcmp()
+#include <simgear/scene/util/SGSceneUserData.hxx>
-#include <plib/sg.h>
-#include <plib/ssg.h>
-#include <plib/ul.h>
-
-#include "location.hxx"
#include "placementtrans.hxx"
#include "placement.hxx"
// 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 SGPlacementTransform)
{
}
SGModelPlacement::~SGModelPlacement ()
{
- delete _location;
}
void
-SGModelPlacement::init( ssgBranch * model )
+SGModelPlacement::init( osg::Node * model )
{
if (model != 0) {
- _position->addKid(model);
+ _transform->addChild(model);
}
- _selector->addKid(_position);
- _selector->clrTraversalMaskBits(SSGTRAV_HOT);
+ _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);
- sgMat4 rotation;
- sgCopyMat4( rotation, _location->getTransformMatrix() );
- _position->setTransform(_location->get_absolute_view_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
SGModelPlacement::getVisible () const
{
- return (_selector->getSelect() != 0);
+ return _selector->getValue(0);
}
void
SGModelPlacement::setVisible (bool visible)
{
- _selector->select(visible);
+ _selector->setValue(0, 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
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(_transform);
+ SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity();
+ SGQuatd orientation = SGQuatd::fromAngleAxisDeg(180, SGVec3d(0, 1, 0));
+ vel->linear = orientation.backTransform(linear);
+}
+
+void
+SGModelPlacement::setBodyAngularVelocity(const SGVec3d& angular)
+{
+ SGSceneUserData* userData;
+ userData = SGSceneUserData::getOrCreateSceneUserData(_transform);
+ SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity();
+ SGQuatd orientation = SGQuatd::fromAngleAxisDeg(180, SGVec3d(0, 1, 0));
+ vel->angular = orientation.backTransform(angular);
+}
+
// end of model.cxx