//! Copy Constructor DVRVolume::DVRVolume(const DVRVolume &source) : Inherited (source), drawStyleListValid(false ), textureManager (this ), shadingInitialized(false ) { SINFO << "DVRVolume::DVRVolume(const DVRVolume &source) this: " << this << std::endl; //!! FIXME: //!! This is only performed during instantiation of real objects //!! Which is only done with the copy constructor //!! //!! Otherwise my code cores - (maybe the copy constructor of FCPtr is //!! broken?!) DVRVolumePtr ptr(*this); // Fake material for render action SimpleMaterialPtr m = SimpleMaterial::create(); beginEditCP(m); { m->setTransparency(0.001f ); m->setLit (false ); m->setDiffuse (Color3f(1.0, 1.0, 1.0)); m->setAmbient (Color3f(1.0, 1.0, 1.0)); } endEditCP(m); // Chunk material as storage fieldcontainer for textures ChunkMaterialPtr cm = SimpleMaterial::create(); // Add all beginEditCP(ptr, RenderMaterialFieldMask | TextureStorageFieldMask); { setRenderMaterial(m ); setTextureStorage(cm); } endEditCP (ptr, RenderMaterialFieldMask | TextureStorageFieldMask); commonConstructor(); }
NodePtr createScenegraph(){ SimpleMaterialPtr simpleMaterial = SimpleMaterial::create(); beginEditCP (simpleMaterial, SimpleMaterial::DiffuseFieldMask | SimpleMaterial::AmbientFieldMask | SimpleMaterial::TransparencyFieldMask); simpleMaterial->setDiffuse(Color3f(1,0,0)); simpleMaterial->setAmbient(Color3f(0.2, 0.2, 0.2)); simpleMaterial->setTransparency(0.5); endEditCP (simpleMaterial, SimpleMaterial::DiffuseFieldMask | SimpleMaterial::AmbientFieldMask | SimpleMaterial::TransparencyFieldMask); NodePtr simpleMaterialNode = Node::create(); NodePtr sphere = makeSphere(2,6); MaterialGroupPtr mg = MaterialGroup::create(); beginEditCP(mg); mg->setMaterial(simpleMaterial); endEditCP(mg); beginEditCP(simpleMaterialNode); simpleMaterialNode->setCore(mg); simpleMaterialNode->addChild(sphere); endEditCP(simpleMaterialNode); NodePtr root = Node::create(); beginEditCP(root); root->setCore(Group::create()); root->addChild(simpleMaterialNode); endEditCP(root); return root; }
NodePtr Puck::init() { // CREATE THE PUCK NodePtr puck_trans_node = makeCoredNode<Transform>(&transPtr); beginEditCP(transPtr); { transPtr->getMatrix().setTranslate(position[0],position[1],position[2]); } endEditCP(transPtr); NodePtr puck = OSG::makeCylinder(PUCK_HALF_HEIGHT*2.0,radius, 32, true, true ,true); beginEditCP(puck_trans_node); { puck_trans_node->addChild(puck); } endEditCP(puck_trans_node); SimpleMaterialPtr puck_mat = SimpleMaterial::create(); beginEditCP(puck_mat); { puck_mat->setAmbient(Color3f(0.0,0.0,0.0)); puck_mat->setDiffuse(Color3f(1.0,0.0,0.0)); } endEditCP(puck_mat); GeometryPtr puck_geo = GeometryPtr::dcast(puck->getCore()); beginEditCP(puck_geo); puck_geo->setMaterial(puck_mat); beginEditCP(puck_geo); ///////////////////////////// // SETUP THE INTERSECTION TEST COMPONENTS // Create a small geometry to show the ray and what was hit // Contains a line and a single triangle. // The line shows the ray, the triangle whatever was hit. isectPoints = GeoPositions3f::create(); beginEditCP(isectPoints); { isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); } endEditCP(isectPoints); GeoIndicesUI32Ptr index = GeoIndicesUI32::create(); beginEditCP(index); { index->addValue(0); index->addValue(1); index->addValue(2); index->addValue(3); index->addValue(4); } endEditCP(index); GeoPLengthsUI32Ptr lens = GeoPLengthsUI32::create(); beginEditCP(lens); { lens->addValue(2); lens->addValue(3); } endEditCP(lens); GeoPTypesUI8Ptr type = GeoPTypesUI8::create(); beginEditCP(type); { type->addValue(GL_LINES); type->addValue(GL_TRIANGLES); } endEditCP(type); SimpleMaterialPtr red = SimpleMaterial::create(); beginEditCP(red); { red->setDiffuse (Color3f( 1,0,0 )); red->setTransparency(0.5); red->setLit (false); } endEditCP (red); testgeocore = Geometry::create(); beginEditCP(testgeocore); { testgeocore->setPositions(isectPoints); testgeocore->setIndices(index); testgeocore->setLengths(lens); testgeocore->setTypes(type); testgeocore->setMaterial(red); } endEditCP(testgeocore); NodePtr testgeo = Node::create(); beginEditCP(testgeo); { testgeo->setCore(testgeocore); } endEditCP(testgeo); beginEditCP(puck_trans_node); { puck_trans_node->addChild(testgeo); } return puck_trans_node; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // GLUT init int winid = setupGLUT(&argc, argv); // the connection between GLUT and OpenSG GLUTWindowPtr gwin= GLUTWindow::create(); gwin->setId(winid); gwin->init(); // Create the Scene NodePtr scene = Node::create(); GroupPtr grcore = Group::create(); beginEditCP(scene); scene->setCore(grcore); // Add a Torus for background scene->addChild(makeTorus(.2, 2, 16, 16)); // The actual creation of the functors is a little complicated. // Mainly because the braindead M$ compiler has problems with, you have to // explicitly create the functor for the right combination of return value // type, number of arguments and argument types (values, pointers, // references, etc.) and whether it is a function, a static method or an // instance method. // Given that the signatures of the draw and volumeUpdate functions are // fixed, the three variants shown here should cover all the bases // Add the DrawFunctor node for standard functions NodePtr df = Node::create(); DrawFunctorCorePtr func = DrawFunctorCore::create(); beginEditCP(func); func->setMaterial(getDefaultUnlitMaterial()); func->setDraw( osgTypedFunctionFunctor1Ptr< Action::ResultE, DrawActionBase >(draw)); func->setVolumeUpdate( osgTypedFunctionVoidFunctor1Ptr< Volume >(volUpdate)); endEditCP(func); beginEditCP(df); df->setCore(func); endEditCP(df); scene->addChild(df); // Some transparent material // Even though the DrawFunctorCore can do any kind of OpenGL functions, the // Material of the Core is used to decide whether the node should be sorted // and rendered last SimpleMaterialPtr transmat = SimpleMaterial::create(); beginEditCP(transmat); transmat->setTransparency(0.1); // The actual value is overriden by the draw // anyway, but it has to be != 0 to be // considered transparent transmat->setLit(false); endEditCP(transmat); // Add the DrawFunctor node for static methods of a class // Static methods are pretty much the same as functions NodePtr dfsm = Node::create(); DrawFunctorCorePtr funcsm = DrawFunctorCore::create(); beginEditCP(funcsm); funcsm->setMaterial(transmat); funcsm->setDraw( osgTypedFunctionFunctor1Ptr< Action::ResultE, DrawActionBase >( &SWrapper::draw)); funcsm->setVolumeUpdate( osgTypedFunctionVoidFunctor1Ptr< Volume >(&SWrapper::volUpdate)); endEditCP(funcsm); beginEditCP(dfsm); dfsm->setCore(funcsm); endEditCP(dfsm); scene->addChild(dfsm); // Add the DrawFunctor node for methods // The functor creation functions need the type of the object for which // methods should be called. Wrapper wrap(Color4f(0,1,0,.3)); NodePtr dfm = Node::create(); DrawFunctorCorePtr funcm = DrawFunctorCore::create(); beginEditCP(funcm); funcm->setMaterial(transmat); funcm->setDraw( osgTypedMethodFunctor1ObjPtr< Action::ResultE, Wrapper, DrawActionBase >( &wrap, &Wrapper::draw)); funcm->setVolumeUpdate( osgTypedMethodVoidFunctor1ObjPtr< Wrapper, Volume >( &wrap, &Wrapper::volUpdate)); endEditCP(funcm); beginEditCP(dfm); dfm->setCore(funcm); endEditCP(dfm); scene->addChild(dfm); // Add a Sphere, just for fun scene->addChild(makeLatLongSphere(16,16,.4)); endEditCP(scene); // create the SimpleSceneManager helper mgr = new SimpleSceneManager; // tell the manager what to manage mgr->setWindow(gwin ); mgr->setRoot (scene); // show the whole scene mgr->showAll(); // GLUT main loop glutMainLoop(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // GLUT init int winid = setupGLUT(&argc, argv); // the connection between GLUT and OpenSG GLUTWindowPtr gwin= GLUTWindow::create(); gwin->setId(winid); gwin->init(); // The scene group NodePtr scene = Node::create(); GroupPtr g = Group::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(g); if(argc < 2) { FWARNING(("No file given!\n")); FWARNING(("Supported file formats:\n")); std::list<const char*> suffixes; SceneFileHandler::the().getSuffixList(suffixes); for(std::list<const char*>::iterator it = suffixes.begin(); it != suffixes.end(); ++it) { FWARNING(("%s\n", *it)); } fileroot = makeTorus(.5, 2, 16, 16); } else { /* All scene file loading is handled via the SceneFileHandler. */ fileroot = SceneFileHandler::the().read(argv[1]); } scene->addChild(fileroot); // Create a small geometry to show the ray and what was hit // Contains a line and a single triangle. // The line shows the ray, the triangle whatever was hit. SimpleMaterialPtr red = SimpleMaterial::create(); beginEditCP(red); { red->setDiffuse (Color3f( 1,0,0 )); red->setTransparency(0.5); red->setLit (false); } endEditCP (red); isectPoints = GeoPositions3f::create(); beginEditCP(isectPoints); { isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); isectPoints->addValue(Pnt3f(0,0,0)); } endEditCP(isectPoints); GeoIndicesUI32Ptr index = GeoIndicesUI32::create(); beginEditCP(index); { index->addValue(0); index->addValue(1); index->addValue(2); index->addValue(3); index->addValue(4); index->addValue(5); index->addValue(6); } endEditCP(index); GeoPLengthsUI32Ptr lens = GeoPLengthsUI32::create(); beginEditCP(lens); { lens->addValue(4); lens->addValue(3); } endEditCP(lens); GeoPTypesUI8Ptr type = GeoPTypesUI8::create(); beginEditCP(type); { type->addValue(GL_LINES); type->addValue(GL_TRIANGLES); } endEditCP(type); testgeocore = Geometry::create(); beginEditCP(testgeocore); { testgeocore->setPositions(isectPoints); testgeocore->setIndices(index); testgeocore->setLengths(lens); testgeocore->setTypes(type); testgeocore->setMaterial(red); } endEditCP(testgeocore); NodePtr testgeo = Node::create(); beginEditCP(testgeo); { testgeo->setCore(testgeocore); } endEditCP(testgeo); scene->addChild(testgeo); endEditCP(scene); // create the SimpleSceneManager helper mgr = new SimpleSceneManager; // tell the manager what to manage mgr->setWindow(gwin ); mgr->setRoot (scene); // show the whole scene mgr->showAll(); mgr->getCamera()->setNear(mgr->getCamera()->getNear() / 10); // Show the bounding volumes? Not for now mgr->getAction()->setVolumeDrawing(false); // GLUT main loop glutMainLoop(); return 0; // GLUT main loop glutMainLoop(); return 0; }