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-22 05:27:40 +08:00
|
|
|
#include <osg/NodeVisitor>
|
2002-02-11 06:35:22 +08:00
|
|
|
#include <osg/Transform>
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
NodeVisitor::NodeVisitor(TraversalMode tm)
|
|
|
|
{
|
2002-08-12 05:26:58 +08:00
|
|
|
_visitorType = NODE_VISITOR;
|
|
|
|
_traversalNumber = -1;
|
|
|
|
|
|
|
|
_traversalMode = tm;
|
|
|
|
_traversalMask = 0xffffffff;
|
|
|
|
_nodeMaskOverride = 0x0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeVisitor::NodeVisitor(VisitorType type,TraversalMode tm)
|
|
|
|
{
|
|
|
|
_visitorType = type;
|
2001-09-22 10:42:08 +08:00
|
|
|
_traversalNumber = -1;
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
_traversalMode = tm;
|
2001-09-22 10:42:08 +08:00
|
|
|
_traversalMask = 0xffffffff;
|
|
|
|
_nodeMaskOverride = 0x0;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
NodeVisitor::~NodeVisitor()
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
// if (_traversalVisitor) detach from _traversalVisitor;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2002-02-11 06:35:22 +08:00
|
|
|
class TransformVisitor : public NodeVisitor
|
2002-02-06 05:54:46 +08:00
|
|
|
{
|
2002-02-11 06:35:22 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum CoordMode
|
|
|
|
{
|
|
|
|
WORLD_TO_LOCAL,
|
|
|
|
LOCAL_TO_WORLD
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CoordMode _coordMode;
|
|
|
|
Matrix& _matrix;
|
|
|
|
NodeVisitor* _nodeVisitor;
|
|
|
|
|
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
|
|
|
TransformVisitor(Matrix& matrix,CoordMode coordMode,NodeVisitor* nv):
|
2002-02-11 06:35:22 +08:00
|
|
|
NodeVisitor(),
|
|
|
|
_coordMode(coordMode),
|
|
|
|
_matrix(matrix),
|
|
|
|
_nodeVisitor(nv)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void apply(Transform& transform)
|
|
|
|
{
|
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
|
|
|
if (_coordMode==LOCAL_TO_WORLD)
|
2002-02-11 06:35:22 +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
|
|
|
osg::Matrix localToWorldMat;
|
|
|
|
transform.getLocalToWorldMatrix(localToWorldMat,_nodeVisitor);
|
|
|
|
_matrix.preMult(localToWorldMat);
|
|
|
|
}
|
|
|
|
else // worldToLocal
|
|
|
|
{
|
|
|
|
osg::Matrix worldToLocalMat;
|
|
|
|
transform.getWorldToLocalMatrix(worldToLocalMat,_nodeVisitor);
|
|
|
|
_matrix.postMult(worldToLocalMat);
|
2002-02-11 06:35:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool NodeVisitor::getLocalToWorldMatrix(Matrix& matrix, Node* node)
|
2002-02-11 06:35:22 +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
|
|
|
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD,this);
|
2002-02-11 06:35:22 +08:00
|
|
|
for(NodePath::iterator itr=_nodePath.begin();
|
|
|
|
itr!=_nodePath.end();
|
|
|
|
++itr)
|
|
|
|
{
|
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
|
|
|
if (*itr==node) return true; // don't account for matrix attached to specified node
|
2002-02-11 06:35:22 +08:00
|
|
|
(*itr)->accept(tv);
|
|
|
|
}
|
|
|
|
return true;
|
2002-02-06 05:54:46 +08:00
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool NodeVisitor::getWorldToLocalMatrix(Matrix& matrix, Node* node)
|
2002-02-06 05:54:46 +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
|
|
|
TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL,this);
|
2002-02-11 06:35:22 +08:00
|
|
|
for(NodePath::iterator itr=_nodePath.begin();
|
|
|
|
itr!=_nodePath.end();
|
|
|
|
++itr)
|
|
|
|
{
|
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
|
|
|
if (*itr==node) return true; // don't account for matrix attached to specified node
|
2002-02-11 06:35:22 +08:00
|
|
|
(*itr)->accept(tv);
|
|
|
|
}
|
|
|
|
return true;
|
2002-02-06 05:54:46 +08:00
|
|
|
}
|