1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSG_AUTOTRANSFORM
15#define OSG_AUTOTRANSFORM 1
18#include <osg/Transform>
20#include <osg/Viewport>
24/** AutoTransform is a derived form of Transform that automatically
25 * scales or rotates to keep its children aligned with screen coordinates.
27class OSG_EXPORT AutoTransform : public Transform
32 AutoTransform(const AutoTransform& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
34 virtual osg::Object* cloneType() const { return new AutoTransform (); }
35 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AutoTransform (*this,copyop); }
36 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const AutoTransform *>(obj)!=NULL; }
37 virtual const char* className() const { return "AutoTransform"; }
38 virtual const char* libraryName() const { return "osg"; }
40 virtual AutoTransform* asAutoTransform() { return this; }
41 virtual const AutoTransform* asAutoTransform() const { return this; }
43 inline void setPosition(const Vec3d& pos) { _position = pos; dirtyBound(); }
44 inline const Vec3d& getPosition() const { return _position; }
47 inline void setRotation(const Quat& quat) { _rotation = quat; dirtyBound(); }
48 inline const Quat& getRotation() const { return _rotation; }
50 inline void setScale(double scale) { setScale(osg::Vec3(scale,scale,scale)); }
52 void setScale(const Vec3d& scale);
53 inline const Vec3d& getScale() const { return _scale; }
55 void setMinimumScale(double minimumScale) { _minimumScale = minimumScale; }
56 double getMinimumScale() const { return _minimumScale; }
58 void setMaximumScale(double maximumScale) { _maximumScale = maximumScale; }
59 double getMaximumScale() const { return _maximumScale; }
61 inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; dirtyBound(); }
62 inline const Vec3d& getPivotPoint() const { return _pivotPoint; }
65 void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
66 float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
77 void setAutoRotateMode(AutoRotateMode mode);
79 AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
81 /** Set the rotation axis for the AutoTransform's child nodes.
82 * Only utilized when _autoRotateMode==ROTATE_TO_AXIS. */
83 void setAxis(const Vec3& axis);
84 /** Get the rotation axis. */
85 inline const Vec3& getAxis() const { return _axis; }
87 /** This normal defines child Nodes' front face direction when unrotated. */
88 void setNormal(const Vec3& normal);
89 /** Get the front face direction normal. */
90 inline const Vec3& getNormal() const { return _normal; }
92 void setAutoScaleToScreen(bool autoScaleToScreen);
93 bool getAutoScaleToScreen() const { return _autoScaleToScreen; }
95 void setAutoScaleTransitionWidthRatio(float ratio) { _autoScaleTransitionWidthRatio = ratio; }
96 float getAutoScaleTransitionWidthRatio() const { return _autoScaleTransitionWidthRatio; }
99 virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
101 virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
105 virtual ~AutoTransform() {}
109 double _autoUpdateEyeMovementTolerance;
111 AutoRotateMode _autoRotateMode;
113 bool _autoScaleToScreen;
115 mutable Quat _rotation;
116 mutable Vec3d _scale;
118 double _minimumScale;
119 double _maximumScale;
120 double _autoScaleTransitionWidthRatio;
122 osg::Matrixd computeMatrix(const osg::NodeVisitor* nv) const;
126 AXIAL_ROT_X_AXIS=ROTATE_TO_AXIS+1,
135 // used internally as cache of which what _axis is aligned to help
136 // decide which method of rotation to use.