3 * Copyright (C) 2006-2007 Mathias Froehlich
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 # include <simgear_config.h>
26 #include <osgDB/Registry>
27 #include <osgDB/Input>
28 #include <osgDB/Output>
30 #include <simgear/scene/util/OsgMath.hxx>
32 #include "SGTranslateTransform.hxx"
34 SGTranslateTransform::SGTranslateTransform() :
38 setReferenceFrame(RELATIVE_RF);
41 SGTranslateTransform::SGTranslateTransform(const SGTranslateTransform& trans,
42 const osg::CopyOp& copyop) :
43 osg::Transform(trans, copyop),
50 SGTranslateTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
51 osg::NodeVisitor* nv) const
53 if (_referenceFrame == RELATIVE_RF) {
54 matrix.preMultTranslate(toOsg(_value*_axis));
56 matrix.setTrans(toOsg(_value*_axis));
62 SGTranslateTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,
63 osg::NodeVisitor* nv) const
65 if (_referenceFrame == RELATIVE_RF) {
66 matrix.postMultTranslate(toOsg(-_value*_axis));
68 matrix.setTrans(toOsg(-_value*_axis));
74 SGTranslateTransform::computeBound() const
76 osg::BoundingSphere bs = osg::Group::computeBound();
77 bs._center += toOsg(_axis)*_value;
83 bool TranslateTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
85 SGTranslateTransform& trans = static_cast<SGTranslateTransform&>(obj);
87 if (fr[0].matchWord("axis")) {
90 if (fr.readSequence(axis))
94 trans.setAxis(toSG(axis));
96 if (fr[0].matchWord("value")) {
99 if (fr[0].getFloat(value))
103 trans.setValue(value);
108 bool TranslateTransform_writeLocalData(const osg::Object& obj,
111 const SGTranslateTransform& trans
112 = static_cast<const SGTranslateTransform&>(obj);
113 const SGVec3d& axis = trans.getAxis();
114 double value = trans.getValue();
116 fw.indent() << "axis ";
117 for (int i = 0; i < 3; i++)
118 fw << axis(i) << " ";
120 fw.indent() << "value " << value << std::endl;
126 osgDB::RegisterDotOsgWrapperProxy g_SGTranslateTransformProxy
128 new SGTranslateTransform,
129 "SGTranslateTransform",
130 "Object Node Transform SGTranslateTransform Group",
131 &TranslateTransform_readLocalData,
132 &TranslateTransform_writeLocalData