2008-08-05 19:17:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2004-08-06 16:22:58 +08:00
|
|
|
*
|
2008-08-05 19:17:48 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2004-08-06 16:22:58 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2008-08-05 19:17:48 +08:00
|
|
|
*
|
2004-08-06 16:22:58 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-05 19:17:48 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-08-06 16:22:58 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
#ifndef OSG_AUTOTRANSFORM
|
|
|
|
#define OSG_AUTOTRANSFORM 1
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/Transform>
|
|
|
|
#include <osg/Quat>
|
2007-01-02 02:20:10 +08:00
|
|
|
#include <osg/Viewport>
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
namespace osg {
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** AutoTransform is a derived form of Transform that automatically
|
|
|
|
* scales or rotates to keep its children aligned with screen coordinates.
|
2004-08-06 16:22:58 +08:00
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT AutoTransform : public Transform
|
2004-08-06 16:22:58 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
AutoTransform();
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2008-08-05 19:17:48 +08:00
|
|
|
AutoTransform(const AutoTransform& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new AutoTransform (); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AutoTransform (*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const AutoTransform *>(obj)!=NULL; }
|
|
|
|
virtual const char* className() const { return "AutoTransform"; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
virtual void accept(NodeVisitor& nv);
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
virtual AutoTransform* asAutoTransform() { return this; }
|
|
|
|
virtual const AutoTransform* asAutoTransform() const { return this; }
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-03-02 23:27:59 +08:00
|
|
|
inline void setPosition(const Vec3& pos) { _position = pos; _matrixDirty=true; dirtyBound(); }
|
2004-08-06 16:22:58 +08:00
|
|
|
inline const Vec3& getPosition() const { return _position; }
|
2003-05-02 05:06:18 +08:00
|
|
|
|
|
|
|
|
2004-03-02 23:27:59 +08:00
|
|
|
inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); }
|
2004-08-06 16:22:58 +08:00
|
|
|
inline const Quat& getRotation() const { return _rotation; }
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2008-03-17 23:22:03 +08:00
|
|
|
inline void setScale(float scale) { setScale(osg::Vec3(scale,scale,scale)); }
|
|
|
|
|
|
|
|
void setScale(const Vec3& scale);
|
2004-08-06 16:22:58 +08:00
|
|
|
inline const Vec3& getScale() const { return _scale; }
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2008-03-17 23:22:03 +08:00
|
|
|
void setMinimumScale(float minimumScale) { _minimumScale = minimumScale; }
|
|
|
|
float getMinimumScale() const { return _minimumScale; }
|
|
|
|
|
|
|
|
void setMaximumScale(float maximumScale) { _maximumScale = maximumScale; }
|
|
|
|
float getMaximumScale() const { return _maximumScale; }
|
|
|
|
|
2004-03-02 23:27:59 +08:00
|
|
|
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); }
|
2004-08-06 16:22:58 +08:00
|
|
|
inline const Vec3& getPivotPoint() const { return _pivotPoint; }
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
|
|
|
|
void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
|
|
|
|
float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
|
|
|
|
|
|
|
|
|
|
|
|
enum AutoRotateMode
|
|
|
|
{
|
|
|
|
NO_ROTATION,
|
|
|
|
ROTATE_TO_SCREEN,
|
|
|
|
ROTATE_TO_CAMERA
|
|
|
|
};
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2007-05-22 23:17:52 +08:00
|
|
|
void setAutoRotateMode(AutoRotateMode mode) { _autoRotateMode = mode; _firstTimeToInitEyePoint = true; }
|
2004-08-06 16:22:58 +08:00
|
|
|
|
|
|
|
AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
|
|
|
|
|
2004-03-02 23:27:59 +08:00
|
|
|
void setAutoScaleToScreen(bool autoScaleToScreen) { _autoScaleToScreen = autoScaleToScreen; _matrixDirty=true; }
|
2004-08-06 16:22:58 +08:00
|
|
|
|
|
|
|
bool getAutoScaleToScreen() const { return _autoScaleToScreen; }
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2008-08-05 19:17:48 +08:00
|
|
|
void setAutoScaleTransitionWidthRatio(float ratio) { _autoScaleTransitionWidthRatio = ratio; }
|
|
|
|
float getAutoScaleTransitionWidthRatio() const { return _autoScaleTransitionWidthRatio; }
|
2008-03-18 23:37:38 +08:00
|
|
|
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2006-02-21 21:51:10 +08:00
|
|
|
virtual BoundingSphere computeBound() const;
|
2003-05-02 05:06:18 +08:00
|
|
|
|
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
protected :
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
virtual ~AutoTransform() {}
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
Vec3 _position;
|
|
|
|
Vec3 _pivotPoint;
|
|
|
|
float _autoUpdateEyeMovementTolerance;
|
2004-08-06 16:22:58 +08:00
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
AutoRotateMode _autoRotateMode;
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
bool _autoScaleToScreen;
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
mutable Quat _rotation;
|
|
|
|
mutable Vec3 _scale;
|
|
|
|
mutable bool _firstTimeToInitEyePoint;
|
|
|
|
mutable osg::Vec3 _previousEyePoint;
|
|
|
|
mutable osg::Vec3 _previousLocalUp;
|
|
|
|
mutable Viewport::value_type _previousWidth;
|
2008-08-05 19:17:48 +08:00
|
|
|
mutable Viewport::value_type _previousHeight;
|
2007-01-02 02:20:10 +08:00
|
|
|
mutable osg::Matrix _previousProjection;
|
|
|
|
mutable osg::Vec3 _previousPosition;
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2008-03-17 23:22:03 +08:00
|
|
|
float _minimumScale;
|
|
|
|
float _maximumScale;
|
2008-03-18 23:37:38 +08:00
|
|
|
float _autoScaleTransitionWidthRatio;
|
2004-08-05 23:15:51 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
void computeMatrix() const;
|
2004-08-05 23:15:51 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
mutable bool _matrixDirty;
|
|
|
|
mutable osg::Matrix _cachedMatrix;
|
|
|
|
};
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
}
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
#endif
|