2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//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-08-05 04:34:48 +08:00
|
|
|
/** A Transform is a group node for which all children are transformed by
|
|
|
|
* a 4x4 matrix. It is often used for positioning objects within a scene,
|
|
|
|
* producing trackball functionality or for animation.
|
|
|
|
*
|
|
|
|
* Transform itself does not provide set/get functions, only the interface
|
|
|
|
* for defining what the 4x4 transformation is. Subclasses, such as
|
|
|
|
* MatrixTransform and PositionAttitudeTransform support the use of an
|
|
|
|
* osg::Matrix or a osg::Vec3/osg::Quat resprectively.
|
|
|
|
* The Transform node can be customized via the ComputeTransfromCallback
|
|
|
|
* which can be attached to the node. This might be used to convert from
|
|
|
|
* internal representations of the transformation into generic osg::Matrix
|
|
|
|
* objects which are used during scene grpah traversal, such as
|
|
|
|
* CullTraversal and IntersectionTraversal.
|
|
|
|
*
|
|
|
|
* 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. This can be done transparently through OpenGL's
|
|
|
|
* use of either GL_NORMALIZE and GL_SCALE_NORMALIZE modes. For further
|
|
|
|
* background reading see the glNormalize documentation in the OpenGL
|
|
|
|
* Reference Guide (the blue book). To enable it in the OSG, you simply
|
|
|
|
* 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
|
|
|
|
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
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Node(osg, Transform);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-09-12 23:34:31 +08:00
|
|
|
virtual Transform* asTransform() { return this; }
|
|
|
|
virtual const Transform* asTransform() const { return this; }
|
|
|
|
|
Added DataVariance enum and set/get fields to osg::Object to help identify
which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC). Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.
Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)
Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc. Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled. However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
2002-04-12 07:20:23 +08:00
|
|
|
enum ReferenceFrame
|
2001-10-11 04:20:14 +08:00
|
|
|
{
|
Added DataVariance enum and set/get fields to osg::Object to help identify
which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC). Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.
Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)
Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc. Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled. However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
2002-04-12 07:20:23 +08:00
|
|
|
RELATIVE_TO_PARENTS,
|
2002-04-12 17:53:39 +08:00
|
|
|
RELATIVE_TO_ABSOLUTE
|
2001-10-11 04:20:14 +08:00
|
|
|
};
|
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Set the transform's ReferenceFrame, either to be relative to its
|
|
|
|
* parent reference frame, or relative to an absolute coordinate
|
|
|
|
* frame. RELATIVE_TO_PARENTS is the default.
|
|
|
|
* Note: setting the ReferenceFrame to be RELATIVE_TO_ABSOLUTE will
|
|
|
|
* also set the CullingActive flag on the transform, and hence all
|
|
|
|
* of its parents, to false, thereby disabling culling of it and
|
|
|
|
* all its parents. This is neccessary to prevent inappropriate
|
|
|
|
* culling, but may impact cull times if the absolute transform is
|
|
|
|
* deep in the scene graph. It is therefore recommend to only use
|
|
|
|
* absolute Transforms at the top of the scene, for such things as
|
|
|
|
* headlight LightSources or Heads up displays. */
|
Added DataVariance enum and set/get fields to osg::Object to help identify
which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC). Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.
Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)
Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc. Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled. However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
2002-04-12 07:20:23 +08:00
|
|
|
void setReferenceFrame(ReferenceFrame rf);
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
ReferenceFrame getReferenceFrame() const { return _referenceFrame; }
|
2002-01-23 23:42:36 +08:00
|
|
|
|
2002-02-06 05:54:46 +08:00
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Callback attached to an Transform to specify how to compute the
|
|
|
|
* modelview transformation for the transform below the Transform
|
|
|
|
* node. */
|
2002-12-04 01:20:31 +08:00
|
|
|
struct ComputeTransformCallback : public virtual osg::Referenced
|
2002-01-24 06:15:39 +08:00
|
|
|
{
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Get the transformation matrix which moves from local coords
|
|
|
|
* to world coords.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeLocalToWorldMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Get the transformation matrix which moves from world coords
|
|
|
|
* to local coords.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeWorldToLocalMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0;
|
2002-02-07 09:15:15 +08:00
|
|
|
};
|
2002-02-06 05:54:46 +08:00
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Set the ComputerTransfromCallback which allows users to attach
|
|
|
|
* custom computation of the local transformation as seen by cull
|
|
|
|
* traversers and the like. */
|
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
|
|
|
|
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Get the transformation matrix which moves from local coords to
|
|
|
|
* world coords.
|
|
|
|
* Returns true if the Matrix passed in has been updated. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool getLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const
|
2002-02-06 05:54:46 +08:00
|
|
|
{
|
|
|
|
if (_computeTransformCallback.valid())
|
|
|
|
return _computeTransformCallback->computeLocalToWorldMatrix(matrix,this,nv);
|
|
|
|
else
|
|
|
|
return computeLocalToWorldMatrix(matrix,nv);
|
|
|
|
}
|
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Get the transformation matrix which moves from world coords to
|
|
|
|
* local coords.
|
|
|
|
* Return true if the Matrix passed in has been updated. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool getWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const
|
2002-02-06 05:54:46 +08:00
|
|
|
{
|
|
|
|
if (_computeTransformCallback.valid())
|
|
|
|
return _computeTransformCallback->computeWorldToLocalMatrix(matrix,this,nv);
|
|
|
|
else
|
|
|
|
return computeWorldToLocalMatrix(matrix,nv);
|
|
|
|
}
|
2002-01-24 06:15:39 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
2002-08-22 16:14:38 +08:00
|
|
|
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else // absolute
|
|
|
|
{
|
2002-07-13 02:12:01 +08:00
|
|
|
matrix.makeIdentity();
|
2002-07-12 22:25:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
2002-08-22 16:14:38 +08:00
|
|
|
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else // absolute
|
|
|
|
{
|
2002-07-13 02:12:01 +08:00
|
|
|
matrix.makeIdentity();
|
2002-07-12 22:25:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-29 07:43:22 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Transform();
|
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** Overrides 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.) */
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeBound() const;
|
2002-05-29 07:43:22 +08:00
|
|
|
|
2002-02-12 16:23:07 +08:00
|
|
|
|
2002-07-12 22:25:10 +08:00
|
|
|
ref_ptr<ComputeTransformCallback> _computeTransformCallback;
|
|
|
|
|
|
|
|
ReferenceFrame _referenceFrame;
|
|
|
|
|
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
|