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"
32 SGTranslateTransform::SGTranslateTransform() :
36 setReferenceFrame(RELATIVE_RF);
39 SGTranslateTransform::SGTranslateTransform(const SGTranslateTransform& trans,
40 const osg::CopyOp& copyop) :
41 osg::Transform(trans, copyop),
48 SGTranslateTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
49 osg::NodeVisitor* nv) const
51 if (_referenceFrame == RELATIVE_RF) {
52 matrix.preMultTranslate(toOsg(_value*_axis));
54 matrix.setTrans(toOsg(_value*_axis));
60 SGTranslateTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,
61 osg::NodeVisitor* nv) const
63 if (_referenceFrame == RELATIVE_RF) {
64 matrix.postMultTranslate(toOsg(-_value*_axis));
66 matrix.setTrans(toOsg(-_value*_axis));
72 SGTranslateTransform::computeBound() const
74 osg::BoundingSphere bs = osg::Group::computeBound();
75 bs._center += toOsg(_axis)*_value;
81 bool TranslateTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
83 SGTranslateTransform& trans = static_cast<SGTranslateTransform&>(obj);
85 if (fr[0].matchWord("axis")) {
88 if (fr.readSequence(axis))
92 trans.setAxis(toSG(axis));
94 if (fr[0].matchWord("value")) {
97 if (fr[0].getFloat(value))
101 trans.setValue(value);
106 bool TranslateTransform_writeLocalData(const osg::Object& obj,
109 const SGTranslateTransform& trans
110 = static_cast<const SGTranslateTransform&>(obj);
111 const SGVec3d& axis = trans.getAxis();
112 double value = trans.getValue();
114 fw.indent() << "axis ";
115 for (int i = 0; i < 3; i++)
116 fw << axis(i) << " ";
118 fw.indent() << "value " << value << std::endl;
124 osgDB::RegisterDotOsgWrapperProxy g_SGTranslateTransformProxy
126 new SGTranslateTransform,
127 "SGTranslateTransform",
128 "Object Node Transform SGTranslateTransform Group",
129 &TranslateTransform_readLocalData,
130 &TranslateTransform_writeLocalData