int main (int argc, char **argv) { osgInit(argc,argv); // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); // OSG SceneFileHandler::the().print(); // create the graph // beacon for camera and light NodePtr b1n = Node::create(); GroupPtr b1 = Group::create(); beginEditCP(b1n); b1n->setCore( b1 ); endEditCP(b1n); // transformation NodePtr t1n = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1n); t1n->setCore( t1 ); t1n->addChild( b1n ); endEditCP(t1n); cam_trans = t1; // light NodePtr dlight = Node::create(); DirectionalLightPtr dl = DirectionalLight::create(); beginEditCP(dlight); dlight->setCore( dl ); endEditCP(dlight); beginEditCP(dl); dl->setAmbient( .3, .3, .3, 1 ); dl->setDiffuse( 1, 1, 1, 1 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); endEditCP(dl); // root root = Node::create(); GroupPtr gr1 = Group::create(); beginEditCP(root); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); endEditCP(root); // Load the file NodePtr file = NullFC; if ( argc > 1 ) file = SceneFileHandler::the().read(argv[1]); if ( file == NullFC ) { std::cerr << "Couldn't load file, ignoring" << std::endl; file = makeTorus( .5, 2, 16, 16 ); } file->updateVolume(); Vec3f min,max; file->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; beginEditCP(dlight); dlight->addChild( file ); endEditCP(dlight); std::cerr << "Tree: " << std::endl; // root->dump(); // Camera cam = PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( deg2rad( 90 ) ); cam->setNear( 0.1 ); cam->setFar( 10000 ); // Background SolidBackgroundPtr bkgnd = SolidBackground::create(); // Foreground GrabForegroundPtr fgnd = GrabForeground::create(); image = Image::create(); beginEditCP(image); image->set(Image::OSG_RGB_PF, 1); endEditCP(image); fgnd->setImage(image); // Viewport vp = Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->editMFForegrounds()->push_back( fgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); // Window std::cout << "GLUT winid: " << winid << std::endl; GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = GLUTWindow::create(); gwin->setId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); win->init(); // Action ract = DrawAction::create(); // tball Vec3f pos( 0, 0, max[2] + ( max[2] - min[2] ) * 1.5 ); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); // run... glutMainLoop(); return 0; }
int main (int argc, char **argv) { osgInit(argc,argv); // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); if ( argc > 1 && isdigit(argv[1][0]) ) { nhviewports = atoi( argv[1] ); argv++; argc--; } if ( argc > 1 && isdigit(argv[1][0]) ) { nvviewports = atoi( argv[1] ); argv++; argc--; } else nvviewports = nhviewports; // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); // OSG SceneFileHandler::the().print(); // create the graph // beacon for camera and light NodePtr b1n = Node::create(); GroupPtr b1 = Group::create(); beginEditCP(b1n); b1n->setCore( b1 ); endEditCP(b1n); // transformation NodePtr t1n = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1n); t1n->setCore( t1 ); t1n->addChild( b1n ); endEditCP(t1n); cam_trans = t1; // light NodePtr dlight = Node::create(); DirectionalLightPtr dl = DirectionalLight::create(); beginEditCP(dlight); dlight->setCore( dl ); endEditCP(dlight); beginEditCP(dl); dl->setAmbient( .3, .3, .3, 1 ); dl->setDiffuse( 1, 1, 1, 1 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); endEditCP(dl); // root root = Node::create(); GroupPtr gr1 = Group::create(); beginEditCP(root); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); endEditCP(root); // Load the file NodePtr file = NullFC; if ( argc > 1 ) file = SceneFileHandler::the().read(argv[1]); if ( file == NullFC ) { std::cerr << "Couldn't load file, ignoring" << std::endl; file = makeTorus( .5, 2, 16, 16 ); file = makeBox( 1,1,1, 1,1,1 ); } file->updateVolume(); Vec3f min,max; file->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; beginEditCP(dlight); dlight->addChild( file ); endEditCP(dlight); std::cerr << "Tree: " << std::endl; root->dump(); // Camera cam = PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( deg2rad( 90 ) ); cam->setNear( 0.1 ); cam->setFar( 100 ); // Background #if 1 // doesn't work right now SkyBackgroundPtr sbkgnd = SkyBackground::create(); sbkgnd->editMFSkyColor()->push_back(Color4f(1, 0, 0,0.5)); sbkgnd->editMFSkyAngle()->push_back(Pi / 2); sbkgnd->editMFSkyColor()->push_back(Color4f(0, 1, 0,0.5)); sbkgnd->editMFSkyAngle()->push_back(Pi); sbkgnd->editMFSkyColor()->push_back(Color4f(0, 0, 1,0.5)); #else SolidBackgroundPtr sbkgnd = SolidBackground::create(); sbkgnd->setColor( Color3f(.5, .5, 1) ); #endif // Window std::cout << "GLUT winid: " << winid << std::endl; GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = GLUTWindow::create(); gwin->setId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; // Viewports & Decorators vp = new ViewportPtr [ nhviewports * nvviewports ]; deco = new TileCameraDecoratorPtr [ nhviewports * nvviewports ]; for ( int i = 0; i < nhviewports; i++ ) { for ( int j = 0; j < nvviewports; j++ ) { int ind = i * nvviewports + j; vp[ind] = Viewport::create(); vp[ind]->setBackground( sbkgnd ); vp[ind]->setRoot( root ); vp[ind]->setSize( 1./nhviewports * i,1./nvviewports * j, 1./nhviewports * (i+1),1./nvviewports * (j+1) ); deco[ind] = TileCameraDecorator::create(); deco[ind]->setDecoratee( cam ); deco[ind]->setSize( 1./nhviewports * i,1./nvviewports * j, 1./nhviewports * (i+1),1./nvviewports * (j+1) ); deco[ind]->setFullSize( 800, 800 ); vp[ind]->setCamera( deco[ind] ); // for debugging: vp[ind]->setCamera( cam ); win->addPort( vp[ind] ); } } win->init(); #if 0 // Test write, to check generic access ofstream outFileStream( "test.osg" ); if( !outFileStream ) { std::cerr << "Can not open output stream to file" << std::endl; return -1; } OSGWriter writer( outFileStream, 4 ); writer.write( win ); #endif // Action ract = DrawAction::create(); ract->setFrustumCulling( false ); // tball Vec3f pos( 0, 0, max[2] + ( max[2] - min[2] ) * 1.5 ); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); // run... glutMainLoop(); return 0; }
int main (int argc, char **argv) { osgInit(argc,argv); // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); glEnable( GL_NORMALIZE ); glEnable( GL_DEPTH_TEST ); // OSG // create the graph // beacon for camera and light NodePtr b1n = Node::create(); GroupPtr b1 = Group::create(); beginEditCP(b1n); b1n->setCore( b1 ); endEditCP(b1n); // transformation NodePtr t1n = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1n); t1n->setCore( t1 ); t1n->addChild( b1n ); endEditCP(t1n); cam_trans = t1; // light NodePtr dlight = Node::create(); headlight = DirectionalLight::create(); beginEditCP(dlight); dlight->setCore( headlight ); endEditCP(dlight); beginEditCP(headlight); headlight->setAmbient( .3, .3, .3, 1 ); headlight->setDiffuse( 1, 1, 1, 1 ); headlight->setSpecular( 1, 1, 1, 1 ); headlight->setDirection(0,0,1); headlight->setBeacon( b1n); endEditCP(headlight); // root root = Node::create(); GroupPtr gr1 = Group::create(); beginEditCP(root); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); endEditCP(root); // Create the scene NodePtr sroot = Node::create(); beginEditCP(dlight); dlight->addChild(sroot); endEditCP(dlight); GroupPtr gr = Group::create(); beginEditCP(sroot); sroot->setCore(gr); endEditCP(sroot); // a transform to move it around NodePtr tnode = Node::create(); tr = Transform::create(); beginEditCP(tnode); tnode->setCore( tr ); endEditCP(tnode); beginEditCP(sroot); sroot->addChild(tnode); endEditCP(sroot); // the billboard NodePtr bnode = Node::create(); bill = Billboard::create(); beginEditCP(bnode); bnode->setCore( bill ); endEditCP(bnode); beginEditCP(tnode); tnode->addChild(bnode); endEditCP(tnode); // a geometry to billboard NodePtr geo = makeTorus( .2, 1, 16, 3); beginEditCP(bnode); bnode->addChild( geo ); endEditCP(bnode); // a geometry to lead the render action somewhere else geo = makePlane( 2, 2, 2, 2 ); beginEditCP(sroot); sroot->addChild( geo ); endEditCP(sroot); dlight->updateVolume(); Vec3f min,max; dlight->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; //std::cerr << "Tree: " << std::endl; //root->dump(); // Camera PerspectiveCameraPtr cam = PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( deg2rad( 60 ) ); cam->setNear( .1 ); cam->setFar( 20. ); // Background GradientBackgroundPtr bkgnd = GradientBackground::create(); bkgnd->addLine( Color3f( 0,0,0 ), 0 ); bkgnd->addLine( Color3f( .5,.5,0 ), 0.5 ); bkgnd->addLine( Color3f( .7,.7,1 ), 0.5 ); bkgnd->addLine( Color3f( 0,0,1 ), 1 ); // Viewport ViewportPtr vp = Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); // Window std::cout << "GLUT winid: " << winid << std::endl; GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = GLUTWindow::create(); gwin->setId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); // Actions dact = DrawAction::create(); ract = RenderAction::create(); // tball Vec3f pos(0, 0, max[2] + 1.5 * (max[2] - min[2])); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); tball.setTranslationScale(10.); // run... glutMainLoop(); return 0; }
int main(int argc, char** argv) { std::cout << "osgInit()..." << std::endl; osgInit( argc, argv ); std::cout << "glutInit()..." << std::endl; glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); int winID = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(resize); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glClearColor( .3, .3, .8, 1 ); std::cout << "Creating objects..." << std::endl; //BEACON NodePtr beaconNode = Node::create(); GroupPtr beaconCore = Group::create(); beginEditCP( beaconNode ); beaconNode->setCore( beaconCore ); endEditCP( beaconNode ); /* //LIGHT NodePtr dlightNode = Node::create(); DirectionalLightPtr dlightCore = DirectionalLight::create(); beginEditCP(dlightNode); dlightNode->setCore(dlightCore); endEditCP(dlightNode); beginEditCP(dlightCore); dlightCore->setAmbient( .3, .3, .3, 1 ); dlightCore->setDiffuse( .5, .5, .5, 1 ); dlightCore->setDirection( 0, 0 , 1 ); dlightCore->setBeacon( beaconNode ); endEditCP(dlightCore); */ //TRANSFORM NodePtr transNode = Node::create(); TransformPtr transCore = Transform::create(); beginEditCP( transNode ); transNode->setCore( transCore ); transNode->addChild( beaconNode ); endEditCP( transNode ); cam_trans = transCore; //LOD NodePtr lowDetailNode = makeBox( 1,1,1, 1,1,1 ); GeometryPtr boxCore = GeometryPtr::dcast(lowDetailNode->getCore()); SimpleMaterialPtr lowDetailMat = SimpleMaterial::create(); lowDetailMat->setDiffuse( Color3f( 1,0,0 ) ); lowDetailMat->setAmbient( Color3f( 1,0,0 ) ); boxCore->setMaterial( lowDetailMat ); NodePtr medDetailNode = makeSphere( 1, 1 ); GeometryPtr medSphereCore = GeometryPtr::dcast(medDetailNode->getCore()); SimpleMaterialPtr medDetailMat = SimpleMaterial::create(); medDetailMat->setDiffuse( Color3f( 0,1,0 ) ); medDetailMat->setAmbient( Color3f( 0,1,0 ) ); medSphereCore->setMaterial( medDetailMat ); NodePtr highDetailNode = makeSphere( 2, 1 ); GeometryPtr highSphereCore = GeometryPtr::dcast(highDetailNode->getCore()); SimpleMaterialPtr highDetailMat = SimpleMaterial::create(); highDetailMat->setDiffuse( Color3f( 0,0,1 ) ); highDetailMat->setAmbient( Color3f( 0,0,1 ) ); highDetailMat->setSpecular( Color3f(1, 1, 1) ); highDetailMat->setShininess( 10 ); highSphereCore->setMaterial( highDetailMat ); NodePtr lodNode = Node::create(); DistanceLODPtr lodNodeCore = DistanceLOD::create(); beginEditCP(lodNode); lodNode->setCore(lodNodeCore); lodNode->addChild( highDetailNode ); lodNode->addChild( medDetailNode ); lodNode->addChild( lowDetailNode ); endEditCP(lodNode); beginEditCP(lodNodeCore); lodNodeCore->editSFCenter()->setValue( Pnt3f(0, 0, 2) ); lodNodeCore->editMFRange()->push_back( 4.0 ); lodNodeCore->editMFRange()->push_back( 8.0 ); lodNodeCore->editMFRange()->push_back( 11.0 ); endEditCP(lodNodeCore); //TRANSFORM LOD NodePtr transLODNode = Node::create(); TransformPtr transLODCore = Transform::create(); transMat.setTranslate( 1, -1, -1 ); beginEditCP(transLODCore); transLODCore->editSFMatrix()->setValue( transMat ); endEditCP(transLODCore); beginEditCP( transLODNode ); transLODNode->setCore( transLODCore ); transLODNode->addChild( lodNode ); endEditCP( transLODNode ); //ROOT root = Node::create(); GroupPtr rootCore = Group::create(); beginEditCP(root); root->setCore(rootCore); root->addChild(transNode); root->addChild(transLODNode); endEditCP(root); camera = PerspectiveCamera::create(); beginEditCP(camera); camera->setBeacon( beaconNode ); camera->setFov( deg2rad(90) ); camera->setNear( 0.1 ); camera->setFar( 10000 ); endEditCP(camera); SolidBackgroundPtr background = SolidBackground::create(); viewp = Viewport::create(); beginEditCP(viewp); viewp->setCamera( camera ); viewp->setBackground( background ); viewp->setRoot( root ); viewp->setSize( 0,0, 1,1 ); endEditCP(viewp); GLint glVP[4]; glGetIntegerv( GL_VIEWPORT, glVP ); GLUTWindowPtr gwin = GLUTWindow::create(); gwin->setId(winID); gwin->setSize(glVP[2], glVP[3]); window = gwin; beginEditCP(window); window->addPort( viewp ); window->init(); endEditCP(window); drAct = DrawAction::create(); Vec3f pos( 0, 0, 3 ); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); glutMainLoop(); return 0; }
int main(int argc, char **argv) { for(int i = 0; i < argc; i++) { std::cout << "Param " << i << ":" << argv[i] << std::endl; } OSG::osgInit(argc, argv); const char *inFileName = "tie.bin"; if(argc > 1) inFileName = argv[1]; std::ifstream in(inFileName, std::ios::binary); if(!in) { std::cerr << "ERROR: Cannot open file " << inFileName << "" << std::endl; return -1; } OSG::BINLoader loader(in); loader.read(); in.close(); std::cout << "MAIN: " << getContainerId(loader.getRootNode()) << " is root" << std::endl; // GLUT init glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glDisable(GL_LIGHTING); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glClearColor(0.5, 0.5, 0.5, 1.); // OSG // OSGSceneFileHandler::the().print(); // FhsFile::touch(); // create the graph // beacon for camera and light NodePtr b1n = Node::create(); GroupPtr b1 = Group::create(); beginEditCP(b1n); b1n->setCore(b1); endEditCP(b1n); // transformation NodePtr t1n = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1n); t1n->setCore(t1); t1n->addChild(b1n); endEditCP(t1n); cam_trans = t1; // light NodePtr dlight = Node::create(); headlight = DirectionalLight::create(); beginEditCP(dlight); dlight->setCore(headlight); endEditCP(dlight); beginEditCP(headlight); headlight->setAmbient(.3, .3, .3, 1); headlight->setDiffuse(1, 1, 1, 1); headlight->setSpecular(1, 1, 1, 1); headlight->setDirection(0, 0, 1); headlight->setBeacon(b1n); endEditCP(headlight); // root root = Node::create(); GroupPtr gr1 = Group::create(); beginEditCP(root); root->setCore(gr1); root->addChild(t1n); root->addChild(dlight); endEditCP(root); // Load the file NodePtr fileRoot = Node::create(); // OSGActivateColMatPtr colMat = OSGActivateColMat::create(); GroupPtr gr = Group::create(); beginEditCP(fileRoot); // fileRoot->setCore(colMat); fileRoot->setCore(gr); endEditCP(fileRoot); beginEditCP(dlight); dlight->addChild(fileRoot); endEditCP(dlight); // for(UInt32 numFiles = 1; numFiles < argc; numFiles++) // { // file = SceneFileHandler::the().read(argv[1]); file = loader.getRootNode(); beginEditCP(fileRoot); fileRoot->addChild(file); fileRoot->invalidateVolume(); endEditCP(fileRoot); // } dlight->updateVolume(); Vec3f min, max; dlight->getVolume().getBounds(min, max); std::cout << "Volume: from " << min << " to " << max << std::endl; //std::cerr << "Tree: " << std::endl; //root->dump(); // Camera PerspectiveCameraPtr cam = PerspectiveCamera::create(); cam->setBeacon(b1n); cam->setFov(deg2rad(60)); cam->setNear(1.); cam->setFar(100000.); // Background GradientBackgroundPtr bkgnd = GradientBackground::create(); bkgnd->addLine(Color3f(0, 0, 0), 0); bkgnd->addLine(Color3f(.5, .5, 0), 0.5); bkgnd->addLine(Color3f(.7, .7, 1), 0.5); bkgnd->addLine(Color3f(0, 0, 1), 1); // Viewport ViewportPtr vp = Viewport::create(); vp->setCamera(cam); vp->setBackground(bkgnd); vp->setRoot(root); vp->setSize(0, 0, 1, 1); // Window std::cout << "GLUT winid: " << winid << std::endl; GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv(GL_VIEWPORT, glvp); gwin = GLUTWindow::create(); gwin->setId(winid); gwin->setSize(glvp[2], glvp[3]); win = gwin; win->addPort(vp); // Actions dact = DrawAction::create(); ract = RenderAction::create(); // tball /* Vec3f pos(min[0] + 0.5 * (max[0] - min[0]), min[1] + 0.5 * (max[1] - min[1]), max[2] + 1.5 * (max[2] - min[2])); */ Vec3f pos(0, 0, max[2] + 1.5 * (max[2] - min[2])); tball.setMode(Trackball::OSGObject); tball.setStartPosition(pos, true); tball.setSum(true); tball.setTranslationMode(Trackball::OSGFree); tball.setTranslationScale(10000.); // run... glutMainLoop(); return 0; }
int main (int argc, char **argv) { osgInit(argc,argv); // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize (uiSize, uiSize); glutInitWindowPosition(100,100); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); // OSG SceneFileHandler::the()->print(); // create the graph // beacon for camera and light NodeUnrecPtr b1n = Node::create(); GroupUnrecPtr b1 = Group::create(); b1n->setCore( b1 ); // transformation NodeUnrecPtr t1n = Node::create(); TransformUnrecPtr t1 = Transform::create(); t1n->setCore (t1 ); t1n->addChild(b1n); cam_trans = t1; // light NodeUnrecPtr dlight = Node::create(); DirectionalLightUnrecPtr dl = DirectionalLight::create(); { dlight->setCore(dl); dl->setAmbient( .0, .0, .0, 1 ); dl->setDiffuse( .8, .8, .8, .8 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); } // root root = Node:: create(); GroupUnrecPtr gr1 = Group::create(); root->setCore (gr1 ); root->addChild(t1n ); root->addChild(dlight); // Load the file NodeUnrecPtr file = NULL; if(argc > 1) { file = SceneFileHandler::the()->read(argv[1], NULL); } if(file == NULL) { std::cerr << "Couldn't load file, ignoring" << std::endl; file = makeSphere(4, 20.0); } Thread::getCurrentChangeList()->commitChanges(); file->updateVolume(); Vec3f min,max; file->getVolume().getBounds(min, max); std::cout << "Volume: from " << min << " to " << max << std::endl; scene_trans = Transform::create(); NodeUnrecPtr sceneTrN = Node::create(); sceneTrN->setCore (scene_trans); sceneTrN->addChild(file ); ref_trans = Transform::create(); NodeUnrecPtr refTrN = Node::create(); refTrN->setCore (ref_trans); refTrN->addChild(makeSphere(4, 20.0)); #ifdef OLD_BBQ AlgorithmStageUnrecPtr pAlgoStage = AlgorithmStage::create(); pAlgoStage->setInheritedTarget(true); pAlgoStage->setProjectionMode(AlgorithmStage::Ignore); pAlgoStage->setCopyViewing(true); CallbackAlgorithmUnrecPtr pAlgo = CallbackAlgorithm::create(); pAlgo->setCallback(&terrainRenderCB, ""); pAlgoStage->setAlgorithm(pAlgo); #endif pSource = BbqOutOfCoreDataSource::create(); // pSource->setFilename("data/ps_com.bbq"); pSource->setFilename("data/ps.bbq"); // pSource->setFilename("/home/gerrit/mtmp/ps.bbq"); pSource->setHeightScale (6500.0f); pSource->setHeightOffset (0.0f ); pSource->setSampleSpacing(1.0f ); pTerrain = BbqTerrain::create(); pTerrain->setBeacon (sceneTrN); pTerrain->setDataSource(pSource ); pTerrain->setScreenSpaceError(6.0); NodeUnrecPtr pAlgoNode = Node::create(); pAlgoNode->setCore(pTerrain); dlight->addChild(pAlgoNode); dlight->addChild(sceneTrN); dlight->addChild(refTrN ); OSG::commitChanges(); const BbqDataSourceInformation &tInfo = pSource->getInformation(); fprintf(stderr, "%d %d\n", tInfo.heightSampleCount[0], tInfo.heightSampleCount[1]); fprintf(stderr, "min %f %f\n", tInfo.vOrigin[0], tInfo.vOrigin[1]); fprintf(stderr, "max %f %f\n", tInfo.vOrigin[0] + tInfo.heightSampleCount[0] * tInfo.vPixelSize[0], tInfo.vOrigin[1] + tInfo.heightSampleCount[1] * tInfo.vPixelSize[1]); fprintf(stderr, "ts: %f\n", tInfo.sampleSpacing); fprintf(stderr, "info Bbox min %f %f\n", tInfo.gridBBoxMin[0], tInfo.gridBBoxMin[1]); fprintf(stderr, "info Bbox max %f %f\n", tInfo.gridBBoxMax[0], tInfo.gridBBoxMax[1]); fUnitScale = tInfo.sampleSpacing / tInfo.vPixelSize[0]; fUnitScale1 = tInfo.sampleSpacing / tInfo.vPixelSize[1]; //(- 285.728333 - (170.f * fUnitScale) vUnitOffset[0] = tInfo.gridBBoxMin[0] - (tInfo.vOrigin[0] * fUnitScale); //m4c[3][2] = (-m4c[3][2] - 40.f) * fUnitScale - 285.728333; vUnitOffset[1] = tInfo.gridBBoxMin[1] - (tInfo.vOrigin[1] * fUnitScale1); #if 1 NodeUnrecPtr geoRef = Node::create(); geoRef->setCore(Group::create()); NodeUnrecPtr pEll = Node::create(); MaterialGroupUnrecPtr pEllMatG = MaterialGroup::create(); SimpleMaterialUnrecPtr pEllMat = SimpleMaterial::create(); pEllMat->editDiffuse().setValuesRGB(0.3, 0.3, 0.3); pEllMatG->setMaterial(pEllMat); pEll->setCore(pEllMatG); pEll->addChild(makeLatLongEllipsoid(18, 36, 6378.137 * 0.95, 6356.7523142 * 0.95)); geoRef->addChild(pEll); geoRef->addChild(makeEllipsoidAxis(18, 36, 6378.137 * 1.05, 6356.7523142 * 1.05)); #if 0 NodeUnrecPtr pEllSeg = Node::create(); MaterialGroupUnrecPtr pEllSegMatG = MaterialGroup::create(); SimpleMaterialUnrecPtr pEllSegMat = SimpleMaterial::create(); pEllSegMat->editDiffuse().setValuesRGB(1.0, 0.0, 0.0); pEllSegMatG->setMaterial(pEllSegMat); pEllSeg->setCore(pEllSegMatG); pEllSeg->addChild(makeLatLongEllipsoidSeg(18, 36, 6378.137 * 1.01, 6356.7523142 * 1.01, osgDegree2Rad(-50.f), osgDegree2Rad(165.f), osgDegree2Rad(-35.f), osgDegree2Rad(180.f))); geoRef->addChild(pEllSeg); #endif NodeUnrecPtr pCorner0 = Node::create(); NodeUnrecPtr pCorner1 = Node::create(); NodeUnrecPtr pCorner2 = Node::create(); NodeUnrecPtr pCorner3 = Node::create(); TransformUnrecPtr pCornerTr0 = Transform::create(); TransformUnrecPtr pCornerTr1 = Transform::create(); TransformUnrecPtr pCornerTr2 = Transform::create(); TransformUnrecPtr pCornerTr3 = Transform::create(); pCorner0->setCore(pCornerTr0); pCorner1->setCore(pCornerTr1); pCorner2->setCore(pCornerTr2); pCorner3->setCore(pCornerTr3); pCorner0->addChild(makeLatLongSphere(10, 10, 100.f)); pCorner1->addChild(makeLatLongSphere(10, 10, 100.f)); pCorner2->addChild(makeLatLongSphere(10, 10, 100.f)); pCorner3->addChild(makeLatLongSphere(10, 10, 100.f)); Pnt3f trpos(0.f, 0.f, 0.f); projectPnt(trpos, -50.f, 165, 10); pCornerTr0->editMatrix()[3][0] = trpos[0]; pCornerTr0->editMatrix()[3][1] = trpos[1]; pCornerTr0->editMatrix()[3][2] = trpos[2]; projectPnt(trpos, -35.f, 165, 10); pCornerTr1->editMatrix()[3][0] = trpos[0]; pCornerTr1->editMatrix()[3][1] = trpos[1]; pCornerTr1->editMatrix()[3][2] = trpos[2]; projectPnt(trpos, -50.f, 180, 10); pCornerTr2->editMatrix()[3][0] = trpos[0]; pCornerTr2->editMatrix()[3][1] = trpos[1]; pCornerTr2->editMatrix()[3][2] = trpos[2]; projectPnt(trpos, -35.f, 180, 10); pCornerTr3->editMatrix()[3][0] = trpos[0]; pCornerTr3->editMatrix()[3][1] = trpos[1]; pCornerTr3->editMatrix()[3][2] = trpos[2]; geoRef->addChild(pCorner0); geoRef->addChild(pCorner1); geoRef->addChild(pCorner2); geoRef->addChild(pCorner3); dlight->addChild(geoRef); #endif Pnt3f x1; Pnt3f x2; projectPnt(x1, 170.0, 40.0, 0); projectPnt(x2, 170.000833333333333, 40.0, 0); Vec3f v1 = x1 - x2; fprintf(stderr, "l:%f\n", v1.length()); // Camera cam = PerspectiveCamera::create(); { cam->setBeacon( b1n ); cam->setFov( osgDegree2Rad( 90 ) ); cam->setNear( 0.1 ); cam->setFar( 120000 ); } // Background SolidBackgroundUnrecPtr bkgnd = SolidBackground::create(); { bkgnd->setColor(Color3f(0,0,1)); } // Viewport vp = Viewport::create(); { vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); } // Window GLUTWindowUnrecPtr gwin; GLint glvp[4]; glGetIntegerv(GL_VIEWPORT, glvp); gwin = GLUTWindow::create(); { gwin->setGlutId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); win->init(); } // Action rentravact = RenderAction::create(); rentravact->setFrustumCulling(false); #ifdef OLD_BBQ outOfCoreDataSource_ = new BbqOutOfCoreDataSource(); bool rc = outOfCoreDataSource_->initialize( // "data/ps.bbq", "data/ps_com.bbq", 650.0f, 0.0f, 1.0f ); fprintf(stderr, "ds::init %d\n", rc); const BbqDataSourceInformation &bbqInfo = outOfCoreDataSource_->getInformation(); fprintf(stderr, "%d %d\n", bbqInfo.levelCount, bbqInfo.nodeCount); fprintf(stderr, "%d %d %d\n", bbqInfo.heightTileSize, bbqInfo.heightSampleCount[0], bbqInfo.heightSampleCount[1]); fprintf(stderr, "%f %f %f\n", bbqInfo.heightScale, bbqInfo.heightOffset, bbqInfo.sampleSpacing); const int maxResidentNodeCount = 5000; terrain_ = new BbqTerrainEngine(); rc = terrain_->initialize(outOfCoreDataSource_, maxResidentNodeCount); fprintf(stderr, "t::init %d\n", rc); terrainRenderOptions_.showSkirts = false; terrainRenderOptions_.showSwitchDistance = true; #endif // tball Vec3f pos; pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), min[1] + ((max[1] - min[1]) * 0.5), max[2] + ( max[2] - min[2] ) * 1.5 ); float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6; Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); fprintf(stderr, "Startpos : %f %f %f\n", pos[0], pos[1], pos[2]); tball.setMode (Trackball::OSGObject); tball.setStartPosition (pos, true ); tball.setSum (true ); tball.setTranslationMode (Trackball::OSGFree ); tball.setTranslationScale(scale * 400 ); tball.setRotationCenter (tCenter ); tScale = scale * 400; fprintf(stderr, "tscale %f\n", tScale); // pos.setValues(0, 400, 0); projectPnt(pos, -42.5, 172.5, 10); tCenter.setValues(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); fprintf(stderr, "Startpos : %f %f %f\n", pos[0], pos[1], pos[2]); tcamball.setMode (Trackball::OSGObject); tcamball.setStartPosition (pos, true ); tcamball.setSum (true ); tcamball.setTranslationMode (Trackball::OSGFree ); tcamball.setTranslationScale(100 ); tcamball.setRotationCenter (tCenter ); m1c.setIdentity(); m1c[3][1] = 5000; m4c.setIdentity(); m4c[3][1] = 5000; pActiveTBall = &tball; commitChanges(); // run... glutMainLoop(); return 0; }
void key(unsigned char key, int x, int y) { switch(key) { case 27: win = NULL; rentravact = NULL; root = NULL; file = NULL; cam = NULL; vp = NULL; win = NULL; cam_trans = NULL; scene_trans = NULL; osgExit(); exit(0); case 'a': glDisable( GL_LIGHTING ); std::cerr << "Lighting disabled." << std::endl; break; case 's': glEnable( GL_LIGHTING ); std::cerr << "Lighting enabled." << std::endl; break; case 'r': { std::cerr << "Sending ray through " << x << "," << y << std::endl; Line l; cam->calcViewRay( l, x, y, *vp ); std::cerr << "From " << l.getPosition() << ", dir " << l.getDirection() << std::endl; } break; case 'w': bWireframe = !bWireframe; break; case ' ': { Matrix m; Quaternion q; Vec3f v; q = oldq; v = oldv; oldq = tball.getRotation(); oldv = tball.getPosition(); move_obj = ! move_obj; if ( move_obj ) { puts("moving object"); tball.setMode( OSG::Trackball::OSGCamera ); } else { puts("moving camera"); tball.setMode( OSG::Trackball::OSGObject ); } tball.setStartPosition(v, true); tball.setStartRotation(q, true); } break; } }
int doMain(int argc, char **argv) { osgInit(argc,argv); // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); // OSG SceneFileHandler::the()->print(); // create the graph // beacon for camera and light NodeUnrecPtr b1n = Node::create(); GroupUnrecPtr b1 = Group::create(); b1n->setCore( b1 ); // transformation NodeUnrecPtr t1n = Node::create(); TransformUnrecPtr t1 = Transform::create(); t1n->setCore (t1 ); t1n->addChild(b1n); cam_trans = t1; // light NodeUnrecPtr dlight = Node::create(); DirectionalLightUnrecPtr dl = DirectionalLight::create(); { dlight->setCore(dl); dl->setAmbient( .0, .0, .0, 1 ); dl->setDiffuse( .8, .8, .8, .8 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); } // root root = Node:: create(); GroupUnrecPtr gr1 = Group::create(); root->setCore (gr1 ); root->addChild(t1n ); root->addChild(dlight); // Load the file NodeUnrecPtr file = NULL; #if 0 if(argc > 1) { file = SceneFileHandler::the()->read(argv[1], NULL); } #endif if(file == NULL) { #if 0 std::cerr << "Couldn't load file, ignoring" << std::endl; NodeUnrecPtr geoRef = Node::create(); geoRef->setCore(Group::create()); NodeUnrecPtr pEll = Node::create(); MaterialGroupUnrecPtr pEllMatG = MaterialGroup::create(); SimpleMaterialUnrecPtr pEllMat = SimpleMaterial::create(); pEllMat->editDiffuse().setValuesRGB(0.3, 0.3, 0.3); pEllMatG->setMaterial(pEllMat); pEll->setCore(pEllMatG); pEll->addChild(makeLatLongEllipsoid(18, 36, 6378137. * 0.95, 6356752.3142 * 0.95)); geoRef->addChild(pEll); geoRef->addChild(makeEllipsoidAxis(18, 36, 6378137. * 1.05, 6356752.3142 * 1.05)); file = geoRef; //makeSphere(4, 2.0); #endif file = makeSphere(4, 2.0); } Thread::getCurrentChangeList()->commitChanges(); file->updateVolume(); Vec3f min,max; file->getVolume().getBounds(min, max); std::cout << "Volume: from " << min << " to " << max << std::endl; /* min[0] = -500; min[1] = 0; min[2] = -500; max[0] = 500; max[1] = 100; max[2] = 500; */ scene_trans = Transform::create(); NodeUnrecPtr sceneTrN = Node::create(); sceneTrN->setCore (scene_trans); sceneTrN->addChild(file ); AlgorithmStageUnrecPtr pAlgoStage = AlgorithmStage::create(); pAlgoStage->setInheritedTarget(true); pAlgoStage->setProjectionMode (AlgorithmStage::Ignore); pAlgoStage->setCopyViewing (true); CallbackAlgorithmUnrecPtr pAlgo = CallbackAlgorithm::create(); pAlgo->setCallback(&terrainRenderCB, ""); pAlgoStage->setAlgorithm(pAlgo); NodeUnrecPtr pAlgoNode = Node::create(); pAlgoNode->setCore(pAlgoStage); sceneTrN->addChild(pAlgoNode); dlight->addChild(sceneTrN); // Camera cam = PerspectiveCamera::create(); { cam->setBeacon( b1n ); cam->setFov( osgDegree2Rad( 90 ) ); cam->setNear( 1000 ); cam->setFar( 100000000 ); } // Background SolidBackgroundUnrecPtr bkgnd = SolidBackground::create(); { bkgnd->setColor(Color3f(0,0,1)); } // Viewport vp = Viewport::create(); { vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); } // Window GLUTWindowUnrecPtr gwin; GLint glvp[4]; glGetIntegerv(GL_VIEWPORT, glvp); gwin = GLUTWindow::create(); { gwin->setGlutId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); win->init(); } // Action rentravact = RenderAction::create(); rentravact->setFrustumCulling(false); int cols = 1; int rows = 1; terrain = new miniload(); terrain->configure_mipmaps(0); terrain->setloader(hw_request_callback, NULL); #if 1 static const char *abasepath1 = "/home/gerrit/SoftwareBuild/Hawaii/data/HawaiiTileset/tiles"; static const char *abasepath2 = "/home/gerrit/SoftwareBuild/Hawaii/data/HawaiiTileset/landsat"; static const float viewx = 0.f; //-560309.0f; static const float viewy = 0.f; //72234.0f; // vertical exaggeration static const float exaggeration=1.5f; // exaggeration=150% float tscale = 1.f; //00.0f; // 1:100 // number of columns and rows cols = 32; rows = 24; // approximate value of one arc-second in meters static float arcsec[3]; // resampling output parameters static float outparams[5]; std::string szTilePath; std::string szLandSatPath; if(argc > 1) { fprintf(stderr, "loading from %s\n", argv[1]); szTilePath .assign(argv[1]); szLandSatPath.assign(argv[1]); szTilePath += "/data/HawaiiTileset/tiles"; szLandSatPath += "/data/HawaiiTileset/landsat"; abasepath1 = szTilePath .c_str(); abasepath2 = szLandSatPath.c_str(); } // load resampled tiles terrain->load(cols,rows, // number of columns and rows abasepath1, abasepath2, NULL, // directories for tiles and textures (and no fogmaps) -viewx,-viewy, // horizontal offset in arc-seconds 0.0f, // no vertical offset 1.0f,1.0f,1.0f, // no horizontal stretching exaggeration,tscale, // vertical exaggeration and global scale 0.0f,0.0f, // no fog parameters required 0.0f, // choose default minimum resolution 0.0f, // disable base offset safety outparams, // geometric output parameters arcsec); // one arcsec in meters #endif #if 1 fprintf(stderr, "%f %f %f\n", terrain->getminitile()->getcenterx(), terrain->getminitile()->getcentery(), terrain->getminitile()->getcenterz()); fprintf(stderr, "%f %f \n", terrain->getminitile()->getsizex(), terrain->getminitile()->getsizez()); #endif max[0] = terrain->getminitile()->getcenterx(); max[1] = terrain->getminitile()->getcentery(); max[2] = terrain->getminitile()->getcenterz(); min[0] = terrain->getminitile()->getcenterx() - (terrain->getminitile()->getsizex() / 2.f); min[1] = terrain->getminitile()->getcentery(); min[2] = terrain->getminitile()->getcenterz() - (terrain->getminitile()->getsizez() / 2.f); // tball Vec3f pos; pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), min[1] + ((max[1] - min[1]) * 0.5), max[2] + ( max[2] - min[2] ) * 1.5 ); float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6; //scale = 100; Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); fprintf(stderr, "Startpos : %f %f %f\n", pos[0], pos[1], pos[2]); fprintf(stderr, "tcenter : %f %f %f\n", tCenter[0], tCenter[1], tCenter[2]); tball.setMode (Trackball::OSGObject); tball.setStartPosition (pos, true ); tball.setSum (true ); tball.setTranslationMode (Trackball::OSGFree ); tball.setTranslationScale(scale ); tball.setRotationCenter (tCenter ); return 0; }
int main( int argc, char **argv ) { Int32 i, retVal; // OSG init osgInit(argc, argv); basetime = getSystemTime(); gThreadManager = ThreadManager::the(); SceneFileHandler::the().print(); // create the graph // beacon for camera and light NodePtr b1n = Node::create(); GroupPtr b1 = Group::create(); beginEditCP(b1n); b1n->setCore( b1 ); endEditCP(b1n); // transformation NodePtr t1n = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1n); t1n->setCore( t1 ); t1n->addChild( b1n ); endEditCP(t1n); cam_trans = t1; // light NodePtr dlight = Node::create(); DirectionalLightPtr dl = DirectionalLight::create(); beginEditCP(dlight); dlight->setCore( dl ); endEditCP(dlight); beginEditCP(dl); dl->setAmbient( .3, .3, .3, 1 ); dl->setDiffuse( 1, 1, 1, 1 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); endEditCP(dl); // root root = Node::create(); GroupPtr gr1 = Group::create(); beginEditCP(root); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); endEditCP(root); // Load the file NodePtr file = NullFC; if ( argc > 1 ) file = SceneFileHandler::the().read(argv[1]); if ( file == NullFC ) { std::cerr << "Couldn't load file, ignoring" << std::endl; file = makePlane( 2,2,2,2 ); } file->updateVolume(); Vec3f min,max; file->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; beginEditCP(dlight); dlight->addChild( file ); endEditCP(dlight); std::cerr << "Tree: " << std::endl; root->dump(); // Camera PerspectiveCameraPtr cam = PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( deg2rad( 60 ) ); cam->setNear( 0.1 ); cam->setFar( 10000 ); // Background GradientBackgroundPtr bkgnd = GradientBackground::create(); bkgnd->addLine( Color3f( 0,0,0 ), 0 ); bkgnd->addLine( Color3f( 0,0,1 ), 0 ); // Action // QT init QApplication::setColorSpec( QApplication::CustomColor ); a = new QApplication( argc, argv ); if ( !QGLFormat::hasOpenGL() ) { qWarning( "This system has no OpenGL support. Exiting." ); return -1; } Vec3f pos( 0, 0, max[2] + ( max[2] - min[2] ) * 1.5 ); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); // Create Windows QGLFormat::setDefaultFormat(QGLFormat(QGL::DirectRendering | QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba )); for ( i = 0; i < NUM_THREADS; i++ ) { glWidget[i] = new MyOSGQGLWidget(); // Viewport vp = Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); glWidget[i]->_osgWin = QTWindow::create(); glWidget[i]->_osgWin->setGlWidget( glWidget[i] ); glWidget[i]->_osgWin->addPort( vp ); glWidget[i]->_osgWin->init(); if ( i == 0 ) { a->setMainWidget( glWidget[0] ); } glWidget[i]->show(); } for (i = 0; i < NUM_THREADS; i++) { drawThread[i] = dynamic_cast<Thread *>(gThreadManager->getThread(NULL)); if ( drawThread[i] != NULL ) { drawThreadID[i] = i; drawThread[i]->runFunction( drawThreadProc, 0, (void *) &(drawThreadID[i]) ); } } drawBarrier = gThreadManager->getBarrier( "drawBarrier" ); // glWidget[0]->paintGL(); retVal = a->exec(); // execute QT main loop // stop th ethreads for ( i=0; i<NUM_THREADS; i++ ) glWidget[i]->_stop = true; drawBarrier->enter( NUM_THREADS + 1 ); for ( i=0; i<NUM_THREADS; i++ ) Thread::join( drawThread[i] ); return (retVal); }
int main (int argc, char **argv) { osgInit(argc,argv); FieldContainerPtr pProto = Geometry::getClassType().getPrototype(); GeometryPtr pGeoProto = GeometryPtr::dcast(pProto); if(pGeoProto != NullFC) { pGeoProto->setDlistCache(false); } // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); // glEnable( GL_LIGHT0 ); glEnable(GL_NORMALIZE); // OSG SceneFileHandler::the().print(); // create the graph // beacon for camera and light NodePtr b1n = Node::create(); GroupPtr b1 = Group::create(); beginEditCP(b1n); b1n->setCore( b1 ); endEditCP(b1n); // transformation NodePtr t1n = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1n); t1n->setCore( t1 ); t1n->addChild( b1n ); endEditCP(t1n); cam_trans = t1; // light //#define OSG_HLIGHT NodePtr dlight = Node::create(); #ifdef OSG_HLIGHT DirectionalLightPtr dl = DirectionalLight::create(); #else GroupPtr dl = Group::create(); #endif beginEditCP(dlight); dlight->setCore( dl ); endEditCP(dlight); #ifdef OSG_HLIGHT beginEditCP(dl); dl->setAmbient( .2, .2, .2, 1 ); dl->setDiffuse( .8, .8, .8, 1 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); endEditCP(dl); #endif // root root = Node::create(); GroupPtr gr1 = Group::create(); beginEditCP(root); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); endEditCP(root); // Load the file NodePtr file = NullFC; /* if ( argc > 1 ) file = SceneFileHandler::the().read(argv[1]); if ( file == NullFC ) { cerr << "Couldn't load file, ignoring" << endl; file = makeTorus( .5, 2, 16, 16 ); } */ VRMLLoader *pFile = new VRMLLoader; pFile->scanFile(argv[1], 0); VRMLToOSGAction aVRMLToOSG; FieldContainerPtr pFC = NullFC; VRMLBindings::NodeBinderPtr pNodeBinder = NULL; fprintf(stderr, "Resnode %p\n", pFile->getFileTree()); aVRMLToOSG.setNameNodeMap(pFile->getNameNodeMap()); aVRMLToOSG.setDataTransferMode(VRMLToOSGAction::SwapData); aVRMLToOSG.apply(pFile->getFileTree()); /* pNodeBinder = (pFile->getFileTree())->getBinder(); if(pNodeBinder != NULL) { pFC = pNodeBinder->getFCPtr(); if(pFC != NullFC) { file = NodePtr::dcast(pFC); } else { fprintf(stderr, "FCPtr NULL\n"); } } else { fprintf(stderr, "Binder NULL\n"); } */ file = aVRMLToOSG.getRoot(); if(file == NullFC) return 0; file->updateVolume(); Vec3f min,max; file->getVolume().getBounds( min, max ); cout << "Volume: from " << min << " to " << max << endl; beginEditCP(dlight); dlight->addChild( file ); endEditCP(dlight); cerr << "Tree: " << endl; // root->dump(); // Camera cam = PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( deg2rad( 90 ) ); cam->setNear( 0.1 ); cam->setFar( 10000 ); // Background SolidBackgroundPtr bkgnd = SolidBackground::create(); // Viewport vp = Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); // Window cout << "GLUT winid: " << winid << endl; GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = GLUTWindow::create(); gwin->setId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); win->init(); // Action ract = DrawAction::create(); // tball Vec3f pos(min[0] + ((max[0] - min[0]) * 0.5), min[1] + ((max[1] - min[1]) * 0.5), max[2] + ( max[2] - min[2] ) * 1.5 ); float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6; Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); tball.setTranslationScale(scale); tball.setRotationCenter(tCenter); // run... #ifdef PAR_SCHEDULER Thread::getCurrent()->getChangeList()->applyTo(1); VSC::VSCScheduler::the()->run(); #endif glutMainLoop(); return 0; }
int main (int argc, char **argv) { osgInit(argc,argv); // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); // OSG SceneFileHandler::the().print(); // create the graph // beacon for camera and light NodePtr b1n = Node::create(); GroupPtr b1 = Group::create(); beginEditCP(b1n); b1n->setCore( b1 ); endEditCP(b1n); // transformation NodePtr t1n = Node::create(); TransformPtr t1 = Transform::create(); beginEditCP(t1n); t1n->setCore( t1 ); t1n->addChild( b1n ); endEditCP(t1n); cam_trans = t1; // light NodePtr dlight = Node::create(); DirectionalLightPtr dl = DirectionalLight::create(); beginEditCP(dlight); dlight->setCore( dl ); endEditCP(dlight); beginEditCP(dl); dl->setAmbient( .3, .3, .3, 1 ); dl->setDiffuse( 1, 1, 1, 1 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); endEditCP(dl); // root root = Node::create(); GroupPtr gr1 = Group::create(); beginEditCP(root); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); endEditCP(root); // Load the file NodePtr file = NullFC; NodePtr file1 = NullFC; if ( argc > 1 ) file1 = SceneFileHandler::the().read(argv[1]); if ( file1 == NullFC ) { std::cerr << "Couldn't load file, ignoring" << std::endl; file1 = makeTorus( .5, 2, 16, 16 ); } file1->updateVolume(); // file->dump(); // subRefCP(file); // return 0; Vec3f min,max; file1->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; file = Node::create(); MaterialGroupPtr testMat = MaterialGroup::create(); SimpleMaterialPtr defaultMaterial = SimpleMaterial::create(); beginEditCP(defaultMaterial); defaultMaterial->setDiffuse(Color3f(1,.0,.0)); defaultMaterial->setAmbient(Color3f(0.1,0.1,0.1)); defaultMaterial->setSpecular(Color3f(1,1,1)); defaultMaterial->setShininess(20); endEditCP (defaultMaterial); testMat->setMaterial(defaultMaterial); beginEditCP(file); { // file->setCore(testMat); file->setCore(Group::create()); file->addChild(file1); } endEditCP (file); scene_trans = Transform::create(); NodePtr sceneTrN = Node::create(); beginEditCP(sceneTrN); { sceneTrN->setCore(scene_trans); sceneTrN->addChild(file); sceneTrN->addChild(makeTorus( .5, 2, 16, 16 )); } endEditCP(sceneTrN); beginEditCP(dlight); dlight->addChild(sceneTrN); endEditCP(dlight); std::cerr << "Tree: " << std::endl; // root->dump(); // Camera cam = PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( deg2rad( 90 ) ); cam->setNear( 0.1 ); cam->setFar( 100000 ); // Background SolidBackgroundPtr bkgnd = SolidBackground::create(); beginEditCP(bkgnd, SolidBackground::ColorFieldMask); bkgnd->setColor(Color3f(1,1,1)); endEditCP(bkgnd, SolidBackground::ColorFieldMask); // Viewport vp = Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); // Window std::cout << "GLUT winid: " << winid << std::endl; GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = GLUTWindow::create(); gwin->setId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); win->init(); // Action ract = DrawAction::create(); renact = RenderAction::create(); // tball Vec3f pos; pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), min[1] + ((max[1] - min[1]) * 0.5), max[2] + ( max[2] - min[2] ) * 1.5 ); float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6; Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); tball.setTranslationScale(scale); tball.setRotationCenter(tCenter); // run... glutMainLoop(); return 0; }
void key(unsigned char key, int x, int y) { switch ( key ) { case 27: osgExit(); exit(0); case 'a': glDisable( GL_LIGHTING ); std::cerr << "Lighting disabled." << std::endl; break; case 's': glEnable( GL_LIGHTING ); std::cerr << "Lighting enabled." << std::endl; break; case 'z': glPolygonMode( GL_FRONT_AND_BACK, GL_POINT); std::cerr << "PolygonMode: Point." << std::endl; break; case 'x': glPolygonMode( GL_FRONT_AND_BACK, GL_LINE); std::cerr << "PolygonMode: Line." << std::endl; break; case 'c': glPolygonMode( GL_FRONT_AND_BACK, GL_FILL); std::cerr << "PolygonMode: Fill." << std::endl; break; case 'r': { std::cerr << "Sending ray through " << x << "," << y << std::endl; Line l; cam->calcViewRay( l, x, y, *vp ); std::cerr << "From " << l.getPosition() << ", dir " << l.getDirection() << std::endl; } break; case ' ': { Matrix m; Quaternion q; Vec3f v; q = oldq; v = oldv; oldq = tball.getRotation(); oldv = tball.getPosition(); move_obj = ! move_obj; if ( move_obj ) { puts("moving object"); // m = scene_trans->getSFMatrix()->getValue(); tball.setMode( OSG::Trackball::OSGCamera ); } else { puts("moving camera"); // m = cam_trans->getSFMatrix()->getValue(); tball.setMode( OSG::Trackball::OSGObject ); } // q.setValue(m); tball.setStartPosition( v, true ); tball.setStartRotation( q, true ); // std::cout << q << std::endl; // std::cout << v << std::endl; // std::cout << " " << m[3][0] << " " << m[3][1] << " " << m[3][2] << std::endl; } break; } }
int main (int argc, char **argv) { osgInit( argc, argv ); glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); int winID = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(resize); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glClearColor( .1, .6, .2, 1 ); //glCullFace( GL_BACK ); //glEnable( GL_CULL_FACE ); //BEACON NodePtr beaconNode = Node::create(); GroupPtr beaconCore = Group::create(); beginEditCP( beaconNode ); beaconNode->setCore( beaconCore ); endEditCP( beaconNode ); //TRANSFORM NodePtr transNode = Node::create(); TransformPtr transCore = Transform::create(); beginEditCP( transNode ); transNode->setCore( transCore ); transNode->addChild( beaconNode ); endEditCP( transNode ); cam_trans = transCore; //OBJECT0: Plane objects[0] = makeBox( 3,3,2, 2,2,1 ); calcFaceNormals( GeometryPtr::dcast(objects[0]->getCore()) ); normals[0] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[0]->getCore()), 0.5 ); //OBJECT1: Sphere objects[1] = makeSphere( 2, 2 ); calcFaceNormals( GeometryPtr::dcast(objects[1]->getCore()) ); normals[1] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[1]->getCore()), 0.5 ); //OBJECT2: Cone objects[2] = makeConicalFrustum( 1.5, 0.75, 2, 8, true, true, true ); calcFaceNormals( GeometryPtr::dcast(objects[2]->getCore()) ); normals[2] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[2]->getCore()), 0.5 ); //OBJECT3: Custom Single Indexed Geometry objects[3] = Node::create(); GeometryPtr obj3Core= Geometry::create(); GeoIndicesUI32Ptr obj3Index = GeoIndicesUI32::create(); GeoPositions3f::PtrType obj3Pnts = GeoPositions3f::create(); GeoColors3f::PtrType obj3Colors = GeoColors3f::create(); GeoPTypesPtr obj3Types = GeoPTypesUI8::create(); GeoPLengthsPtr obj3Lengths = GeoPLengthsUI32::create(); beginEditCP( obj3Pnts ); obj3Pnts->addValue( Pnt3f(0, 0,0) ); obj3Pnts->addValue( Pnt3f(1,-1,0) ); obj3Pnts->addValue( Pnt3f(1, 1,0) ); obj3Pnts->addValue( Pnt3f(1, 1,0) ); obj3Pnts->addValue( Pnt3f(1,-1,0) ); obj3Pnts->addValue( Pnt3f(3,-1.3,0) ); obj3Pnts->addValue( Pnt3f(3, 1.3,0) ); obj3Pnts->addValue( Pnt3f(3, 1.3,0) ); obj3Pnts->addValue( Pnt3f(3,-1.3,0) ); obj3Pnts->addValue( Pnt3f(4, 0,0) ); endEditCP( obj3Pnts ); beginEditCP( obj3Types ); //obj3Types->addValue( GL_TRIANGLES ); //obj3Types->addValue( GL_QUADS ); //obj3Types->addValue( GL_TRIANGLES ); obj3Types->addValue( GL_POLYGON ); endEditCP( obj3Types ); beginEditCP( obj3Lengths ); //obj3Lengths->addValue( 3 ); //obj3Lengths->addValue( 4 ); //obj3Lengths->addValue( 3 ); obj3Lengths->addValue( 6 ); endEditCP( obj3Lengths ); beginEditCP( obj3Colors ); for( UInt32 i=0; i<obj3Pnts->getSize(); ++i ) { obj3Colors->addValue( Color3f(.7,.7,.7) ); } endEditCP( obj3Colors ); beginEditCP( obj3Index ); //for( UInt32 i=0; i<obj3Pnts->getSize(); ++i ) //{ // obj3Index->addValue( i ); //} obj3Index->addValue( 0 ); obj3Index->addValue( 1 ); obj3Index->addValue( 5 ); obj3Index->addValue( 9 ); obj3Index->addValue( 6 ); obj3Index->addValue( 2 ); endEditCP( obj3Index ); beginEditCP( obj3Core ); obj3Core->setIndices( obj3Index ); obj3Core->setPositions( obj3Pnts ); obj3Core->setTypes( obj3Types ); obj3Core->setLengths( obj3Lengths ); obj3Core->setColors( obj3Colors ); endEditCP( obj3Core ); beginEditCP( objects[3] ); objects[3]->setCore( obj3Core ); endEditCP( objects[3] ); calcFaceNormals( GeometryPtr::dcast(objects[3]->getCore()) ); normals[3] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[3]->getCore()), 0.5 ); //ROOT root = Node::create(); GroupPtr rootCore = Group::create(); beginEditCP(root); root->setCore(rootCore); root->addChild(transNode); root->addChild(objects[0]); root->addChild(normals[0]); activeObj = root->findChild( objects[0] ); activeNorm = root->findChild( normals[0] ); endEditCP(root); camera = PerspectiveCamera::create(); camera->setBeacon( beaconNode ); camera->setFov( 90 ); camera->setNear( 0.1 ); camera->setFar( 10000 ); SolidBackgroundPtr background = SolidBackground::create(); viewp = Viewport::create(); viewp->setCamera( camera ); viewp->setBackground( background ); viewp->setRoot( root ); viewp->setSize( 0,0, 1,1 ); GLint glVP[4]; glGetIntegerv( GL_VIEWPORT, glVP ); GLUTWindowPtr gwin = GLUTWindow::create(); gwin->setId(winID); gwin->setSize(glVP[2], glVP[3]); window = gwin; window->addPort( viewp ); window->init(); drAct = DrawAction::create(); Vec3f pos( 0, 0, 3 ); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); glutMainLoop(); return 0; }