From 5ceefdcc127f8ac1cf12637c52ffb49145ae04b6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 11 Nov 2001 22:32:59 +0000 Subject: [PATCH] Fixed compilation error in src/osgDB/FileUtils.cpp. Added support for nested NodeCallbacks, allowing them to be chained together so that multiple operations can be applied. --- VisualStudio/osg/osg.dsp | 4 +++ include/osg/Matrix | 10 +++++-- include/osg/NodeCallback | 41 +++++++++++++++++++++++++++++ include/osg/ref_ptr | 12 +++++++-- src/Demos/osgcube/osgcube.cpp | 2 +- src/Demos/osgreflect/osgreflect.cpp | 3 +-- src/osg/Makefile | 1 + src/osg/Matrix.cpp | 3 --- src/osgDB/FileUtils.cpp | 2 +- 9 files changed, 67 insertions(+), 11 deletions(-) diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index c1d63c319..c973a9527 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -209,6 +209,10 @@ SOURCE=..\..\src\osg\Node.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\NodeCallback.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\NodeVisitor.cpp # End Source File # Begin Source File diff --git a/include/osg/Matrix b/include/osg/Matrix index 2bf267916..2f8b23bd5 100644 --- a/include/osg/Matrix +++ b/include/osg/Matrix @@ -77,7 +77,7 @@ class SG_EXPORT Matrix : public Object // can I still do something to optimize the same case now? void makeRot( const Vec3& from, const Vec3& to ); - void makeRot( float angle, const Vec3& orientation ); + void makeRot( float angle, const Vec3& axis ); void makeRot( float angle, float x, float y, float z ); void makeRot( const Quat& ); void makeRot( float, float, float ); //Euler angles @@ -92,6 +92,7 @@ class SG_EXPORT Matrix : public Object inline static Matrix trans( float, float, float ); inline static Matrix rotate( const Vec3&, const Vec3& ); inline static Matrix rotate( float, float, float, float ); + inline static Matrix rotate( float angle, const Vec3& axis); inline static Matrix rotate( const Quat& ); inline Vec3 preMult( const Vec3& v ) const; @@ -215,7 +216,12 @@ inline Matrix Matrix::rotate(float angle, float x, float y, float z ) m.makeRot(angle,x,y,z); return m; } - +inline Matrix Matrix::rotate(float angle, const Vec3& axis ) +{ + Matrix m; + m.makeRot(angle,axis); + return m; +} inline Matrix Matrix::rotate(const Vec3& from, const Vec3& to ) { Matrix m; diff --git a/include/osg/NodeCallback b/include/osg/NodeCallback index e10f6569b..edaedd38c 100644 --- a/include/osg/NodeCallback +++ b/include/osg/NodeCallback @@ -39,9 +39,50 @@ class SG_EXPORT NodeCallback : public Referenced { /** Callback method call by the NodeVisitor when visiting a node.*/ virtual void operator()(Node*, NodeVisitor*) {} + /** Call any nested callbacks and then traverse the scene graph. */ + void traverse(Node* node,NodeVisitor* nv); + + void setNestedCallback(NodeCallback* nc) { _nestedCallback = nc; } + NodeCallback* getNestedCallback() { return _nestedCallback.get(); } + + inline void addNestedCallback(NodeCallback* nc) + { + if (nc) + { + if (_nestedCallback.valid()) + { + nc->addNestedCallback(_nestedCallback.get()); + _nestedCallback = nc; + } + else + { + _nestedCallback = nc; + } + } + } + + inline void removeNestedCallback(NodeCallback* nc) + { + if (nc) + { + if (_nestedCallback==nc) + { + NodeCallback* nested_nc = _nestedCallback->getNestedCallback(); + if (nested_nc) _nestedCallback = nc; + else _nestedCallback = 0; + } + else + { + _nestedCallback->removeNestedCallback(nc); + } + } + } + public: Requirements _requirements; + + ref_ptr _nestedCallback; }; }; // namespace diff --git a/include/osg/ref_ptr b/include/osg/ref_ptr index 2b7d07f20..e64d87295 100644 --- a/include/osg/ref_ptr +++ b/include/osg/ref_ptr @@ -21,18 +21,26 @@ class ref_ptr inline ref_ptr& operator = (const ref_ptr& rp) { if (_ptr==rp._ptr) return *this; - if (_ptr) _ptr->unref(); + T* tmp_ptr = _ptr; _ptr = rp._ptr; if (_ptr) _ptr->ref(); + // unref second to prevent any deletion of any object which might + // be referenced by the other object. i.e rp is child of the + // original _ptr. + if (tmp_ptr) tmp_ptr->unref(); return *this; } inline ref_ptr& operator = (T* ptr) { if (_ptr==ptr) return *this; - if (_ptr) _ptr->unref(); + T* tmp_ptr = _ptr; _ptr = ptr; if (_ptr) _ptr->ref(); + // unref second to prevent any deletion of any object which might + // be referenced by the other object. i.e rp is child of the + // original _ptr. + if (tmp_ptr) tmp_ptr->unref(); return *this; } diff --git a/src/Demos/osgcube/osgcube.cpp b/src/Demos/osgcube/osgcube.cpp index 6362ebdf2..29dd3499f 100644 --- a/src/Demos/osgcube/osgcube.cpp +++ b/src/Demos/osgcube/osgcube.cpp @@ -57,7 +57,7 @@ class TransformCallback : public osg::NodeCallback{ } // must continue subgraph traversal. - nv->traverse(*node); + traverse(node,nv); } diff --git a/src/Demos/osgreflect/osgreflect.cpp b/src/Demos/osgreflect/osgreflect.cpp index 71db281e8..f596338f8 100644 --- a/src/Demos/osgreflect/osgreflect.cpp +++ b/src/Demos/osgreflect/osgreflect.cpp @@ -84,8 +84,7 @@ class TransformCallback : public osg::NodeCallback{ } // must continue subgraph traversal. - nv->traverse(*node); - + traverse(node,nv); } diff --git a/src/osg/Makefile b/src/osg/Makefile index d1d845e14..f779ecde5 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -31,6 +31,7 @@ C++FILES = \ Material.cpp\ Matrix.cpp\ Node.cpp\ + NodeCallback.cpp\ NodeVisitor.cpp\ Notify.cpp\ Object.cpp\ diff --git a/src/osg/Matrix.cpp b/src/osg/Matrix.cpp index e018e3deb..37e19e00a 100644 --- a/src/osg/Matrix.cpp +++ b/src/osg/Matrix.cpp @@ -99,9 +99,6 @@ void Matrix::set( float a00, float a01, float a02, float a03, void Matrix::setTrans( float tx, float ty, float tz ) { -#ifdef WARN_DEPRECATED - notify(NOTICE) << "Matrix::setTrans is deprecated."<