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
This commit is contained in:
Robert Osfield
2015-04-09 18:42:08 +00:00
parent 595a048319
commit 16b19a0c30
2 changed files with 15 additions and 19 deletions

View File

@@ -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;

View File

@@ -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<OpenThreads::Mutex> 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;