# include <simgear_config.h>
#endif
-#include "SGTranslateTransform.hxx"
+#include <osgDB/Registry>
+#include <osgDB/Input>
+#include <osgDB/Output>
-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),
setReferenceFrame(RELATIVE_RF);
}
+SGTranslateTransform::SGTranslateTransform(const SGTranslateTransform& trans,
+ const osg::CopyOp& copyop) :
+ osg::Transform(trans, copyop),
+ _axis(trans._axis),
+ _value(trans._value)
+{
+}
+
bool
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;
}
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;
}
SGTranslateTransform::computeBound() const
{
osg::BoundingSphere bs = osg::Group::computeBound();
- bs._center += _axis.osg()*_value;
+ bs._center += toOsg(_axis)*_value;
return bs;
}
+
+namespace {
+
+bool TranslateTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
+{
+ SGTranslateTransform& trans = static_cast<SGTranslateTransform&>(obj);
+
+ if (fr[0].matchWord("axis")) {
+ ++fr;
+ osg::Vec3d axis;
+ if (fr.readSequence(axis))
+ fr += 3;
+ else
+ return false;
+ trans.setAxis(toSG(axis));
+ }
+ if (fr[0].matchWord("value")) {
+ ++fr;
+ double value;
+ if (fr[0].getFloat(value))
+ ++fr;
+ else
+ return false;
+ trans.setValue(value);
+ }
+ return true;
+}
+
+bool TranslateTransform_writeLocalData(const osg::Object& obj,
+ osgDB::Output& fw)
+{
+ const SGTranslateTransform& trans
+ = static_cast<const SGTranslateTransform&>(obj);
+ const SGVec3d& axis = trans.getAxis();
+ double value = trans.getValue();
+
+ fw.indent() << "axis ";
+ for (int i = 0; i < 3; i++)
+ fw << axis(i) << " ";
+ fw << std::endl;
+ fw.indent() << "value " << value << std::endl;
+ return true;
+}
+
+}
+
+osgDB::RegisterDotOsgWrapperProxy g_SGTranslateTransformProxy
+(
+ new SGTranslateTransform,
+ "SGTranslateTransform",
+ "Object Node Transform SGTranslateTransform Group",
+ &TranslateTransform_readLocalData,
+ &TranslateTransform_writeLocalData
+);