Changeset 5920 for OpenSceneGraph/trunk/examples/osgcluster/osgcluster.cpp
- Timestamp:
- 01/05/07 22:19:01 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgcluster/osgcluster.cpp
r5592 r5920 9 9 #include <osgDB/ReadFile> 10 10 11 #include <osg Producer/Viewer>11 #include <osgViewer/Viewer> 12 12 13 13 #include <osg/Quat> 14 14 #include <osg/io_utils> 15 16 #include <iostream> 15 17 16 18 #if defined (WIN32) && !defined(__CYGWIN__) … … 48 50 } 49 51 50 void readEventQueue(osg Producer::Viewer& viewer);51 52 void writeEventQueue(osg Producer::Viewer& viewer);52 void readEventQueue(osgViewer::Viewer& viewer); 53 54 void writeEventQueue(osgViewer::Viewer& viewer); 53 55 54 56 void setMasterKilled(const bool flag) { _masterKilled = flag; } … … 380 382 }; 381 383 382 void CameraPacket::readEventQueue(osg Producer::Viewer& viewer)384 void CameraPacket::readEventQueue(osgViewer::Viewer& viewer) 383 385 { 384 386 _events.clear(); 385 387 386 viewer.get KeyboardMouseCallback()->copyEventQueue(_events);388 viewer.getEventQueue()->copyEvents(_events); 387 389 388 390 osg::notify(osg::INFO)<<"written events = "<<_events.size()<<std::endl; 389 391 } 390 392 391 void CameraPacket::writeEventQueue(osg Producer::Viewer& viewer)393 void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer) 392 394 { 393 395 osg::notify(osg::INFO)<<"recieved events = "<<_events.size()<<std::endl; 394 396 395 // copy the events to osgProducer style events. 396 viewer.getKeyboardMouseCallback()->appendEventQueue(_events); 397 viewer.getEventQueue()->appendEvents(_events); 397 398 } 398 399 … … 422 423 423 424 // construct the viewer. 424 osgProducer::Viewer viewer(arguments); 425 426 // set up the value with sensible default event handlers. 427 viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 428 429 // get details on keyboard and mouse bindings used by the viewer. 430 viewer.getUsage(*arguments.getApplicationUsage()); 425 osgViewer::Viewer viewer; 431 426 432 427 … … 470 465 return 1; 471 466 } 472 473 467 474 468 // load model. 475 469 osg::ref_ptr<osg::Node> rootnode = osgDB::readNodeFiles(arguments); 476 470 477 478 471 // set the scene to render 479 472 viewer.setSceneData(rootnode.get()); 480 473 474 if (camera_fov>0.0f) 475 { 476 double fovy, aspectRatio, zNear, zFar; 477 viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); 478 479 double original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; 480 std::cout << "setting lens perspective : original "<<original_fov<<" "<<fovy<<std::endl; 481 482 fovy = atan(tan(osg::DegreesToRadians(camera_fov)*0.5)/aspectRatio)*2.0; 483 viewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); 484 485 viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); 486 original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; 487 std::cout << "setting lens perspective : new "<<original_fov<<" "<<fovy<<std::endl; 488 } 489 490 481 491 // create the windows and run the threads. 482 492 viewer.realize(); 483 484 485 // set up the lens after realize as the Producer lens is not set up properly before this.... will need to inveestigate this at a later date.486 if (camera_fov>0.0f)487 {488 float aspectRatio = tan( osg::DegreesToRadians(viewer.getLensVerticalFov()*0.5)) / tan(osg::DegreesToRadians(viewer.getLensHorizontalFov()*0.5));489 float new_fovy = osg::RadiansToDegrees(atan( aspectRatio * tan( osg::DegreesToRadians(camera_fov*0.5))))*2.0f;490 std::cout << "setting lens perspective : original "<<viewer.getLensHorizontalFov()<<" "<<viewer.getLensVerticalFov()<<std::endl;491 viewer.setLensPerspective(camera_fov,new_fovy,1.0f,1000.0f);492 std::cout << "setting lens perspective : new "<<viewer.getLensHorizontalFov()<<" "<<viewer.getLensVerticalFov()<<std::endl;493 }494 493 495 494 … … 509 508 while( !viewer.done() && !masterKilled ) 510 509 { 511 // wait for all cull and draw threads to complete.512 viewer.sync();513 514 510 osg::Timer_t startTick = osg::Timer::instance()->tick(); 515 511 512 viewer.advance(); 513 516 514 // special handling for working as a cluster. 517 515 switch (viewerMode) … … 521 519 522 520 // take camera zero as the guide. 523 osg::Matrix modelview(viewer.getCamera( 0)->getViewMatrix());521 osg::Matrix modelview(viewer.getCamera()->getViewMatrix()); 524 522 525 523 cp->setPacket(modelview,viewer.getFrameStamp()); … … 572 570 // update the scene by traversing it with the the update visitor which will 573 571 // call all node update callbacks and animations. 574 viewer.update(); 572 viewer.eventTraversal(); 573 viewer.updateTraversal(); 575 574 576 575 if (viewerMode==SLAVE) … … 579 578 cp->getModelView(modelview,camera_offset); 580 579 581 viewer. setView(modelview);580 viewer.getCamera()->setViewMatrix(modelview); 582 581 } 583 582 584 583 // fire off the cull and draw traversals of the scene. 585 584 if(!masterKilled) 586 viewer. frame();585 viewer.renderingTraversals(); 587 586 588 587 } 589 590 // wait for all cull and draw threads to complete.591 viewer.sync();592 593 // run a clean up frame to delete all OpenGL objects.594 viewer.cleanup_frame();595 596 // wait for all the clean up frame to complete.597 viewer.sync();598 588 599 589 // if we are master clean up by telling all slaves that we're going down.
