From 16b19a0c30e61e70c2ae59a25e9fcf3a2ebeb160 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 9 Apr 2015 18:42:08 +0000 Subject: [PATCH] Refactored AntiSquish::computeUnSquishedMatrix() method to use the parent node path of the AntiSquish node to compute the required matrix rather than using the NodePath provided by the NodeVistor. This is required as in osg::computeLocalToWorld() usage case the NodeVisitor pointer is NULL, so the correct matrix isn't possible to compute. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14828 16af8721-9629-0410-8352-f15c8da7e697 --- include/osgManipulator/AntiSquish | 2 +- src/osgManipulator/AntiSquish.cpp | 32 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/include/osgManipulator/AntiSquish b/include/osgManipulator/AntiSquish index fe72103db..b036bf13a 100644 --- a/include/osgManipulator/AntiSquish +++ b/include/osgManipulator/AntiSquish @@ -64,7 +64,7 @@ class OSGMANIPULATOR_EXPORT AntiSquish: public osg::Transform virtual ~AntiSquish(); - bool computeUnSquishedMatrix(const osg::NodeVisitor*,osg::Matrix&) const; + bool computeUnSquishedMatrix(osg::Matrix&) const; osg::Vec3d _pivot; bool _usePivot; diff --git a/src/osgManipulator/AntiSquish.cpp b/src/osgManipulator/AntiSquish.cpp index 47e676336..68115a714 100644 --- a/src/osgManipulator/AntiSquish.cpp +++ b/src/osgManipulator/AntiSquish.cpp @@ -52,8 +52,10 @@ AntiSquish::~AntiSquish() bool AntiSquish::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const { osg::Matrix unsquishedMatrix; - if ( !computeUnSquishedMatrix( nv, unsquishedMatrix ) ) - return Transform::computeLocalToWorldMatrix( matrix, nv ); + if ( !computeUnSquishedMatrix( unsquishedMatrix ) ) + { + return false; + } if (_referenceFrame==RELATIVE_RF) { @@ -68,11 +70,13 @@ bool AntiSquish::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* } -bool AntiSquish::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const +bool AntiSquish::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const { osg::Matrix unsquishedMatrix; - if ( !computeUnSquishedMatrix( nv, unsquishedMatrix ) ) - return Transform::computeWorldToLocalMatrix( matrix, nv ); + if ( !computeUnSquishedMatrix( unsquishedMatrix ) ) + { + return false; + } osg::Matrixd inverse; inverse.invert( unsquishedMatrix ); @@ -89,22 +93,13 @@ bool AntiSquish::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* } -bool AntiSquish::computeUnSquishedMatrix(const osg::NodeVisitor* nv, osg::Matrix& unsquished) const +bool AntiSquish::computeUnSquishedMatrix(osg::Matrix& unsquished) const { OpenThreads::ScopedLock lock( _cacheLock ); - if ( !nv ) - { - if ( !_cacheDirty ) - { - unsquished = _cache; - return true; - } - - return false; - } - - osg::NodePath np = nv->getNodePath(); + osg::NodePathList nodePaths = getParentalNodePaths(); + osg::NodePath np; + if (!nodePaths.empty()) np = nodePaths.front(); // Remove the last node which is the anti squish node itself. np.pop_back(); @@ -112,6 +107,7 @@ bool AntiSquish::computeUnSquishedMatrix(const osg::NodeVisitor* nv, osg::Matrix // Get the accumulated modeling matrix. const osg::Matrix localToWorld = osg::computeLocalToWorld(np); + // reuse cached value if ( !_cacheDirty && _cacheLocalToWorld==localToWorld ) { unsquished = _cache;