]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/SGTranslateTransform.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / model / SGTranslateTransform.cxx
index e185618eb44c8683d52ae727cb3e78ecea2152e1..9f148b6449e33cfcf8ecadb488dfb8f2340c5d93 100644 (file)
 #include <osgDB/Input>
 #include <osgDB/Output>
 
-#include "SGTranslateTransform.hxx"
+#include <simgear/scene/util/OsgMath.hxx>
 
-static inline void
-set_translation (osg::Matrix &matrix, double position_m, const SGVec3d &axis)
-{
-  SGVec3d xyz = axis * position_m;
-  matrix.makeIdentity();
-  matrix(3, 0) = xyz[0];
-  matrix(3, 1) = xyz[1];
-  matrix(3, 2) = xyz[2];
-}
+#include "SGTranslateTransform.hxx"
 
 SGTranslateTransform::SGTranslateTransform() :
   _axis(0, 0, 0),
@@ -59,13 +51,9 @@ SGTranslateTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
                                                 osg::NodeVisitor* nv) const 
 {
   if (_referenceFrame == RELATIVE_RF) {
-    osg::Matrix tmp;
-    set_translation(tmp, _value, _axis);
-    matrix.preMult(tmp);
+    matrix.preMultTranslate(toOsg(_value*_axis));
   } else {
-    osg::Matrix tmp;
-    set_translation(tmp, _value, _axis);
-    matrix = tmp;
+    matrix.setTrans(toOsg(_value*_axis));
   }
   return true;
 }
@@ -75,13 +63,9 @@ SGTranslateTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,
                                                 osg::NodeVisitor* nv) const
 {
   if (_referenceFrame == RELATIVE_RF) {
-    osg::Matrix tmp;
-    set_translation(tmp, -_value, _axis);
-    matrix.postMult(tmp);
+    matrix.postMultTranslate(toOsg(-_value*_axis));
   } else {
-    osg::Matrix tmp;
-    set_translation(tmp, -_value, _axis);
-    matrix = tmp;
+    matrix.setTrans(toOsg(-_value*_axis));
   }
   return true;
 }
@@ -90,7 +74,7 @@ osg::BoundingSphere
 SGTranslateTransform::computeBound() const
 {
   osg::BoundingSphere bs = osg::Group::computeBound();
-  bs._center += _axis.osg()*_value;
+  bs._center += toOsg(_axis)*_value;
   return bs;
 }
 
@@ -102,12 +86,12 @@ bool TranslateTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
 
     if (fr[0].matchWord("axis")) {
         ++fr;
-        SGVec3d axis;
-        if (fr.readSequence(axis.osg()))
+        osg::Vec3d axis;
+        if (fr.readSequence(axis))
             fr += 3;
         else
             return false;
-        trans.setAxis(axis);
+        trans.setAxis(toSG(axis));
     }
     if (fr[0].matchWord("value")) {
         ++fr;