2001-10-04 23:12:57 +08:00
|
|
|
//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.
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSG_TRANSFORM
|
|
|
|
#define OSG_TRANSFORM 1
|
|
|
|
|
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/Matrix>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Transform - is group which all children are transformed by the the Transform's osg::Matrix.
|
|
|
|
* Typical uses
|
2001-12-29 22:27:46 +08:00
|
|
|
* of the Transform is for positioning objects within a scene or
|
|
|
|
* producing trackball functionality or for animation.
|
2002-02-06 05:54:46 +08:00
|
|
|
* The Transform node can be customized via the ComputeTransfromCallback which can be
|
|
|
|
* attached to the node, this might be used to convert internal representations of the transformation
|
|
|
|
* into generic osg::Matrix'c which are used during scene grpah traversal, such as CullTraversal and IntersectionTraversal.
|
2001-12-29 22:27:46 +08:00
|
|
|
* 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);.
|
2001-09-20 05:19:47 +08:00
|
|
|
*/
|
|
|
|
class SG_EXPORT Transform : public Group
|
|
|
|
{
|
|
|
|
public :
|
Added support for shallow and deep copy of nodes, drawables and state, via a
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
Transform();
|
Added support for shallow and deep copy of nodes, drawables and state, via a
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Transform(const Transform&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
Transform(const Matrix& matix);
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
META_Node(Transform);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-01-23 23:42:36 +08:00
|
|
|
/** Range of types that the Transform can be.*/
|
2001-10-11 04:20:14 +08:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
DYNAMIC,
|
|
|
|
STATIC
|
|
|
|
};
|
|
|
|
|
2001-12-29 22:27:46 +08:00
|
|
|
/** 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
|
2001-10-11 04:20:14 +08:00
|
|
|
* Transforms can be optimized away is some instances, which
|
2001-12-29 22:27:46 +08:00
|
|
|
* can improve performance so unless you plan to modify the
|
|
|
|
* Matrix explicitly set the Matrix to STATIC. The default
|
2001-10-11 04:20:14 +08:00
|
|
|
* value is DYNAMIC.*/
|
|
|
|
inline void setType(Type type) { _type = type; }
|
2001-12-16 00:56:39 +08:00
|
|
|
|
2001-10-11 04:20:14 +08:00
|
|
|
/** Get the Transform Type.*/
|
|
|
|
inline const Type getType() const { return _type; }
|
2002-01-23 23:42:36 +08:00
|
|
|
|
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Set the matrix mode which tells traversers them how to treat this Transform - as Projection, View or Model transformation.*/
|
|
|
|
inline void setMatrixMode(MatrixMode mode) { _mode = mode; }
|
|
|
|
|
|
|
|
/** Get the transform mode.*/
|
|
|
|
inline const MatrixMode getMatrixMode() const { return _mode; }
|
|
|
|
|
2001-10-11 04:20:14 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Callback attached to an Transform to specifiy how to compute the modelview or projection transformation
|
|
|
|
* for the transform below the Transform node.*/
|
2002-02-07 09:15:15 +08:00
|
|
|
struct ComputeTransformCallback : public osg::Referenced
|
2002-01-24 06:15:39 +08:00
|
|
|
{
|
2002-02-07 09:15:15 +08:00
|
|
|
/** Get the transformation matrix which moves from local coords to world coords.*/
|
|
|
|
virtual const bool computeLocalToWorldMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-02-07 09:15:15 +08:00
|
|
|
/** Get the transformation matrix which moves from world coords to local coords.*/
|
|
|
|
virtual const bool computeWorldToLocalMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
friend struct osg::Transform::ComputeTransformCallback;
|
2002-02-06 05:54:46 +08:00
|
|
|
|
|
|
|
/** Set the ComputerTransfromCallback which allows users to attach custom computation of the local transformation as
|
|
|
|
* seen by cull traversers and alike.*/
|
2002-02-07 09:15:15 +08:00
|
|
|
void setComputeTransformCallback(ComputeTransformCallback* ctc) { _computeTransformCallback=ctc; dirtyBound(); }
|
2002-01-24 06:15:39 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Get the non const ComputerTransfromCallback.*/
|
|
|
|
ComputeTransformCallback* getComputeTransformCallback() { return _computeTransformCallback.get(); }
|
2002-01-24 06:15:39 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Get the const ComputerTransfromCallback.*/
|
|
|
|
const ComputeTransformCallback* getComputeTransformCallback() const { return _computeTransformCallback.get(); }
|
2002-01-23 23:42:36 +08:00
|
|
|
|
|
|
|
|
2001-11-14 22:09:07 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
/** Get the transformation matrix which moves from local coords to world coords.
|
|
|
|
* Return true if Matrix passed in has been modified and */
|
|
|
|
inline const bool getLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const
|
|
|
|
{
|
|
|
|
if (_computeTransformCallback.valid())
|
|
|
|
return _computeTransformCallback->computeLocalToWorldMatrix(matrix,this,nv);
|
|
|
|
else
|
|
|
|
return computeLocalToWorldMatrix(matrix,nv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Get the transformation matrix which moves from world coords to local coords.
|
|
|
|
* Return true if Matrix passed in has been modified and */
|
|
|
|
inline const bool getWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const
|
|
|
|
{
|
|
|
|
if (_computeTransformCallback.valid())
|
|
|
|
return _computeTransformCallback->computeWorldToLocalMatrix(matrix,this,nv);
|
|
|
|
else
|
|
|
|
return computeWorldToLocalMatrix(matrix,nv);
|
|
|
|
}
|
2002-01-24 06:15:39 +08:00
|
|
|
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
/** Set the transform's matrix.*/
|
2002-02-06 05:54:46 +08:00
|
|
|
void setMatrix(const Matrix& mat) { (*_matrix) = mat; dirtyBound(); }
|
2002-01-24 06:15:39 +08:00
|
|
|
|
|
|
|
/** Get the transform's matrix. */
|
2002-02-06 05:54:46 +08:00
|
|
|
inline const Matrix& getMatrix() const { return *_matrix; }
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
/** preMult transform.*/
|
2002-02-06 05:54:46 +08:00
|
|
|
void preMult(const Matrix& mat) { _matrix->preMult(mat); dirtyBound(); }
|
2002-01-24 06:15:39 +08:00
|
|
|
|
|
|
|
/** postMult transform.*/
|
2002-02-06 05:54:46 +08:00
|
|
|
void postMult(const Matrix& mat) { _matrix->postMult(mat); dirtyBound(); }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-01-24 06:15:39 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Transform();
|
|
|
|
|
2002-01-23 23:42:36 +08:00
|
|
|
/** 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.) */
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual const bool computeBound() const;
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-02-07 09:15:15 +08:00
|
|
|
virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
2002-02-06 05:54:46 +08:00
|
|
|
{
|
|
|
|
matrix = *_matrix;
|
|
|
|
return true;
|
|
|
|
}
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-02-07 09:15:15 +08:00
|
|
|
virtual const bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
2002-02-06 05:54:46 +08:00
|
|
|
{
|
|
|
|
matrix.invert(*_matrix);
|
|
|
|
return true;
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
|
|
|
|
Type _type;
|
|
|
|
MatrixMode _mode;
|
|
|
|
ref_ptr<ComputeTransformCallback> _computeTransformCallback;
|
|
|
|
|
|
|
|
ref_ptr<Matrix> _matrix;
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|