#include <simgear/compiler.h>
-#include <string.h> // for strcmp()
+#include <simgear/scene/util/SGSceneUserData.hxx>
-#include <vector>
-
-#include <plib/sg.h>
-#include <plib/ssg.h>
-#include <plib/ul.h>
-
-#include <simgear/scene/model/location.hxx>
+#include "location.hxx"
+#include "placementtrans.hxx"
#include "placement.hxx"
-SG_USING_STD(vector);
-
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGModelPlacement.
+// Implementation of SGModelPlacement.
////////////////////////////////////////////////////////////////////////
-FGModelPlacement::FGModelPlacement ()
+SGModelPlacement::SGModelPlacement ()
: _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)
+ _selector(new osg::Switch),
+ _position(new SGPlacementTransform),
+ _location(new SGLocation)
{
}
-FGModelPlacement::~FGModelPlacement ()
+SGModelPlacement::~SGModelPlacement ()
{
+ delete _location;
}
void
-FGModelPlacement::init( ssgBranch * model )
+SGModelPlacement::init( osg::Node * model )
{
if (model != 0) {
- _position->addKid(model);
+ _position->addChild(model);
}
- _selector->addKid(_position);
- _selector->clrTraversalMaskBits(SSGTRAV_HOT);
+ _selector->addChild(_position.get());
+ _selector->setValue(0, 1);
}
void
-FGModelPlacement::update( const Point3D scenery_center )
+SGModelPlacement::update()
{
_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);
+ 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);
}
bool
-FGModelPlacement::getVisible () const
+SGModelPlacement::getVisible () const
{
- return (_selector->getSelect() != 0);
+ return _selector->getValue(0);
}
void
-FGModelPlacement::setVisible (bool visible)
+SGModelPlacement::setVisible (bool visible)
{
- _selector->select(visible);
+ _selector->setValue(0, visible);
}
void
-FGModelPlacement::setLongitudeDeg (double lon_deg)
+SGModelPlacement::setLongitudeDeg (double lon_deg)
{
_lon_deg = lon_deg;
}
void
-FGModelPlacement::setLatitudeDeg (double lat_deg)
+SGModelPlacement::setLatitudeDeg (double lat_deg)
{
_lat_deg = lat_deg;
}
void
-FGModelPlacement::setElevationFt (double elev_ft)
+SGModelPlacement::setElevationFt (double elev_ft)
{
_elev_ft = elev_ft;
}
void
-FGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft)
+SGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft)
{
_lon_deg = lon_deg;
_lat_deg = lat_deg;
}
void
-FGModelPlacement::setRollDeg (double roll_deg)
+SGModelPlacement::setPosition(const SGGeod& position)
+{
+ _lon_deg = position.getLongitudeDeg();
+ _lat_deg = position.getLatitudeDeg();
+ _elev_ft = position.getElevationFt();
+}
+
+void
+SGModelPlacement::setRollDeg (double roll_deg)
{
_roll_deg = roll_deg;
}
void
-FGModelPlacement::setPitchDeg (double pitch_deg)
+SGModelPlacement::setPitchDeg (double pitch_deg)
{
_pitch_deg = pitch_deg;
}
void
-FGModelPlacement::setHeadingDeg (double heading_deg)
+SGModelPlacement::setHeadingDeg (double heading_deg)
{
_heading_deg = heading_deg;
}
void
-FGModelPlacement::setOrientation (double roll_deg, double pitch_deg,
+SGModelPlacement::setOrientation (double roll_deg, double pitch_deg,
double heading_deg)
{
_roll_deg = roll_deg;
_heading_deg = heading_deg;
}
+void
+SGModelPlacement::setOrientation (const SGQuatd& orientation)
+{
+ orientation.getEulerDeg(_heading_deg, _pitch_deg, _roll_deg);
+}
+
+void
+SGModelPlacement::setBodyLinearVelocity(const SGVec3d& linear)
+{
+ SGSceneUserData* userData;
+ userData = SGSceneUserData::getOrCreateSceneUserData(_position);
+ 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(_position);
+ SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity();
+ SGQuatd orientation = SGQuatd::fromAngleAxisDeg(180, SGVec3d(0, 1, 0));
+ vel->angular = orientation.backTransform(angular);
+}
+
// end of model.cxx