]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/placement.cxx
Compile even if OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION is not set.
[simgear.git] / simgear / scene / model / placement.cxx
index e7d4d384eace32440b6b52f1a5f87ac24d54f880..852844921f5424ede40e8297cf8c54a5a74dd926 100644 (file)
@@ -7,15 +7,10 @@
 #include <simgear_config.h>
 #endif
 
-#include <simgear/compiler.h>
-
-#include <simgear/scene/util/SGSceneUserData.hxx>
-
-#include "location.hxx"
-#include "placementtrans.hxx"
-
 #include "placement.hxx"
 
+#include <simgear/compiler.h>
+#include <simgear/scene/util/SGSceneUserData.hxx>
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -28,14 +23,12 @@ SGModelPlacement::SGModelPlacement () :
     _pitch_deg(0),
     _heading_deg(0),
     _selector(new osg::Switch),
-    _transform(new SGPlacementTransform),
-    _location(new SGLocation)
+    _transform(new osg::PositionAttitudeTransform)
 {
 }
 
 SGModelPlacement::~SGModelPlacement ()
 {
-  delete _location;
 }
 
 void
@@ -51,18 +44,19 @@ SGModelPlacement::init( osg::Node * model )
 void
 SGModelPlacement::update()
 {
-  _location->setPosition( _position.getLongitudeDeg(),
-                          _position.getLatitudeDeg(),
-                          _position.getElevationFt() );
-  _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());
-  _transform->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
@@ -140,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.get());
+  SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity();
+  vel->referenceTime = referenceTime;
+}
+
 void
 SGModelPlacement::setBodyLinearVelocity(const SGVec3d& linear)
 {
   SGSceneUserData* userData;
-  userData = SGSceneUserData::getOrCreateSceneUserData(_transform);
+  userData = SGSceneUserData::getOrCreateSceneUserData(_transform.get());
   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(_transform);
+  userData = SGSceneUserData::getOrCreateSceneUserData(_transform.get());
   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