2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSG_TRANSFORM
|
|
|
|
#define OSG_TRANSFORM 1
|
|
|
|
|
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/Matrix>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2003-04-14 21:22:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** compute the matrix which transforms objects in local coords to world coords,
|
|
|
|
* by accumulating the Transform local to world matrices along the specified node path.*/
|
|
|
|
extern SG_EXPORT Matrix computeLocalToWorld(NodePath& nodePath);
|
|
|
|
|
|
|
|
/** compute the matrix which transforms objects in world coords to local coords,
|
|
|
|
* by accumulating the Transform world to local matrices along the specified node path.*/
|
|
|
|
extern SG_EXPORT Matrix computeWorldToLocal(NodePath& nodePath);
|
|
|
|
|
|
|
|
/** compute the matrix which transforms objects in local coords to world coords,
|
|
|
|
* by accumulating the Transform local to world matrices along the specified node path
|
|
|
|
* the supplied initialial camera modelview .*/
|
|
|
|
extern SG_EXPORT Matrix computeLocalToEye(const Matrix& modelview, NodePath& nodePath);
|
|
|
|
|
|
|
|
/** compute the matrix which transforms objects in world coords to local coords,
|
|
|
|
* by accumulating the Transform world to local matrices along the specified node path
|
|
|
|
* the inverse of the supplied initialial camera modelview.*/
|
|
|
|
extern SG_EXPORT Matrix computeEyeToLocal(const Matrix& modelview, NodePath& nodePath);
|
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2003-01-24 17:37:56 +08:00
|
|
|
virtual MatrixTransform* asMatrixTransform() { return 0; }
|
|
|
|
virtual const MatrixTransform* asMatrixTransform() const { return 0; }
|
|
|
|
|
|
|
|
virtual PositionAttitudeTransform* asPositionAttitudeTransform() { return 0; }
|
|
|
|
virtual const PositionAttitudeTransform* asPositionAttitudeTransform() const { return 0; }
|
|
|
|
|
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
|
2003-01-17 00:37:24 +08:00
|
|
|
* 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-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-07-12 22:25:10 +08:00
|
|
|
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
|