Update of /var/cvs/SimGear-0.3/source/simgear/scene/model
In directory baron:/tmp/cvs-serv17718/simgear/scene/model
Modified Files:
SGOffsetTransform.cxx SGOffsetTransform.hxx
SGRotateTransform.cxx SGRotateTransform.hxx
SGScaleTransform.cxx SGScaleTransform.hxx
SGTranslateTransform.cxx SGTranslateTransform.hxx
placementtrans.cxx placementtrans.hxx
Log Message:
Support for reading and writing nodes in .osg files, plus some new accessors.
Index: SGOffsetTransform.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGOffsetTransform.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGOffsetTransform.cxx 28 May 2007 05:00:29 -0000 1.1
--- SGOffsetTransform.cxx 22 Jul 2007 20:06:20 -0000 1.2
***************
*** 24,27 ****
--- 24,31 ----
#endif
+ #include <osgDB/Registry>
+ #include <osgDB/Input>
+ #include <osgDB/Output>
+
#include "SGOffsetTransform.hxx"
***************
*** 32,35 ****
--- 36,47 ----
}
+ SGOffsetTransform::SGOffsetTransform(const SGOffsetTransform& offset,
+ const osg::CopyOp& copyop) :
+ osg::Transform(offset, copyop),
+ _scaleFactor(offset._scaleFactor),
+ _rScaleFactor(offset._rScaleFactor)
+ {
+ }
+
bool
SGOffsetTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
***************
*** 67,68 ****
--- 79,116 ----
return true;
}
+
+ namespace {
+
+ bool OffsetTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
+ {
+ SGOffsetTransform& offset = static_cast<SGOffsetTransform&>(obj);
+ if (fr[0].matchWord("scaleFactor")) {
+ ++fr;
+ double scaleFactor;
+ if (fr[0].getFloat(scaleFactor))
+ ++fr;
+ else
+ return false;
+ offset.setScaleFactor(scaleFactor);
+ }
+ return true;
+ }
+
+ bool OffsetTransform_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
+ {
+ const SGOffsetTransform& offset
+ = static_cast<const SGOffsetTransform&>(obj);
+ fw.indent() << "scaleFactor " << offset.getScaleFactor() << std::endl;
+ return true;
+ }
+
+ }
+
+ osgDB::RegisterDotOsgWrapperProxy g_SGOffsetTransformProxy
+ (
+ new SGOffsetTransform,
+ "SGOffsetTransform",
+ "Object Node Transform SGOffsetTransform Group",
+ &OffsetTransform_readLocalData,
+ &OffsetTransform_writeLocalData
+ );
Index: SGOffsetTransform.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGOffsetTransform.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGOffsetTransform.hxx 28 May 2007 05:00:29 -0000 1.1
--- SGOffsetTransform.hxx 22 Jul 2007 20:06:21 -0000 1.2
***************
*** 27,35 ****
class SGOffsetTransform : public osg::Transform {
public:
! SGOffsetTransform(double scaleFactor);
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,
osg::NodeVisitor* nv) const;
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,
osg::NodeVisitor* nv) const;
private:
double _scaleFactor;
--- 27,49 ----
class SGOffsetTransform : public osg::Transform {
public:
! SGOffsetTransform(double scaleFactor = 1.0);
! SGOffsetTransform(const SGOffsetTransform&,
! const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
!
! META_Node(simgear, SGOffsetTransform);
!
! double getScaleFactor() const { return _scaleFactor; };
!
! void setScaleFactor(double scaleFactor)
! {
! _scaleFactor = scaleFactor;
! _rScaleFactor = 1.0 / scaleFactor;
! }
!
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,
osg::NodeVisitor* nv) const;
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,
osg::NodeVisitor* nv) const;
+
private:
double _scaleFactor;
Index: SGRotateTransform.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGRotateTransform.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGRotateTransform.cxx 28 May 2007 07:13:07 -0000 1.1
--- SGRotateTransform.cxx 22 Jul 2007 20:06:21 -0000 1.2
***************
*** 24,27 ****
--- 24,31 ----
#endif
+ #include <osgDB/Registry>
+ #include <osgDB/Input>
+ #include <osgDB/Output>
+
#include "SGRotateTransform.hxx"
***************
*** 76,79 ****
--- 80,92 ----
}
+ SGRotateTransform::SGRotateTransform(const SGRotateTransform& rot,
+ const osg::CopyOp& copyop) :
+ osg::Transform(rot, copyop),
+ _center(rot._center),
+ _axis(rot._axis),
+ _angleRad(rot._angleRad)
+ {
+ }
+
bool
SGRotateTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
***************
*** 121,122 ****
--- 134,205 ----
}
+ // Functions to read/write SGRotateTransform from/to a .osg file.
+
+ namespace {
+
+ bool RotateTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
+ {
+ SGRotateTransform& rot = static_cast<SGRotateTransform&>(obj);
+ if (fr[0].matchWord("center")) {
+ ++fr;
+ SGVec3d center;
+ if (fr.readSequence(center.osg()))
+ fr += 3;
+ else
+ return false;
+ rot.setCenter(center);
+ }
+ if (fr[0].matchWord("axis")) {
+ ++fr;
+ SGVec3d axis;
+ if (fr.readSequence(axis.osg()))
+ fr += 3;
+ else
+ return false;
+ rot.setCenter(axis);
+ }
+ if (fr[0].matchWord("angle")) {
+ ++fr;
+ double angle;
+ if (fr[0].getFloat(angle))
+ ++fr;
+ else
+ return false;
+ rot.setAngleRad(angle);
+ }
+ return true;
+ }
+
+ bool RotateTransform_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
+ {
+ const SGRotateTransform& rot = static_cast<const SGRotateTransform&>(obj);
+ const SGVec3d& center = rot.getCenter();
+ const SGVec3d& axis = rot.getAxis();
+ const double angle = rot.getAngleRad();
+ 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() << "axis ";
+ for (int i = 0; i < 3; i++) {
+ fw << axis(i) << " ";
+ }
+ fw << std::endl;
+ fw.indent() << "angle ";
+ fw << angle << std::endl;
+ return true;
+ }
+ }
+
+ osgDB::RegisterDotOsgWrapperProxy g_SGRotateTransformProxy
+ (
+ new SGRotateTransform,
+ "SGRotateTransform",
+ "Object Node Transform SGRotateTransform Group",
+ &RotateTransform_readLocalData,
+ &RotateTransform_writeLocalData
+ );
Index: SGRotateTransform.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGRotateTransform.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGRotateTransform.hxx 28 May 2007 07:13:07 -0000 1.1
--- SGRotateTransform.hxx 22 Jul 2007 20:06:21 -0000 1.2
***************
*** 29,33 ****
--- 29,37 ----
public:
SGRotateTransform();
+ SGRotateTransform(const SGRotateTransform&,
+ const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
+ META_Node(simgear, SGRotateTransform);
+
void setCenter(const SGVec3f& center)
{ setCenter(toVec3d(center)); }
Index: SGScaleTransform.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGScaleTransform.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGScaleTransform.cxx 28 May 2007 07:13:07 -0000 1.1
--- SGScaleTransform.cxx 22 Jul 2007 20:06:21 -0000 1.2
***************
*** 45,48 ****
--- 45,52 ----
#endif
+ #include <osgDB/Registry>
+ #include <osgDB/Input>
+ #include <osgDB/Output>
+
#include "SGScaleTransform.hxx"
***************
*** 55,58 ****
--- 59,71 ----
}
+ 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,
***************
*** 108,109 ****
--- 121,178 ----
return bs;
}
+
+ namespace {
+
+ bool ScaleTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
+ {
+ SGScaleTransform& scale = static_cast<SGScaleTransform&>(obj);
+ if (fr[0].matchWord("center")) {
+ ++fr;
+ SGVec3d center;
+ if (fr.readSequence(center.osg()))
+ fr += 3;
+ else
+ return false;
+ scale.setCenter(center);
+ }
+ if (fr[0].matchWord("scaleFactor")) {
+ ++fr;
+ SGVec3d scaleFactor;
+ if (fr.readSequence(scaleFactor.osg()))
+ fr += 3;
+ else
+ return false;
+ scale.setScaleFactor(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
+ );
Index: SGScaleTransform.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGScaleTransform.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGScaleTransform.hxx 28 May 2007 07:13:07 -0000 1.1
--- SGScaleTransform.hxx 22 Jul 2007 20:06:21 -0000 1.2
***************
*** 29,32 ****
--- 29,36 ----
public:
SGScaleTransform();
+ SGScaleTransform(const SGScaleTransform&,
+ const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
+
+ META_Node(simgear, SGScaleTransform);
void setCenter(const SGVec3f& center)
Index: SGTranslateTransform.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGTranslateTransform.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGTranslateTransform.cxx 28 May 2007 07:13:07 -0000 1.1
--- SGTranslateTransform.cxx 22 Jul 2007 20:06:21 -0000 1.2
***************
*** 24,27 ****
--- 24,31 ----
#endif
+ #include <osgDB/Registry>
+ #include <osgDB/Input>
+ #include <osgDB/Output>
+
#include "SGTranslateTransform.hxx"
***************
*** 43,46 ****
--- 47,58 ----
}
+ 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,
***************
*** 82,83 ****
--- 94,149 ----
return bs;
}
+
+ namespace {
+
+ bool TranslateTransform_readLocalData(osg::Object& obj, osgDB::Input& fr)
+ {
+ SGTranslateTransform& trans = static_cast<SGTranslateTransform&>(trans);
+
+ if (fr[0].matchWord("axis")) {
+ ++fr;
+ SGVec3d axis;
+ if (fr.readSequence(axis.osg()))
+ fr += 3;
+ else
+ return false;
+ trans.setAxis(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
+ );
Index: SGTranslateTransform.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/SGTranslateTransform.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -r1.1 -r1.2
*** SGTranslateTransform.hxx 28 May 2007 07:13:07 -0000 1.1
--- SGTranslateTransform.hxx 22 Jul 2007 20:06:21 -0000 1.2
***************
*** 29,33 ****
--- 29,37 ----
public:
SGTranslateTransform();
+ SGTranslateTransform(const SGTranslateTransform&,
+ const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
+ META_Node(simgear, SGTranslateTransform);
+
void setAxis(const SGVec3d& axis)
{ _axis = axis; dirtyBound(); }
Index: placementtrans.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/placementtrans.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -C 2 -r1.6 -r1.7
*** placementtrans.cxx 20 Nov 2006 18:17:56 -0000 1.6
--- placementtrans.cxx 22 Jul 2007 20:06:21 -0000 1.7
***************
*** 28,31 ****
--- 28,35 ----
#endif
+ #include <osgDB/Registry>
+ #include <osgDB/Input>
+ #include <osgDB/Output>
+
#include <simgear/compiler.h>
#include <simgear/constants.h>
***************
*** 70,73 ****
--- 74,87 ----
}
+ SGPlacementTransform::SGPlacementTransform(const SGPlacementTransform& trans,
+ const osg::CopyOp& copyop):
+ osg::Transform(trans, copyop),
+ _placement_offset(trans._placement_offset),
+ _scenery_center(trans._scenery_center),
+ _rotation(trans._rotation)
+ {
+
+ }
+
SGPlacementTransform::~SGPlacementTransform(void)
{
***************
*** 112,113 ****
--- 126,221 ----
return true;
}
+
+ // Functions to read / write SGPlacementTrans from / to a .osg file,
+ // mostly for debugging purposes.
+
+ namespace {
+
+ bool PlacementTrans_readLocalData(osg::Object& obj, osgDB::Input& fr)
+ {
+ SGPlacementTransform& trans = static_cast<SGPlacementTransform&>(obj);
+ SGMatrixd rotation(1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+ SGVec3d placementOffset(0, 0, 0);
+ SGVec3d sceneryCenter(0, 0, 0);
+
+ if (fr[0].matchWord("rotation") && fr[1].isOpenBracket()) {
+ fr += 2;
+ for (int i = 0; i < 3; i++) {
+ SGVec3d scratch;
+ if (!fr.readSequence(scratch.osg()))
+ return false;
+ fr += 3;
+ for (int j = 0; j < 3; j++)
+ rotation(j, i) = scratch[j];
+ }
+ if (fr[0].isCloseBracket())
+ ++fr;
+ else
+ return false;
+ }
+ if (fr[0].matchWord("placement")) {
+ ++fr;
+ if (fr.readSequence(placementOffset.osg()))
+ fr += 3;
+ else
+ return false;
+ }
+ if (fr[0].matchWord("sceneryCenter")) {
+ ++fr;
+ if (fr.readSequence(sceneryCenter.osg()))
+ fr += 3;
+ else
+ return false;
+ }
+ trans.setTransform(placementOffset, rotation);
+ trans.setSceneryCenter(sceneryCenter);
+ return true;
+ }
+
+ bool PlacementTrans_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
+ {
+ const SGPlacementTransform& trans
+ = static_cast<const SGPlacementTransform&>(obj);
+ const SGMatrixd& rotation = trans.getRotation();
+ const SGVec3d& placement = trans.getGlobalPos();
+ const SGVec3d& sceneryCenter = trans.getSceneryCenter();
+
+ fw.indent() << "rotation {" << std::endl;
+ fw.moveIn();
+ for (int i = 0; i < 3; i++) {
+ fw.indent();
+ for (int j = 0; j < 3; j++) {
+ fw << rotation(j, i) << " ";
+ }
+ fw << std::endl;
+ }
+ fw.moveOut();
+ fw.indent() << "}" << std::endl;
+ int prec = fw.precision();
+ fw.precision(15);
+ fw.indent() << "placement ";
+ for (int i = 0; i < 3; i++) {
+ fw << placement(i) << " ";
+ }
+ fw << std::endl;
+ fw.indent() << "sceneryCenter ";
+ for (int i = 0; i < 3; i++) {
+ fw << sceneryCenter(i) << " ";
+ }
+ fw << std::endl;
+ fw.precision(prec);
+ return true;
+ }
+ }
+
+ osgDB::RegisterDotOsgWrapperProxy g_SGPlacementTransProxy
+ (
+ new SGPlacementTransform,
+ "SGPlacementTransform",
+ "Object Node Transform SGPlacementTransform Group",
+ &PlacementTrans_readLocalData,
+ &PlacementTrans_writeLocalData
+ );
Index: placementtrans.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/placementtrans.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -C 2 -r1.4 -r1.5
*** placementtrans.hxx 20 Nov 2006 18:17:56 -0000 1.4
--- placementtrans.hxx 22 Jul 2007 20:06:21 -0000 1.5
***************
*** 39,44 ****
SGPlacementTransform(void);
! virtual ~SGPlacementTransform(void);
void setTransform(const SGVec3d& off)
{ _placement_offset = off; dirtyBound(); }
--- 39,47 ----
SGPlacementTransform(void);
! SGPlacementTransform(const SGPlacementTransform&,
! const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
+ META_Node(simgear, SGPlacementTransform);
+
void setTransform(const SGVec3d& off)
{ _placement_offset = off; dirtyBound(); }
***************
*** 47,57 ****
void setSceneryCenter(const SGVec3d& center)
{ _scenery_center = center; dirtyBound(); }
!
const SGVec3d& getGlobalPos() const
{ return _placement_offset; }
!
virtual bool computeLocalToWorldMatrix(osg::Matrix&,osg::NodeVisitor*) const;
virtual bool computeWorldToLocalMatrix(osg::Matrix&,osg::NodeVisitor*) const;
private:
--- 50,65 ----
void setSceneryCenter(const SGVec3d& center)
{ _scenery_center = center; dirtyBound(); }
!
const SGVec3d& getGlobalPos() const
{ return _placement_offset; }
! const SGMatrixd& getRotation() const { return _rotation; }
! const SGVec3d& getSceneryCenter() const { return _scenery_center; }
!
virtual bool computeLocalToWorldMatrix(osg::Matrix&,osg::NodeVisitor*) const;
virtual bool computeWorldToLocalMatrix(osg::Matrix&,osg::NodeVisitor*) const;
+ protected:
+ virtual ~SGPlacementTransform(void);
+
private:
|