void OgreMeshReader::constructMaterial(SubMeshInfo &smInfo) { OSG_OGRE_LOG(("OgreMeshReader::constructMaterial\n")); MaterialMap::const_iterator mmIt = _matMap.find(smInfo.matName); Material *mat = NULL; if(mmIt != _matMap.end()) { mat = (*mmIt).second; } else { SimpleMaterialUnrecPtr newMat = SimpleMaterial::create(); newMat->setDiffuse (Color3f(1.0f, 1.0f, 1.0f)); newMat->setAmbient (Color3f(0.1f, 0.1f, 0.1f)); newMat->setSpecular (Color3f(0.3f, 0.3f, 0.3f)); newMat->setShininess(20.f); setName(newMat, smInfo.matName); _matMap.insert(MaterialMap::value_type(smInfo.matName, newMat)); mat = newMat; } smInfo.mesh->setMaterial(mat); }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); //Torus Material SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create(); TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3)); TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7)); TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0)); TheTorusMaterial->setShininess(20.0); //Torus Geometry GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32); TorusGeometry->setMaterial(TheTorusMaterial); NodeUnrecPtr TorusGeometryNode = Node::create(); TorusGeometryNode->setCore(TorusGeometry); //Make Torus Node NodeUnrecPtr TorusNode = Node::create(); TransformUnrecPtr TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); ComponentTransformUnrecPtr Trans = ComponentTransform::create(); setName(Trans, std::string("MainTransformationCore")); scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TheAnimation.get(), TutorialWindow.get())); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); // tell the manager what to manage sceneManager.setRoot (scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "07AnimationGroup"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }