]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/SGScaleTransform.cxx
Merge branch 'jmt/waypt' into next
[simgear.git] / simgear / scene / model / SGScaleTransform.cxx
index f8d4ca3179b63e489951533a3c1742ec48850478..ab9d6215742674e8a9dfde02438927d36bd5b620 100644 (file)
  *
  */
 
-/* -*-c++-*-
- *
- * Copyright (C) 2006-2007 Mathias Froehlich 
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- */
-
 #ifdef HAVE_CONFIG_H
 #  include <simgear_config.h>
 #endif
 
+#include <osgDB/Registry>
+#include <osgDB/Input>
+#include <osgDB/Output>
+
 #include "SGScaleTransform.hxx"
 
 SGScaleTransform::SGScaleTransform() :
@@ -54,6 +37,15 @@ SGScaleTransform::SGScaleTransform() :
   setReferenceFrame(RELATIVE_RF);
 }
 
+SGScaleTransform::SGScaleTransform(const SGScaleTransform& scale,
+                                   const osg::CopyOp& copyop) :
+    osg::Transform(scale, copyop),
+    _center(scale._center),
+    _scaleFactor(scale._scaleFactor),
+    _boundScale(scale._boundScale)
+{
+}
+
 bool
 SGScaleTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
                                             osg::NodeVisitor* nv) const
@@ -107,3 +99,59 @@ SGScaleTransform::computeBound() const
   bs.radius() *= _boundScale;
   return bs;
 }
+
+namespace {
+
+bool ScaleTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
+{
+    SGScaleTransform& scale = static_cast<SGScaleTransform&>(obj);
+    if (fr[0].matchWord("center")) {
+        ++fr;
+        osg::Vec3d center;
+        if (fr.readSequence(center))
+            fr += 3;
+        else
+            return false;
+        scale.setCenter(toSG(center));
+    }
+    if (fr[0].matchWord("scaleFactor")) {
+        ++fr;
+        osg::Vec3d scaleFactor;
+        if (fr.readSequence(scaleFactor))
+            fr += 3;
+        else
+            return false;
+        scale.setScaleFactor(toSG(scaleFactor));
+    }
+    return true;
+}
+
+bool ScaleTransform_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
+{
+    const SGScaleTransform& scale = static_cast<const SGScaleTransform&>(obj);
+    const SGVec3d& center = scale.getCenter();
+    const SGVec3d& scaleFactor = scale.getScaleFactor();
+    int prec = fw.precision();
+    fw.precision(15);
+    fw.indent() << "center ";
+    for (int i = 0; i < 3; i++)
+        fw << center(i) << " ";
+    fw << std::endl;
+    fw.precision(prec);
+    fw.indent() << "scaleFactor ";
+    for (int i = 0; i < 3; i++)
+        fw << scaleFactor(i) << " ";
+    fw << std::endl;
+    return true;
+}
+
+}
+
+osgDB::RegisterDotOsgWrapperProxy g_ScaleTransformProxy
+(
+    new SGScaleTransform,
+    "SGScaleTransform",
+    "Object Node Transform SGScaleTransform Group",
+    &ScaleTransform_readLocalData,
+    &ScaleTransform_writeLocalData
+);