2003-05-02 05:06:18 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
2004-08-06 16:22:58 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
2003-05-02 05:06:18 +08:00
|
|
|
* 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.
|
2003-05-02 05:06:18 +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
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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>
|
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
|
|
|
|
|
|
|
/** AutoTransform - is Transform the automatically scales or rotates
|
2004-08-06 16:22:58 +08:00
|
|
|
* to keep its children relative to screen space coordinates.
|
|
|
|
*/
|
|
|
|
class SG_EXPORT AutoTransform : public Transform
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
AutoTransform();
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +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; }
|
|
|
|
|
2004-03-02 23:27:59 +08:00
|
|
|
inline void setScale(float scale) { _scale.set(scale,scale,scale); _matrixDirty=true; dirtyBound(); }
|
2004-08-06 16:22:58 +08:00
|
|
|
inline void setScale(const Vec3& scale) { _scale = scale; dirtyBound(); }
|
|
|
|
inline const Vec3& getScale() const { return _scale; }
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
|
|
void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
|
|
|
|
float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum AutoRotateMode
|
|
|
|
{
|
|
|
|
NO_ROTATION,
|
|
|
|
ROTATE_TO_SCREEN,
|
|
|
|
ROTATE_TO_CAMERA
|
|
|
|
};
|
|
|
|
|
|
|
|
void setAutoRotateMode(AutoRotateMode mode) { _autoRotateMode = mode; }
|
|
|
|
|
|
|
|
AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
|
|
|
|
|
|
|
|
#ifdef USE_DEPRECATED_API
|
|
|
|
void setAutoRotateToScreen(bool autoRotateToScreen)
|
|
|
|
{
|
|
|
|
setAutoRotateMode(autoRotateToScreen?ROTATE_TO_SCREEN:NO_ROTATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getAutoRotateToCamera() const { return _autoRotateMode==ROTATE_TO_SCREEN; }
|
|
|
|
|
|
|
|
void setAutoRotateToCamera(bool autoRotateToCamera)
|
|
|
|
{
|
|
|
|
setAutoRotateMode(autoRotateToScreen?ROTATE_TO_CAMERA:NO_ROTATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getAutoRotateToCamera() const { return _autoRotateMode==ROTATE_TO_SCREEN; }
|
|
|
|
#endif
|
2003-05-02 05:06:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~AutoTransform() {}
|
|
|
|
|
|
|
|
|
|
|
|
Vec3 _position;
|
|
|
|
Vec3 _pivotPoint;
|
|
|
|
float _autoUpdateEyeMovementTolerance;
|
|
|
|
|
|
|
|
AutoRotateMode _autoRotateMode;
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
bool _autoScaleToScreen;
|
|
|
|
|
|
|
|
mutable Quat _rotation;
|
|
|
|
mutable Vec3 _scale;
|
|
|
|
mutable bool _firstTimeToInitEyePoint;
|
|
|
|
mutable osg::Vec3 _previousEyePoint;
|
2004-08-17 15:58:32 +08:00
|
|
|
mutable osg::Vec3 _previousLocalUp;
|
2004-08-06 16:22:58 +08:00
|
|
|
mutable int _previousWidth;
|
|
|
|
mutable int _previousHeight;
|
|
|
|
mutable osg::Matrix _previousProjection;
|
2004-08-05 23:15:51 +08:00
|
|
|
mutable osg::Vec3 _previousPosition;
|
|
|
|
|
|
|
|
|
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
|