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 AutoTransform* asAutoTransform() { return this; }
|
|
|
|
virtual const AutoTransform* asAutoTransform() const { return this; }
|
2003-05-02 05:06:18 +08:00
|
|
|
|
2017-04-26 18:50:35 +08:00
|
|
|
inline void setPosition(const Vec3d& pos) { _position = pos; dirtyBound(); }
|
2008-08-28 17:43:00 +08:00
|
|
|
inline const Vec3d& getPosition() const { return _position; }
|
2003-05-02 05:06:18 +08:00
|
|
|
|
|
|
|
|
2017-04-26 18:50:35 +08:00
|
|
|
inline void setRotation(const Quat& quat) { _rotation = quat; 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-08-28 17:43:00 +08:00
|
|
|
inline void setScale(double scale) { setScale(osg::Vec3(scale,scale,scale)); }
|
2008-03-17 23:22:03 +08:00
|
|
|
|
2008-08-28 17:43:00 +08:00
|
|
|
void setScale(const Vec3d& scale);
|
|
|
|
inline const Vec3d& getScale() const { return _scale; }
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2008-08-28 17:43:00 +08:00
|
|
|
void setMinimumScale(double minimumScale) { _minimumScale = minimumScale; }
|
|
|
|
double getMinimumScale() const { return _minimumScale; }
|
2008-03-17 23:22:03 +08:00
|
|
|
|
2008-08-28 17:43:00 +08:00
|
|
|
void setMaximumScale(double maximumScale) { _maximumScale = maximumScale; }
|
|
|
|
double getMaximumScale() const { return _maximumScale; }
|
2008-03-17 23:22:03 +08:00
|
|
|
|
2017-04-26 18:50:35 +08:00
|
|
|
inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; dirtyBound(); }
|
2008-08-28 17:43:00 +08:00
|
|
|
inline const Vec3d& 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,
|
2010-11-06 01:24:50 +08:00
|
|
|
ROTATE_TO_CAMERA,
|
|
|
|
ROTATE_TO_AXIS
|
2004-08-06 16:22:58 +08:00
|
|
|
};
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2010-11-06 01:24:50 +08:00
|
|
|
void setAutoRotateMode(AutoRotateMode mode);
|
2004-08-06 16:22:58 +08:00
|
|
|
|
|
|
|
AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
|
|
|
|
|
2010-11-06 01:24:50 +08:00
|
|
|
/** Set the rotation axis for the AutoTransform's child nodes.
|
|
|
|
* Only utilized when _autoRotateMode==ROTATE_TO_AXIS. */
|
|
|
|
void setAxis(const Vec3& axis);
|
|
|
|
/** Get the rotation axis. */
|
|
|
|
inline const Vec3& getAxis() const { return _axis; }
|
|
|
|
|
|
|
|
/** This normal defines child Nodes' front face direction when unrotated. */
|
|
|
|
void setNormal(const Vec3& normal);
|
|
|
|
/** Get the front face direction normal. */
|
|
|
|
inline const Vec3& getNormal() const { return _normal; }
|
|
|
|
|
2018-04-03 01:26:26 +08:00
|
|
|
void setAutoScaleToScreen(bool autoScaleToScreen);
|
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
|
|
|
|
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() {}
|
|
|
|
|
2008-08-28 17:43:00 +08:00
|
|
|
Vec3d _position;
|
|
|
|
Vec3d _pivotPoint;
|
|
|
|
double _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;
|
2008-08-28 17:43:00 +08:00
|
|
|
mutable Vec3d _scale;
|
2008-08-05 19:17:48 +08:00
|
|
|
|
2008-08-28 17:43:00 +08:00
|
|
|
double _minimumScale;
|
|
|
|
double _maximumScale;
|
|
|
|
double _autoScaleTransitionWidthRatio;
|
2004-08-05 23:15:51 +08:00
|
|
|
|
2017-04-26 18:50:35 +08:00
|
|
|
osg::Matrixd computeMatrix(const osg::NodeVisitor* nv) const;
|
2004-08-05 23:15:51 +08:00
|
|
|
|
2010-11-06 01:24:50 +08:00
|
|
|
enum AxisAligned
|
|
|
|
{
|
|
|
|
AXIAL_ROT_X_AXIS=ROTATE_TO_AXIS+1,
|
|
|
|
AXIAL_ROT_Y_AXIS,
|
|
|
|
AXIAL_ROT_Z_AXIS,
|
|
|
|
CACHE_DIRTY
|
|
|
|
};
|
|
|
|
|
|
|
|
Vec3 _axis;
|
|
|
|
Vec3 _normal;
|
|
|
|
|
|
|
|
// used internally as cache of which what _axis is aligned to help
|
|
|
|
// decide which method of rotation to use.
|
|
|
|
int _cachedMode;
|
|
|
|
Vec3 _side;
|
|
|
|
void updateCache();
|
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
};
|
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
|