Hi Tristan, since I was interested in checking out osg::Switch, I
reworked your example to get the result you wanted:
1: changed how models got added to have only 1 enabled at start
2: in the main loop, I changed the logic that does the switch, so it's
only called when needed
I think this could be an ok tutorial for osg::Switch, so if people find
it interesting enough we could submit it.
Regards
Mihai
Tristan McMillan wrote:
Hi
Okay the first was a simple error I agree, but even after changing that
too:
Switchg->insertChild(2,model2Node.get());
Switchg->insertChild(1,model1Node.get());
The scene doesn't alternate between the two models for some reason.
It must be crazy friday or something.
Thanks
Tristan
On Fri, 2006-11-17 at 13:51 +0000, David Spilling wrote:
Firstly, you do this, which I'm sure you don't mean (note the models
you are actually adding).
Switchg->insertChild(2,model2Node.get());
Switchg->insertChild(1,model2Node.get ());
Secondly, you do this, which I'm also sure you don't mean (your temp
counter will flicker between true and false)
if ( counter > 1000)
{
counter = 0;
temp = !temp;
}
else
{
counter++;
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgProducer/Viewer>
int main( int argc, char **argv )
{
osg::Switch *Switchg = new osg::Switch();
osg::ref_ptr<osg::Group> rootNode = new osg::Group();
//osgDB::FilePathList pathList;
//pathList.push_back("/opt/OpenSceneGraph-Data/models/");
//osgDB::setDataFilePathList(pathList);
osg::ref_ptr<osg::Node> model1Node = osgDB::readNodeFile("cow.osg");
if (!model1Node)
{
std::cout << " no model1 " << std::endl;
abort();
}
osg::ref_ptr<osg::Node>model2Node = osgDB::readNodeFile("dumptruck.osg");
if( ! model2Node)
{
std::cout << "no model2Node" << std::endl;
abort();
}
Switchg->addChild(model1Node.get(),true);
Switchg->addChild(model2Node.get(),false);
std::cout << " Children: " <<Switchg->getNumChildren()<<std::endl;
rootNode->addChild(Switchg);
osgProducer::Viewer viewer;
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
viewer.setSceneData( rootNode.get() );
viewer.realize();
int counter = 0;
bool switchModels = false;
int currentModel = 1;
while( !viewer.done() )
{
viewer.sync();
viewer.update();
if ( counter++ > 1000)
{
counter = 0;
switchModels = true;
}
if (switchModels == true )
{
if (currentModel == 1)
{
Switchg->setSingleChildOn(1);
currentModel = 2;
}
else
{
Switchg->setSingleChildOn(0);
currentModel = 1;
}
switchModels = false;
}
std::cout << " Counter: " << counter << " Current child: " <<
currentModel-1 <<" Value: "<< Switchg->getValue(currentModel-1) << std::endl;
// fire off the cull and draw traversals of the scene.
viewer.frame();
}
// wait for all cull and draw threads to complete before exit.
viewer.sync();
return 0;
}_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/