root/OpenSceneGraph/trunk/include/osg/AutoTransform @ 7968

Revision 7968, 5.1 kB (checked in by robert, 6 years ago)

To osg::AutoTransform? added support for MinimumScale?, MaximumScale? and AutoScaleTransitionWidth? parameters
and a new scheme for computing the scaling when using autoscale that introduces smooth
transitions to the scaling of the subgraph so that it looks more natural.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_AUTOTRANSFORM
15#define OSG_AUTOTRANSFORM 1
16
17#include <osg/Group>
18#include <osg/Transform>
19#include <osg/Quat>
20#include <osg/Viewport>
21
22namespace osg {
23
24/** AutoTransform is a derived form of Transform that automatically
25  * scales or rotates to keep its children aligned with screen coordinates.
26*/
27class OSG_EXPORT AutoTransform : public Transform
28{
29    public :
30        AutoTransform();
31
32        AutoTransform(const AutoTransform& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY);           
33
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"; }
39
40        virtual void accept(NodeVisitor& nv);
41
42        virtual AutoTransform* asAutoTransform() { return this; }
43        virtual const AutoTransform* asAutoTransform() const { return this; }
44
45        inline void setPosition(const Vec3& pos) { _position = pos; _matrixDirty=true; dirtyBound(); }
46        inline const Vec3& getPosition() const { return _position; }
47
48
49        inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); }
50        inline const Quat& getRotation() const { return _rotation; }
51       
52        inline void setScale(float scale) { setScale(osg::Vec3(scale,scale,scale)); }
53
54        void setScale(const Vec3& scale);
55        inline const Vec3& getScale() const { return _scale; }
56       
57        void setMinimumScale(float minimumScale) { _minimumScale = minimumScale; }
58        float getMinimumScale() const { return _minimumScale; }
59
60        void setMaximumScale(float maximumScale) { _maximumScale = maximumScale; }
61        float getMaximumScale() const { return _maximumScale; }
62
63        inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); }
64        inline const Vec3& getPivotPoint() const { return _pivotPoint; }
65       
66
67        void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
68        float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
69
70
71        enum AutoRotateMode
72        {
73            NO_ROTATION,
74            ROTATE_TO_SCREEN,
75            ROTATE_TO_CAMERA
76        };
77       
78        void setAutoRotateMode(AutoRotateMode mode) { _autoRotateMode = mode; _firstTimeToInitEyePoint = true; }
79
80        AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
81
82        void setAutoScaleToScreen(bool autoScaleToScreen) { _autoScaleToScreen = autoScaleToScreen; _matrixDirty=true; }
83
84        bool getAutoScaleToScreen() const { return _autoScaleToScreen; }
85
86        void setAutoScaleTransistionWidthRatio(float ratio) { _autoScaleTransitionWidthRatio = ratio; }
87        float getAutoScaleTransistionWidthRatio() const { return _autoScaleTransitionWidthRatio; }
88
89
90        virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
91
92        virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
93
94        virtual BoundingSphere computeBound() const;
95
96
97    protected :
98           
99        virtual ~AutoTransform() {}
100
101        Vec3                            _position;
102        Vec3                            _pivotPoint;
103        float                           _autoUpdateEyeMovementTolerance;
104
105        AutoRotateMode                  _autoRotateMode;
106
107        bool                            _autoScaleToScreen;
108       
109        mutable Quat                    _rotation;
110        mutable Vec3                    _scale;
111        mutable bool                    _firstTimeToInitEyePoint;
112        mutable osg::Vec3               _previousEyePoint;
113        mutable osg::Vec3               _previousLocalUp;
114        mutable Viewport::value_type    _previousWidth;
115        mutable Viewport::value_type    _previousHeight;       
116        mutable osg::Matrix             _previousProjection;
117        mutable osg::Vec3               _previousPosition;
118       
119        float                           _minimumScale;
120        float                           _maximumScale;
121        float                           _autoScaleTransitionWidthRatio;
122
123        void computeMatrix() const;
124
125        mutable bool        _matrixDirty;
126        mutable osg::Matrix _cachedMatrix;
127};
128
129}
130
131#endif
Note: See TracBrowser for help on using the browser.