2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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
|
2003-01-22 00:45:36 +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.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* 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>
|
|
|
|
|
2004-05-19 17:12:52 +08:00
|
|
|
#ifndef GL_RESCALE_NORMAL
|
2009-10-30 23:17:38 +08:00
|
|
|
#define GL_RESCALE_NORMAL 0x803A
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_NORMALIZE
|
|
|
|
#define GL_NORMALIZE 0x0BA1
|
2004-05-19 17:12:52 +08:00
|
|
|
#endif
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
namespace osg {
|
|
|
|
|
2003-04-14 21:22:21 +08:00
|
|
|
|
|
|
|
|
2004-09-13 23:14:11 +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.
|
|
|
|
*/
|
2006-11-27 22:52:07 +08:00
|
|
|
extern OSG_EXPORT Matrix computeLocalToWorld(const NodePath& nodePath, bool ignoreCameras = true);
|
2003-04-14 21:22:21 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** 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.
|
|
|
|
*/
|
2006-11-27 22:52:07 +08:00
|
|
|
extern OSG_EXPORT Matrix computeWorldToLocal(const NodePath& nodePath, bool ignoreCameras = true);
|
2003-04-14 21:22:21 +08:00
|
|
|
|
2004-09-13 23:17:43 +08:00
|
|
|
/** Compute the matrix which transforms objects in local coords to eye coords,
|
2012-03-22 01:36:20 +08:00
|
|
|
* by accumulating the Transform local to world matrices along the specified node path
|
2007-12-11 01:30:18 +08:00
|
|
|
* and multiplying by the supplied initial camera modelview.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2006-11-27 22:52:07 +08:00
|
|
|
extern OSG_EXPORT Matrix computeLocalToEye(const Matrix& modelview, const NodePath& nodePath, bool ignoreCameras = true);
|
2003-04-14 21:22:21 +08:00
|
|
|
|
2004-09-13 23:17:43 +08:00
|
|
|
/** Compute the matrix which transforms objects in eye coords to local coords,
|
|
|
|
* by accumulating the Transform world to local matrices along the specified node path
|
2007-12-11 01:30:18 +08:00
|
|
|
* and multiplying by the inverse of the supplied initial camera modelview.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2006-11-27 22:52:07 +08:00
|
|
|
extern OSG_EXPORT Matrix computeEyeToLocal(const Matrix& modelview, const NodePath& nodePath, bool ignoreCameras = true);
|
2003-04-14 21:22:21 +08:00
|
|
|
|
|
|
|
|
2002-08-05 04:34:48 +08:00
|
|
|
/** A Transform is a group node for which all children are transformed by
|
2004-09-13 23:14:11 +08:00
|
|
|
* a 4x4 matrix. It is often used for positioning objects within a scene,
|
2002-08-05 04:34:48 +08:00
|
|
|
* 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
|
2016-06-01 21:20:14 +08:00
|
|
|
* osg::Matrix or a Vec3 and Quat respectively.
|
2002-08-05 04:34:48 +08:00
|
|
|
*
|
2004-09-13 23:14:11 +08:00
|
|
|
* Note: If the transformation matrix scales the subgraph then the normals
|
2002-08-05 04:34:48 +08:00
|
|
|
* of the underlying geometry will need to be renormalized to be unit
|
2012-03-22 01:36:20 +08:00
|
|
|
* vectors once more. This can be done transparently through OpenGL's
|
2006-05-02 17:49:37 +08:00
|
|
|
* use of either GL_NORMALIZE and GL_RESCALE_NORMAL modes. For further
|
2002-08-05 04:34:48 +08:00
|
|
|
* 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
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Transform : public Group
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
2002-01-29 22:04:06 +08:00
|
|
|
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
|
|
|
{
|
2004-10-25 04:04:00 +08:00
|
|
|
RELATIVE_RF,
|
2007-02-08 00:32:14 +08:00
|
|
|
ABSOLUTE_RF,
|
|
|
|
ABSOLUTE_RF_INHERIT_VIEWPOINT
|
2001-10-11 04:20:14 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +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
|
2004-10-25 04:04:00 +08:00
|
|
|
* frame. RELATIVE_RF is the default.
|
|
|
|
* Note: Setting the ReferenceFrame to be ABSOLUTE_RF will
|
2002-08-05 04:34:48 +08:00
|
|
|
* also set the CullingActive flag on the transform, and hence all
|
|
|
|
* of its parents, to false, thereby disabling culling of it and
|
2007-12-11 01:30:18 +08:00
|
|
|
* all its parents. This is necessary to prevent inappropriate
|
2002-08-05 04:34:48 +08:00
|
|
|
* culling, but may impact cull times if the absolute transform is
|
2004-09-13 23:14:11 +08:00
|
|
|
* deep in the scene graph. It is therefore recommended to only use
|
2002-08-05 04:34:48 +08:00
|
|
|
* absolute Transforms at the top of the scene, for such things as
|
2004-09-13 23:14:11 +08:00
|
|
|
* heads up displays.
|
2007-02-08 00:32:14 +08:00
|
|
|
* ABSOLUTE_RF_INHERIT_VIEWPOINT is the same as ABSOLUTE_RF except it
|
|
|
|
* adds the ability to use the parents view points position in world coordinates
|
|
|
|
* as its local viewpoint in the new coordinates frame. This is useful for
|
2012-03-22 01:36:20 +08:00
|
|
|
* Render to texture Cameras that wish to use the main views LOD range computation
|
2007-02-08 00:32:14 +08:00
|
|
|
* (which uses the viewpoint rather than the eye point) rather than use the local
|
2007-12-11 01:30:18 +08:00
|
|
|
* eye point defined by the this Transforms' absolute view matrix.
|
2005-11-18 01:44:48 +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
|
|
|
void setReferenceFrame(ReferenceFrame rf);
|
2012-03-22 01:36:20 +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
|
|
|
{
|
2004-10-25 04:04:00 +08:00
|
|
|
if (_referenceFrame==RELATIVE_RF)
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
2004-10-25 04:04:00 +08:00
|
|
|
if (_referenceFrame==RELATIVE_RF)
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Overrides Group's computeBound.
|
2002-08-05 04:34:48 +08:00
|
|
|
* There is no need to override in subclasses from osg::Transform
|
|
|
|
* since this computeBound() uses the underlying matrix (calling
|
2004-09-13 23:14:11 +08:00
|
|
|
* computeMatrix if required).
|
2005-11-18 01:44:48 +08:00
|
|
|
*/
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual BoundingSphere computeBound() const;
|
|
|
|
|
|
|
|
protected :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual ~Transform();
|
2012-03-22 01:36:20 +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
|