Removed dependency of the new osg::DOFTransform and osg::Sequence Node's

on osgUtil by implementing a NodeVisitor::VisitorType enum, and associated
g/setVisitorType.  This allows callbacks to querry the visitor/traversal
type without doing down cast's to specific visitor subclasses such as
osgUtil::AppVisitor/CullVisitor.
This commit is contained in:
Robert Osfield 2002-08-11 21:26:58 +00:00
parent 19eaf17632
commit 7010c1c4f8
7 changed files with 93 additions and 67 deletions

View File

@ -43,15 +43,27 @@ class SG_EXPORT NodeVisitor : public Referenced
{
public:
enum TraversalMode {
enum TraversalMode
{
TRAVERSE_NONE,
TRAVERSE_PARENTS,
TRAVERSE_ALL_CHILDREN,
TRAVERSE_ACTIVE_CHILDREN,
TRAVERSE_VISITOR
};
enum VisitorType
{
NODE_VISITOR = 0,
APP_VISITOR,
COLLECT_OCCLUDER_VISITOR,
CULL_VISITOR
};
NodeVisitor(TraversalMode tm=TRAVERSE_NONE);
NodeVisitor(VisitorType type,TraversalMode tm=TRAVERSE_NONE);
virtual ~NodeVisitor();
/** Method to call to reset visitor. Useful for your visitor accumulates
@ -61,6 +73,14 @@ class SG_EXPORT NodeVisitor : public Referenced
virtual void reset() {}
/** Set the VisitorType, used to distingush different visitors during
* traversal of the scene, typically used in the Node::traverse() method
* to select which behaviour to use for different types of traversal/visitors.*/
inline void setVisitorType(VisitorType type) { _visitorType = type; }
/** Get the VisitorType.*/
inline VisitorType getVisitorType() const { return _visitorType; }
/** Set the traversal number. Typically used to denote the frame count.*/
inline void setTraversalNumber(const int fn) { _traversalNumber = fn; }
@ -187,6 +207,7 @@ class SG_EXPORT NodeVisitor : public Referenced
protected:
VisitorType _visitorType;
int _traversalNumber;
ref_ptr<FrameStamp> _frameStamp;

View File

@ -9,10 +9,9 @@
using namespace osg;
CollectOccludersVisitor::CollectOccludersVisitor()
CollectOccludersVisitor::CollectOccludersVisitor():
NodeVisitor(COLLECT_OCCLUDER_VISITOR,TRAVERSE_ACTIVE_CHILDREN)
{
// overide the default node visitor mode.
setTraversalMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
setCullingMode(VIEW_FRUSTUM_CULLING|
NEAR_PLANE_CULLING|

View File

@ -1,8 +1,5 @@
#include <osg/DOFTransform>
#include <osgUtil/CullVisitor>
#include <osgUtil/AppVisitor>
using namespace osg;
struct DOFCullCallback : public Transform::ComputeTransformCallback
@ -10,36 +7,32 @@ struct DOFCullCallback : public Transform::ComputeTransformCallback
/**/
virtual const bool computeLocalToWorldMatrix(Matrix& matrix, const Transform* trans, NodeVisitor* nv) const
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if(cv)
const DOFTransform* dof = dynamic_cast<const DOFTransform*>(trans);
if(dof)
{
const DOFTransform* dof = dynamic_cast<const DOFTransform*>(trans);
if(dof)
{
//here we are:
//put the PUT matrix first:
Matrix l2w(dof->getPutMatrix());
//here we are:
//put the PUT matrix first:
Matrix l2w(dof->getPutMatrix());
//now the current matrix:
Matrix current;
current.makeTranslate(dof->getCurrentTranslate());
//now the current matrix:
Matrix current;
current.makeTranslate(dof->getCurrentTranslate());
//now create the local rotation:
current.preMult(Matrix::rotate(dof->getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch
current.preMult(Matrix::rotate(dof->getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll
current.preMult(Matrix::rotate(dof->getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading
//now create the local rotation:
current.preMult(Matrix::rotate(dof->getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch
current.preMult(Matrix::rotate(dof->getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll
current.preMult(Matrix::rotate(dof->getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading
//and scale:
current.preMult(Matrix::scale(dof->getCurrentScale()));
//and scale:
current.preMult(Matrix::scale(dof->getCurrentScale()));
l2w.postMult(current);
l2w.postMult(current);
//and impose inverse put:
l2w.postMult(dof->getInversePutMatrix());
//and impose inverse put:
l2w.postMult(dof->getInversePutMatrix());
//finally:
matrix.preMult(l2w);
}
//finally:
matrix.preMult(l2w);
}
return true;
@ -48,38 +41,34 @@ struct DOFCullCallback : public Transform::ComputeTransformCallback
/**/
virtual const bool computeWorldToLocalMatrix(Matrix& matrix, const Transform* trans, NodeVisitor* nv) const
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if(cv)
const DOFTransform* dof = dynamic_cast<const DOFTransform*>(trans);
if(dof)
{
const DOFTransform* dof = dynamic_cast<const DOFTransform*>(trans);
if(dof)
{
//here we are:
//put the PUT matrix first:
Matrix w2l(dof->getInversePutMatrix());
//here we are:
//put the PUT matrix first:
Matrix w2l(dof->getInversePutMatrix());
//now the current matrix:
Matrix current;
current.makeTranslate(-dof->getCurrentTranslate());
//now the current matrix:
Matrix current;
current.makeTranslate(-dof->getCurrentTranslate());
//now create the local rotation:
current.postMult(Matrix::rotate(-dof->getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading
current.postMult(Matrix::rotate(-dof->getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll
current.postMult(Matrix::rotate(-dof->getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch
//now create the local rotation:
//and scale:
current.postMult(Matrix::scale(1./dof->getCurrentScale()[0], 1./dof->getCurrentScale()[1], 1./dof->getCurrentScale()[2]));
w2l.postMult(current);
current.postMult(Matrix::rotate(-dof->getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading
current.postMult(Matrix::rotate(-dof->getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll
current.postMult(Matrix::rotate(-dof->getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch
//and impose inverse put:
w2l.postMult(dof->getPutMatrix());
//and scale:
current.postMult(Matrix::scale(1./dof->getCurrentScale()[0], 1./dof->getCurrentScale()[1], 1./dof->getCurrentScale()[2]));
//finally:
matrix.postMult(w2l);
}
w2l.postMult(current);
//and impose inverse put:
w2l.postMult(dof->getPutMatrix());
//finally:
matrix.postMult(w2l);
}
return true;
@ -91,14 +80,19 @@ class DOFAnimationAppCallback : public osg::NodeCallback
/** Callback method call by the NodeVisitor when visiting a node.*/
virtual void operator()(Node* node, NodeVisitor* nv)
{
//this is aspp visitor, see if we have DOFTransform:
DOFTransform* dof = dynamic_cast<DOFTransform*>(node);
if(dof)
if (nv && nv->getVisitorType()==NodeVisitor::APP_VISITOR)
{
//see if it is ina animation mode:
dof->animate();
}
//this is aspp visitor, see if we have DOFTransform:
DOFTransform* dof = dynamic_cast<DOFTransform*>(node);
if(dof)
{
//see if it is ina animation mode:
dof->animate();
}
}
// note, callback is repsonsible for scenegraph traversal so
// should always include call the traverse(node,nv) to ensure
// that the rest of cullbacks and the scene graph are traversed.
@ -379,4 +373,6 @@ void DOFTransform::animate()
new_value[2] -= _incrementScale[2];
setCurrentScale(new_value);
dirtyBound();
}

View File

@ -6,6 +6,18 @@ using namespace osg;
NodeVisitor::NodeVisitor(TraversalMode tm)
{
_visitorType = NODE_VISITOR;
_traversalNumber = -1;
_traversalVisitor = NULL;
_traversalMode = tm;
_traversalMask = 0xffffffff;
_nodeMaskOverride = 0x0;
}
NodeVisitor::NodeVisitor(VisitorType type,TraversalMode tm)
{
_visitorType = type;
_traversalNumber = -1;
_traversalVisitor = NULL;

View File

@ -2,8 +2,6 @@
#include <osg/Sequence>
#include <osgUtil/AppVisitor>
using namespace osg;
/**
@ -100,8 +98,8 @@ void Sequence::setMode(SequenceMode mode)
void Sequence::traverse(NodeVisitor& nv)
{
osgUtil::AppVisitor* app = dynamic_cast<osgUtil::AppVisitor*>(&nv);
if (app && _mode == START && _nrepsremain) {
if (nv.getVisitorType()==NodeVisitor::APP_VISITOR && _mode == START && _nrepsremain)
{
double t = nv.getFrameStamp()->getReferenceTime();
if (_last == -1.0)
_last = t;

View File

@ -3,7 +3,7 @@
using namespace osg;
using namespace osgUtil;
AppVisitor::AppVisitor():NodeVisitor(TRAVERSE_ACTIVE_CHILDREN)
AppVisitor::AppVisitor():NodeVisitor(APP_VISITOR,TRAVERSE_ACTIVE_CHILDREN)
{
}

View File

@ -75,7 +75,7 @@ class PrintVisitor : public NodeVisitor
};
CullVisitor::CullVisitor():
NodeVisitor(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN),
NodeVisitor(CULL_VISITOR,TRAVERSE_ACTIVE_CHILDREN),
_currentRenderGraph(NULL),
_currentRenderBin(NULL),
_computeNearFar(COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES),