Hello Brian,

I did not understand why down-casting is not possible.  Super class can be
downcasted to a concrete class through dynamic cast,
isnt it?


I am afraid that the discussion is getting a bit off -topic now.

Sajjad

On Thu, Apr 9, 2009 at 3:43 PM, Brian R Hill <bhil...@csc.com> wrote:

> Sajjad,
>
> You can't cast a group to a switch if it wasn't created as a switch.
>
> osg::ref_ptr<osg::Group>  groupOfLights;
>
> This will always fail and return 0.
> osg::Switch * your_switch = dynamic_cast<osg::Switch *>(groupOfLights.get
> ());
>
> You need to create your groupOfLights as a switch.
>
> osg::ref_ptr<osg::Switch>  groupOfLights;
>
> Since a switch is a groud, you can use it as both a group and a switch.
>
> Also, using dynamic_cast isn't bad. There are situations where it might not
> be optimal. But for your intended use - key press events - it's absolutley
> acceptable.
>
> Brian
>
>
> This is a PRIVATE message. If you are not the intended recipient, please
> delete without copying and kindly advise us by e-mail of the mistake in
> delivery.
> NOTE: Regardless of content, this e-mail shall not operate to bind CSC to
> any order or other contract unless pursuant to explicit written agreement
> or government initiative expressly permitting the use of e-mail for such
> purpose. •
>
>
> -----osg-users-boun...@lists.openscenegraph.org wrote: -----
>
>
> To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org>
> From: René Molenaar <megamillerz...@gmail.com>
> Sent by: osg-users-boun...@lists.openscenegraph.org
> Date: 04/09/2009 09:28AM
> Subject: Re: [osg-users] Light Manager
>
> Hi Sajjad,
>
>
> There are asType functions is osg::Node,
> this has better performance then dynamic_cast ...
>
> for example you can do:
>
> osg::ref_ptr<osg::Switch> switch = group->asSwitch();
>
> Now you are using a virtual table to get the right type:
>
> if the object is a Switch you will get the this-pointer of the Switch
> if it is not you will get 0.
>
> Usually there are always better ways then dynamic_cast, especially
> if you are the owner of the code.
>
> Good Luck,
>
> Rene
>
>
>
>
> 2009/4/9 ami guru < dosto.wa...@gmail.com >
>
> Hello Forum,
>
>
> I have a LightManager class that tracks the number of lights(OpenGL Lights)
> that have been created.
>
> Inside the class the have the following member
>
>
>  osg::ref_ptr<osg::Group>  groupOfLights;
>  vector<osg::ref_ptr<osg::LightSource> >   lights;
>
> the member groupOfLights contain the LightSource as child.
>
>
> In the application i want to select different light (spot,point or diffuse)
> with key press event and only one light is enabled during an instant OR i
> may enable several lights.
>
>
> In that case i believe that i have to do dynamic casting to cast Group to
> Switch.
>
> In other better way to do that ?
>
>
>
> Regards
> Sajjad
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to