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. "
This commit is contained in:
Robert Osfield 2004-08-17 07:58:32 +00:00
parent ffc5dfb83b
commit ca61c11134
2 changed files with 11 additions and 4 deletions

View File

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

View File

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