Hi John,

Also, as a side note, how do I convert osg::Node* to osg::Node&   ?

This is a basic C/C++ programming question. Node* is a pointer-to-Node, and Node& is a reference-to-Node. The quick answer is:

osg::Node* node_pointer = new osg::Node;
osg::Node& node_reference = *node_pointer;
osg::Node* other_node_pointer = &node_reference;

On line 2, * is "dereference" which dereferences a pointer.
On line 3, & is "address-of" which returns the address of a variable (which you can store in a pointer). The new on line 1 allocates memory for an object of the size of the Node class, calls its constructors, and returns the address of that new instance.

But be careful not to dereference a null or uninitialized pointer:

osg::Node* uninitialized_node;
osg::BoundingSphere bs1 = uninitialized_node->getBound();  // crash
osg::Node& uninitialized_node_reference = *uninitialized_node;
osg::BoundingSphere bs2 = node.getBound();  // crash

osg::Node* null_node = NULL;    // or = 0
osg::BoundingSphere bs3 = null_node->getBound();  // crash
osg::Node& null_node_reference = *null_node;  // crash
osg::BoundingSphere bs4 = null_node_reference.getBound();  // crash

Note above the -> and . operators... var->method() is equivalent to (*var).method(). So . is "call on variable or reference" whereas -> is "dereference and call" or "call method on pointer".

For more details please see a C/C++ textbook... I've already said more than I should have... ;-)

J-S

--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to