OpenSceneGraph/include/osg/Transform

155 lines
6.1 KiB
Plaintext
Raw Normal View History

/* -*-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-09-20 05:19:47 +08:00
#ifndef OSG_TRANSFORM
#define OSG_TRANSFORM 1
#include <osg/Group>
#include <osg/Matrix>
#ifndef GL_RESCALE_NORMAL
#define GL_RESCALE_NORMAL 0x803A
#endif
2001-09-20 05:19:47 +08:00
namespace osg {
/** 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);
/** 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 :
2001-09-20 05:19:47 +08:00
Transform();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Transform(const Transform&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, Transform);
2001-09-20 05:19:47 +08:00
virtual Transform* asTransform() { return this; }
virtual const Transform* asTransform() const { return this; }
virtual MatrixTransform* asMatrixTransform() { return 0; }
virtual const MatrixTransform* asMatrixTransform() const { return 0; }
virtual PositionAttitudeTransform* asPositionAttitudeTransform() { return 0; }
virtual const PositionAttitudeTransform* asPositionAttitudeTransform() const { return 0; }
enum ReferenceFrame
{
RELATIVE_TO_PARENTS,
2002-04-12 17:53:39 +08:00
RELATIVE_TO_ABSOLUTE
};
/** 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
* heads up displays. */
void setReferenceFrame(ReferenceFrame rf);
ReferenceFrame getReferenceFrame() const { return _referenceFrame; }
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
{
return false;
}
else // absolute
{
matrix.makeIdentity();
return true;
}
}
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
{
return false;
}
else // absolute
{
matrix.makeIdentity();
return true;
}
}
protected :
virtual ~Transform();
/** 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.) */
virtual bool computeBound() const;
ReferenceFrame _referenceFrame;
2001-09-20 05:19:47 +08:00
};
}
2001-09-20 05:19:47 +08:00
#endif