-class SGScaleAnimation::Transform : public osg::Transform {
-public:
- Transform() :
- _center(0, 0, 0),
- _scaleFactor(1, 1, 1),
- _boundScale(0)
- {
- setReferenceFrame(RELATIVE_RF);
- }
- void setCenter(const SGVec3d& center)
- {
- _center = center;
- dirtyBound();
- }
- void setScaleFactor(const SGVec3d& scaleFactor)
- {
- if (_boundScale < normI(scaleFactor))
- dirtyBound();
- _scaleFactor = scaleFactor;
- }
- void setScaleFactor(double scaleFactor)
- {
- if (_boundScale < fabs(scaleFactor))
- dirtyBound();
- _scaleFactor = SGVec3d(scaleFactor, scaleFactor, scaleFactor);
- }
- virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,
- osg::NodeVisitor* nv) const
- {
- assert(_referenceFrame == RELATIVE_RF);
- osg::Matrix transform;
- transform(0,0) = _scaleFactor[0];
- transform(1,1) = _scaleFactor[1];
- transform(2,2) = _scaleFactor[2];
- transform(3,0) = _center[0]*(1 - _scaleFactor[0]);
- transform(3,1) = _center[1]*(1 - _scaleFactor[1]);
- transform(3,2) = _center[2]*(1 - _scaleFactor[2]);
- matrix.preMult(transform);
- return true;
- }
- virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,
- osg::NodeVisitor* nv) const
- {
- assert(_referenceFrame == RELATIVE_RF);
- if (fabs(_scaleFactor[0]) < SGLimitsd::min())
- return false;
- if (fabs(_scaleFactor[1]) < SGLimitsd::min())
- return false;
- if (fabs(_scaleFactor[2]) < SGLimitsd::min())
- return false;
- SGVec3d rScaleFactor(1/_scaleFactor[0],
- 1/_scaleFactor[1],
- 1/_scaleFactor[2]);
- osg::Matrix transform;
- transform(0,0) = rScaleFactor[0];
- transform(1,1) = rScaleFactor[1];
- transform(2,2) = rScaleFactor[2];
- transform(3,0) = _center[0]*(1 - rScaleFactor[0]);
- transform(3,1) = _center[1]*(1 - rScaleFactor[1]);
- transform(3,2) = _center[2]*(1 - rScaleFactor[2]);
- matrix.postMult(transform);
- return true;
- }
- virtual osg::BoundingSphere computeBound() const
- {
- osg::BoundingSphere bs = osg::Group::computeBound();
- _boundScale = normI(_scaleFactor);
- bs.radius() *= _boundScale;
- return bs;
- }
-
-private:
- SGVec3d _center;
- SGVec3d _scaleFactor;
- mutable double _boundScale;
-};
-