f612924a45
copy constructor which takes an optional Cloner object, and the old osg::Object::clone() has changed so that it now requires a Cloner as paramter. This is passed on to the copy constructor to help control the shallow vs deep copying. The old functionality of clone() which was clone of type has been renamed to cloneType(). Updated all of the OSG to work with these new conventions, implemention all the required copy constructors etc. A couple of areas will do shallow copies by design, a couple of other still need to be updated to do either shallow or deep. Neither of the shallow or deep copy operations have been tested yet, only the old functionality of the OSG has been checked so far, such running the viewer on various demo datasets. Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which was not checking that Group didn't have have any attached StateSet's, Callbacks or UserData. These checks have now been added, which fixes a bug which was revealled by the new osgscribe demo, this related to removal of group acting as state decorator. method
123 lines
4.4 KiB
Plaintext
123 lines
4.4 KiB
Plaintext
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
//as published by the Free Software Foundation.
|
|
|
|
#ifndef OSG_TRANSFORM
|
|
#define OSG_TRANSFORM 1
|
|
|
|
#include <osg/Group>
|
|
#include <osg/Matrix>
|
|
|
|
namespace osg {
|
|
|
|
/** Transform - is group which all children
|
|
* are transformed by the the Transform's osg::Matrix. Typical uses
|
|
* of the Transform is for positioning objects within a scene or
|
|
* producing trackball functionality or for animation.
|
|
* Note, if the transformation matrix scales the subgraph then the
|
|
* normals of the underlying geometry will need to be renormalized to
|
|
* be unit vectors once more. One can done transparently through OpenGL's
|
|
* use of either GL_NORMALIZE and GL_SCALE_NORMALIZE modes. Further
|
|
* background reading see the glNormalize documentation in the OpenGL Reference
|
|
* Guide (the blue book). To enable it in the OSG, you simple need to
|
|
* attach a local osg::StateSet to the osg::Transform, and set the appropriate
|
|
* mode to on via stateset->setMode(GL_NORMALIZE,osg::StateAttribute::ON);.
|
|
*/
|
|
class SG_EXPORT Transform : public Group
|
|
{
|
|
public :
|
|
|
|
Transform();
|
|
|
|
/** Copy constructor using Cloner to manage deep vs shallow copy.*/
|
|
Transform(const Transform&,const Cloner& cloner=ShallowCopy());
|
|
|
|
Transform(const Matrix& matix);
|
|
|
|
META_Node(Transform);
|
|
|
|
/** Range of types that the Transform can be.*/
|
|
enum Type
|
|
{
|
|
DYNAMIC,
|
|
STATIC
|
|
};
|
|
|
|
/** Set the Transform Type, which can be DYNAMIC - the Matrix
|
|
* value is updated during the main loop, or STATIC - the Matrix
|
|
* is constant throughout the life of the main loop. STATIC
|
|
* Transforms can be optimized away is some instances, which
|
|
* can improve performance so unless you plan to modify the
|
|
* Matrix explicitly set the Matrix to STATIC. The default
|
|
* value is DYNAMIC.*/
|
|
inline void setType(Type type) { _type = type; }
|
|
|
|
/** Get the Transform Type.*/
|
|
inline const Type getType() const { return _type; }
|
|
|
|
|
|
|
|
enum Mode
|
|
{
|
|
VIEW,
|
|
MODEL
|
|
};
|
|
|
|
inline void setMode(Mode mode) { _mode = mode; }
|
|
|
|
inline const Mode getMode() const { return _mode; }
|
|
|
|
|
|
/** Get the transformation matrix which moves from local coords to world coords.*/
|
|
inline const Matrix& getLocalToWorldMatrix() const { if (_localToWorldDirty) computeLocalToWorld(); return *_localToWorld; }
|
|
|
|
/** Get the transformation matrix which moves from world coords to local coords.*/
|
|
inline const Matrix& getWorldToLocalMatrix() const { if (_worldToLocalDirty) computeWorldToLocal(); return *_worldToLocal; }
|
|
|
|
|
|
|
|
/** Set the transform's matrix.*/
|
|
void setMatrix(const Matrix& mat);
|
|
|
|
/** Get the transform's matrix. */
|
|
inline const Matrix& getMatrix() const { if (_mode==MODEL) return *_localToWorld; else return *_worldToLocal; }
|
|
|
|
/** preMult transform.*/
|
|
void preMult(const Matrix& mat);
|
|
|
|
/** postMult transform.*/
|
|
void postMult(const Matrix& mat);
|
|
|
|
|
|
protected :
|
|
|
|
virtual ~Transform();
|
|
|
|
/** Override's Group's computeBound.
|
|
* There is no need to override in subclasses from osg::Transform since this computeBound() uses
|
|
* the underlying matrix (calling computeMatrix if required.) */
|
|
virtual const bool computeBound() const;
|
|
|
|
/** If you subclass from osg::Transform you must override computeLocalToWorld() to provide your own mechanism for
|
|
* setting up the 4x4 matrix. An example of a subclass might a PositionAttitudeTransfrom which is its own
|
|
* Vec3 and Quat to calculate the matrix.*/
|
|
virtual void computeLocalToWorld() const;
|
|
|
|
/** If you subclass from osg::Transform it must also override computeWorldToLocal() to provide your own mechanism for
|
|
* setting up the 4x4 matrix.*/
|
|
virtual void computeWorldToLocal() const;
|
|
|
|
Type _type;
|
|
Mode _mode;
|
|
|
|
mutable bool _localToWorldDirty;
|
|
mutable ref_ptr<Matrix> _localToWorld;
|
|
|
|
mutable bool _worldToLocalDirty;
|
|
mutable ref_ptr<Matrix> _worldToLocal;
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|