Added minimum and maximum scale support to osg::AutoTransform
This commit is contained in:
@@ -49,10 +49,17 @@ class OSG_EXPORT AutoTransform : public Transform
|
||||
inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); }
|
||||
inline const Quat& getRotation() const { return _rotation; }
|
||||
|
||||
inline void setScale(float scale) { _scale.set(scale,scale,scale); _matrixDirty=true; dirtyBound(); }
|
||||
inline void setScale(const Vec3& scale) { _scale = scale; _matrixDirty=true; dirtyBound(); }
|
||||
inline void setScale(float scale) { setScale(osg::Vec3(scale,scale,scale)); }
|
||||
|
||||
void setScale(const Vec3& scale);
|
||||
inline const Vec3& getScale() const { return _scale; }
|
||||
|
||||
void setMinimumScale(float minimumScale) { _minimumScale = minimumScale; }
|
||||
float getMinimumScale() const { return _minimumScale; }
|
||||
|
||||
void setMaximumScale(float maximumScale) { _maximumScale = maximumScale; }
|
||||
float getMaximumScale() const { return _maximumScale; }
|
||||
|
||||
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); }
|
||||
inline const Vec3& getPivotPoint() const { return _pivotPoint; }
|
||||
|
||||
@@ -105,6 +112,9 @@ class OSG_EXPORT AutoTransform : public Transform
|
||||
mutable Viewport::value_type _previousHeight;
|
||||
mutable osg::Matrix _previousProjection;
|
||||
mutable osg::Vec3 _previousPosition;
|
||||
|
||||
float _minimumScale;
|
||||
float _maximumScale;
|
||||
|
||||
|
||||
void computeMatrix() const;
|
||||
|
||||
@@ -23,6 +23,8 @@ AutoTransform::AutoTransform():
|
||||
_autoScaleToScreen(false),
|
||||
_scale(1.0f,1.0f,1.0f),
|
||||
_firstTimeToInitEyePoint(true),
|
||||
_minimumScale(0.0f),
|
||||
_maximumScale(FLT_MAX),
|
||||
_matrixDirty(true)
|
||||
{
|
||||
// setNumChildrenRequiringUpdateTraversal(1);
|
||||
@@ -38,11 +40,29 @@ AutoTransform::AutoTransform(const AutoTransform& pat,const CopyOp& copyop):
|
||||
_rotation(pat._rotation),
|
||||
_scale(pat._scale),
|
||||
_firstTimeToInitEyePoint(true),
|
||||
_minimumScale(pat._minimumScale),
|
||||
_maximumScale(pat._maximumScale),
|
||||
_matrixDirty(true)
|
||||
{
|
||||
// setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||
}
|
||||
|
||||
void AutoTransform::setScale(const Vec3& scale)
|
||||
{
|
||||
_scale = scale;
|
||||
if (_scale.x()<_minimumScale) _scale.x() = _minimumScale;
|
||||
if (_scale.y()<_minimumScale) _scale.y() = _minimumScale;
|
||||
if (_scale.z()<_minimumScale) _scale.z() = _minimumScale;
|
||||
|
||||
if (_scale.x()>_maximumScale) _scale.x() = _maximumScale;
|
||||
if (_scale.y()>_maximumScale) _scale.y() = _maximumScale;
|
||||
if (_scale.z()>_maximumScale) _scale.z() = _maximumScale;
|
||||
|
||||
_matrixDirty=true;
|
||||
dirtyBound();
|
||||
}
|
||||
|
||||
|
||||
bool AutoTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
if (_matrixDirty) computeMatrix();
|
||||
@@ -158,6 +178,10 @@ void AutoTransform::accept(NodeVisitor& nv)
|
||||
if (getAutoScaleToScreen())
|
||||
{
|
||||
float size = 1.0f/cs->pixelSize(getPosition(),0.48f);
|
||||
|
||||
if (size<_minimumScale) size = _minimumScale;
|
||||
if (size>_maximumScale) size = _maximumScale;
|
||||
|
||||
setScale(size);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,28 @@ bool AutoTransform_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("minimumScale %f"))
|
||||
{
|
||||
float scale;
|
||||
fr[1].getFloat(scale);
|
||||
|
||||
transform.setMinimumScale(scale);
|
||||
|
||||
fr += 2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("maximumScale %f"))
|
||||
{
|
||||
float scale;
|
||||
fr[1].getFloat(scale);
|
||||
|
||||
transform.setMaximumScale(scale);
|
||||
|
||||
fr += 2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("pivotPoint %f %f %f"))
|
||||
{
|
||||
osg::Vec3 pivot;
|
||||
@@ -129,6 +151,11 @@ bool AutoTransform_writeLocalData(const Object& obj, Output& fw)
|
||||
fw.indent()<<"position "<<transform.getPosition()<<std::endl;
|
||||
fw.indent()<<"rotation "<<transform.getRotation()<<std::endl;
|
||||
fw.indent()<<"scale "<<transform.getScale()<<std::endl;
|
||||
|
||||
if (transform.getMinimumScale()>0.0) fw.indent()<<"minimumScale "<<transform.getMinimumScale()<<std::endl;
|
||||
if (transform.getMaximumScale()<FLT_MAX) fw.indent()<<"maximumScale "<<transform.getMaximumScale()<<std::endl;
|
||||
|
||||
|
||||
fw.indent()<<"pivotPoint "<<transform.getPivotPoint()<<std::endl;
|
||||
fw.indent()<<"autoUpdateEyeMovementTolerance "<<transform.getAutoUpdateEyeMovementTolerance()<<std::endl;
|
||||
fw.indent()<<"autoRotateMode ";
|
||||
|
||||
Reference in New Issue
Block a user