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 "SGTranslateTransform.hxx"
33 set_translation (osg::Matrix &matrix, double position_m, const SGVec3d &axis)
35 SGVec3d xyz = axis * position_m;
36 matrix.makeIdentity();
37 matrix(3, 0) = xyz[0];
38 matrix(3, 1) = xyz[1];
39 matrix(3, 2) = xyz[2];
42 SGTranslateTransform::SGTranslateTransform() :
46 setReferenceFrame(RELATIVE_RF);
49 SGTranslateTransform::SGTranslateTransform(const SGTranslateTransform& trans,
50 const osg::CopyOp& copyop) :
51 osg::Transform(trans, copyop),
58 SGTranslateTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
59 osg::NodeVisitor* nv) const
61 if (_referenceFrame == RELATIVE_RF) {
63 set_translation(tmp, _value, _axis);
67 set_translation(tmp, _value, _axis);
74 SGTranslateTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,
75 osg::NodeVisitor* nv) const
77 if (_referenceFrame == RELATIVE_RF) {
79 set_translation(tmp, -_value, _axis);
83 set_translation(tmp, -_value, _axis);
90 SGTranslateTransform::computeBound() const
92 osg::BoundingSphere bs = osg::Group::computeBound();
93 bs._center += _axis.osg()*_value;
99 bool TranslateTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
101 SGTranslateTransform& trans = static_cast<SGTranslateTransform&>(obj);
103 if (fr[0].matchWord("axis")) {
106 if (fr.readSequence(axis.osg()))
112 if (fr[0].matchWord("value")) {
115 if (fr[0].getFloat(value))
119 trans.setValue(value);
124 bool TranslateTransform_writeLocalData(const osg::Object& obj,
127 const SGTranslateTransform& trans
128 = static_cast<const SGTranslateTransform&>(obj);
129 const SGVec3d& axis = trans.getAxis();
130 double value = trans.getValue();
132 fw.indent() << "axis ";
133 for (int i = 0; i < 3; i++)
134 fw << axis(i) << " ";
136 fw.indent() << "value " << value << std::endl;
142 osgDB::RegisterDotOsgWrapperProxy g_SGTranslateTransformProxy
144 new SGTranslateTransform,
145 "SGTranslateTransform",
146 "Object Node Transform SGTranslateTransform Group",
147 &TranslateTransform_readLocalData,
148 &TranslateTransform_writeLocalData