From ca61c111343788f84d4b9a4f2ba23d3719017a12 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 17 Aug 2004 07:58:32 +0000 Subject: [PATCH] From David Fries, "I added code to also check the local up vector, but only if one of the rotation modes is selected, because autoscale isn't affected by the camera rotations. " --- include/osg/AutoTransform | 4 +--- src/osg/AutoTransform.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/osg/AutoTransform b/include/osg/AutoTransform index 7dc15086b..29129747e 100644 --- a/include/osg/AutoTransform +++ b/include/osg/AutoTransform @@ -119,6 +119,7 @@ class SG_EXPORT AutoTransform : public Transform mutable Vec3 _scale; mutable bool _firstTimeToInitEyePoint; mutable osg::Vec3 _previousEyePoint; + mutable osg::Vec3 _previousLocalUp; mutable int _previousWidth; mutable int _previousHeight; mutable osg::Matrix _previousProjection; @@ -129,9 +130,6 @@ class SG_EXPORT AutoTransform : public Transform mutable bool _matrixDirty; mutable osg::Matrix _cachedMatrix; - - - }; } diff --git a/src/osg/AutoTransform.cpp b/src/osg/AutoTransform.cpp index c98d9ec68..cba4c86fe 100644 --- a/src/osg/AutoTransform.cpp +++ b/src/osg/AutoTransform.cpp @@ -113,6 +113,7 @@ void AutoTransform::accept(NodeVisitor& nv) } osg::Vec3 eyePoint = cs->getEyeLocal(); + osg::Vec3 localUp = cs->getUpLocal(); osg::Vec3 position = getPosition(); const osg::Matrix& projection = cs->getProjectionMatrix(); @@ -125,6 +126,13 @@ void AutoTransform::accept(NodeVisitor& nv) { doUpdate = true; } + osg::Vec3 dupv = _previousLocalUp-localUp; + // rotating the camera only affects ROTATE_TO_* + if (_autoRotateMode && + dupv.length2()>getAutoUpdateEyeMovementTolerance()) + { + doUpdate = true; + } else if (width!=_previousWidth || height!=_previousHeight) { doUpdate = true; @@ -159,13 +167,14 @@ void AutoTransform::accept(NodeVisitor& nv) { osg::Vec3 PosToEye = _position - eyePoint; osg::Matrix lookto = osg::Matrix::lookAt( - osg::Vec3(0,0,0), PosToEye, cs->getUpLocal()); + osg::Vec3(0,0,0), PosToEye, localUp); Quat q; q.set(osg::Matrix::inverse(lookto)); setRotation(q); } _previousEyePoint = eyePoint; + _previousLocalUp = localUp; _previousWidth = width; _previousHeight = height; _previousProjection = projection;