Switching States with Nodes

classic Classic list List threaded Threaded
4 messages Options
Miles Miles
Reply | Threaded
Open this post in threaded view
|

Switching States with Nodes

I need 3 images (osg::Geometries) representing the different stages of a traffic light: one with the red light on, one with the yellow light on, and the last with the green light on. What is the best method to implement swapping between those images as the traffic light's state changes? I am currently making one a child of a GeoTransform and then replacing child 0 with one of the other states using setChild, but that does not seem like an efficient way to accomplish this. I saw a brief mention of Switch Node, but have not seen an example of how that works to determine if that is what I need. Any recommendations or can someone point me to an example?
Using osgEarth to create a full functioning 3D modelling apparatus for simulation with TBE.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Switching States with Nodes

Miles,
osg::Switch will do the job. Just add all your possible children to it, and then call setSingleChildOn(i) to activate the one you want to see.
Glenn Waldron / Pelican Mapping
Miles Miles
Reply | Threaded
Open this post in threaded view
|

Re: Switching States with Nodes

Awesome. I can use that. Thanks!

I actually had one more question I had meant to ask in conjunction with this one but I forgot. osg::Geometry objects use ColorArrays to set their color. Seeing as you can add multiple different vec4 variables to the vec4Array, is pushing back multiple colors just a way of blending multiple colors together easier or is it possible to push back multiple colors and then use individual ones at certain times? If the latter, how is this done?
Using osgEarth to create a full functioning 3D modelling apparatus for simulation with TBE.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Switching States with Nodes

Miles,

The color array is so you can assign a color to each vertex.

You can configure how the colors are used with the setBinding() call. OVERALL tells it to use the color at array[0] for all vertices. PER_VERTEX means that each vertex has its own color at the corresponding array index. OpenGL will blend colors across the verts at draw time.

Hope this helps.
Glenn Waldron / Pelican Mapping