[osg-users] RE : Re: Converting a Drawable object to a Geometry object

Franclin Foping fsfoping at yahoo.fr
Wed Jul 30 17:38:20 PDT 2008


Hi Ulrich,
 I am not sure if you have understood the code snippet I provided. I am also unsure about your C++ knowledge but I think it is better than mine. 
 From the code (and the title of the post), it is easy to see that I am downcasting from a Drawable object to a Geometry one. The shapeDrawable is stuck to the Geode, which is not a concern here. 
 Downcasting from a derived class to a parent class is possible with the dynamic_cast operator. From what you have written in your mail, it looks like the snippet won't compile at all, I can bet something it will as I tried it a couple of hours ago. Try it yourself and let me know.
 My concern in this post is not about shapedrawable. 
 Of course, downcasting from shapedrawable to geometry would have not worked and even worse would have not compiled at all. 
 Please have a look again at my mail and get back to me. I am sure you can find out what is going on. 
 Regards,
 Franclin.
 
Ulrich Hertlein <u.hertlein at sandbox.de> a écrit : Franclin Foping wrote:
>  I would like to turn a Drawable object into a Geometry counterpart in 
> order to retrieve its texture coordinates.
>  I have tried to use both the asGeometry method of the Drawable class 
> and the dynamic cast operator but both attempts ended up delivering a 
> NULL pointer. I am not sure if there is another way of doing it.
> Here is a code snippet.
> osg::Geode myGeode = new osg::Geode;
>  myGeode->addDrawable(new osg::ShapeDrawable(new 
> osg::Box(osg::Vec3(),1,1,1)));
> osg::Drawable* myDrawable = myGeode->getDrawable(0);
> osg::Geometry* myGeom = myDrawable->asGeometry(); //This returns NULL!
> osg::Geometry*  myGeom2 = dynamic_cast(myDrawable);
> Unfortunately both  myGeom and myGeom3 are both NULL at this point.

Sorry, but what you're trying to do is impossible, the class hierarchy isn't 
setup that way.

What you have is:
- ShapeDrawable is-a Drawable, and
- Geometry is-a Drawable

and what you're attempting is to cast a ShapeDrawable to a Geometry.  This can 
never work since they don't have a parent-child relationship.  The fact that 
they're both derived from Drawable is irrelevant for what you're attempting.

Cheers!
/ulrich
_______________________________________________
osg-users mailing list
osg-users at lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


       
---------------------------------
 Envoyé avec Yahoo! Mail.
Une boite mail plus intelligente. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080731/95b8dd62/attachment-0003.htm>


More information about the osg-users mailing list