diff --git a/include/osg/Node b/include/osg/Node index 68642bd68..a6d5d1b9e 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -42,6 +42,7 @@ class Node; class Switch; class Geode; class Camera; +class OccluderNode; /** A vector of Nodes pointers which is used to describe the path from a root node to a descendant.*/ typedef std::vector< Node* > NodePath; @@ -132,6 +133,12 @@ class OSG_EXPORT Node : public Object * Equivalent to dynamic_cast(this).*/ virtual const Transform* asTransform() const { return 0; } + /** Convert 'this' into an OccluderNode pointer if Node is an OccluderNode, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual OccluderNode* asOccluderNode() { return 0; } + /** Convert 'const this' into a const OccluderNode pointer if Node is an OccluderNode, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const OccluderNode* asOccluderNode() const { return 0; } /** Convert 'this' into a Switch pointer if Node is a Switch, otherwise return 0. diff --git a/include/osg/OccluderNode b/include/osg/OccluderNode index 40105f8cb..9a2f69d97 100644 --- a/include/osg/OccluderNode +++ b/include/osg/OccluderNode @@ -34,6 +34,12 @@ class OSG_EXPORT OccluderNode : public Group META_Node(osg, OccluderNode); + /** Convert 'this' into an OccluderNode pointer if Node is an OccluderNode, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual OccluderNode* asOccluderNode() { return this; } + /** Convert 'const this' into a const OccluderNode pointer if Node is an OccluderNode, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const OccluderNode* asOccluderNode() const { return this; } /** Attach a ConvexPlanarOccluder to an OccluderNode.*/ void setOccluder(ConvexPlanarOccluder* occluder) { _occluder = occluder; } diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 7b0ba606c..34ccadb76 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -137,7 +137,7 @@ bool Group::insertChild( unsigned int index, Node *child ) } if (child->getNumChildrenWithOccluderNodes()>0 || - dynamic_cast(child)) + child->asOccluderNode()) { setNumChildrenWithOccluderNodes( getNumChildrenWithOccluderNodes()+1 @@ -190,7 +190,7 @@ bool Group::removeChildren(unsigned int pos,unsigned int numChildrenToRemove) if (child->getNumChildrenWithCullingDisabled()>0 || !child->getCullingActive()) ++numChildrenWithCullingDisabledRemoved; - if (child->getNumChildrenWithOccluderNodes()>0 || dynamic_cast(child)) ++numChildrenWithOccludersRemoved; + if (child->getNumChildrenWithOccluderNodes()>0 || child->asOccluderNode()) ++numChildrenWithOccludersRemoved; } @@ -326,12 +326,12 @@ bool Group::setChild( unsigned int i, Node* newNode ) // so need to check and update if required. int delta_numChildrenWithOccluderNodes = 0; if (origNode->getNumChildrenWithOccluderNodes()>0 || - dynamic_cast(origNode.get())) + origNode.get()->asOccluderNode()) { --delta_numChildrenWithOccluderNodes; } if (newNode->getNumChildrenWithOccluderNodes()>0 || - dynamic_cast(newNode)) + newNode->asOccluderNode()) { ++delta_numChildrenWithOccluderNodes; }