diff --git a/include/osg/Drawable b/include/osg/Drawable index 000f75ecc..50de0d3cc 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -21,6 +21,7 @@ class Vec3; class Vec4; class UByte4; class Node; +class Geometry; // this is define to alter the way display lists are compiled inside the // the draw method, it has been found that the NVidia drivers fail completely @@ -49,6 +50,12 @@ class SG_EXPORT Drawable : public Object virtual const char* libraryName() const { return "osg"; } virtual const char* className() const { return "Drawable"; } + /** convert 'this' into a Geometry pointer if Drawable is a Geometry, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual Geometry* asGeometry() { return 0; } + /** convert 'const this' into a const Geometry pointer if Drawable is a Geometry, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const Geometry* asGeometry() const { return 0; } /** A vector of osg::Node pointers which is used to store the parent(s) of drawable.*/ typedef std::vector ParentList; diff --git a/include/osg/Geometry b/include/osg/Geometry index 2f88af572..0030bd8c8 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -30,6 +30,9 @@ class SG_EXPORT Geometry : public Drawable virtual const char* libraryName() const { return "osg"; } virtual const char* className() const { return "Geometry"; } + virtual Geometry* asGeometry() { return this; } + virtual const Geometry* asGeometry() const { return this; } + enum AttributeBinding { BIND_OFF=0, diff --git a/include/osg/Group b/include/osg/Group index 31e7a0862..567654168 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -27,6 +27,9 @@ class SG_EXPORT Group : public Node META_Node(osg, Group); + virtual Group* asGroup() { return this; } + virtual const Group* asGroup() const { return this; } + virtual void traverse(NodeVisitor& nv); /** Add Node to Group. diff --git a/include/osg/Node b/include/osg/Node index 81fe3a0f4..f0c6b12f7 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -17,6 +17,7 @@ namespace osg { class NodeVisitor; class Group; +class Transform; /** META_Node macro define the standard clone, isSameKindAs, className * and accept methods. Use when subclassing from Node to make it @@ -60,6 +61,20 @@ class SG_EXPORT Node : public Object /** return the name of the node's class type.*/ virtual const char* className() const { return "Node"; } + /** convert 'this' into a Group pointer if Node is a Group, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual Group* asGroup() { return 0; } + /** convert 'const this' into a const Group pointer if Node is a Group, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const Group* asGroup() const { return 0; } + + /** convert 'this' into a Transform pointer if Node is a Transform, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual Transform* asTransform() { return 0; } + /** convert 'const this' into a const Transform pointer if Node is a Transform, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const Transform* asTransform() const { return 0; } + /** Visitor Pattern : calls the apply method of a NodeVisitor with this node's type.*/ virtual void accept(NodeVisitor& nv); /** Traverse upwards : calls parents' accept method with NodeVisitor.*/ diff --git a/include/osg/Transform b/include/osg/Transform index 7784900b1..6841535d5 100644 --- a/include/osg/Transform +++ b/include/osg/Transform @@ -45,6 +45,9 @@ class SG_EXPORT Transform : public Group META_Node(osg, Transform); + virtual Transform* asTransform() { return this; } + virtual const Transform* asTransform() const { return this; } + enum ReferenceFrame { RELATIVE_TO_PARENTS, diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 10fa9ee79..e6040c1d1 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -229,7 +229,7 @@ bool Group::computeBound() const itr!=_children.end(); ++itr) { - const osg::Transform* transform = dynamic_cast(itr->get()); + const osg::Transform* transform = (*itr)->asTransform(); if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_TO_PARENTS) { bb.expandBy((*itr)->getBound()); @@ -244,7 +244,7 @@ bool Group::computeBound() const itr!=_children.end(); ++itr) { - const osg::Transform* transform = dynamic_cast(itr->get()); + const osg::Transform* transform = (*itr)->asTransform(); if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_TO_PARENTS) { _bsphere.expandRadiusBy((*itr)->getBound());