本文整理汇总了C++中osgviewer::Viewer类的典型用法代码示例。如果您正苦于以下问题:C++ Viewer类的具体用法?C++ Viewer怎么用?C++ Viewer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Viewer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startTiming
/// Utility function you call before something you want to time, so that the
/// recorded times will all be consistent using the viewer's time.
void startTiming(osgViewer::Viewer& viewer, const std::string& name)
{
osg::Timer_t tick = osg::Timer::instance()->tick();
double currentTime = osg::Timer::instance()->delta_s(viewer.getStartTick(), tick);
int framenumber = viewer.getFrameStamp()->getFrameNumber();
viewer.getViewerStats()->setAttribute(framenumber, name + " begin", currentTime);
}
示例2: createProjection
void
viewerSetUp( osgViewer::Viewer& viewer, unsigned int width, unsigned int height, osg::Node* node )
{
double aspect = (double)width / (double)height;
viewer.setThreadingModel( osgViewer::ViewerBase::SingleThreaded );
viewer.getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
viewer.getCamera()->setProjectionMatrix( createProjection( aspect ) );
viewer.getCamera()->setClearMask( 0 );
viewer.setSceneData( backdropFX::Manager::instance()->getManagedRoot() );
// No longer needed, apparently. Seems like Viewer used to focus the
// camera manipulator on the entire SkyDome, putting it too far away from
// the scene. This code compensated for that.
//osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator();
//viewer.setCameraManipulator( tb );
//tb->setNode( root.get() );
//tb->home( 0 );
viewer.addEventHandler( new osgViewer::StatsHandler );
viewer.addEventHandler( new osgViewer::ThreadingHandler );
viewer.addEventHandler( new ResizeHandler( viewer, width, height ) );
osgGA::TrackballManipulator* tbm = new osgGA::TrackballManipulator;
viewer.setCameraManipulator( tbm );
tbm->setNode( node );
tbm->home( 0 );
}
示例3: InitWnd
void InitWnd(osgViewer::Viewer &viewer)
{
int xoffset = 40;
int yoffset = 40;
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = xoffset + 0;
traits->y = yoffset + 0;
traits->width = 600;
traits->height = 480;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer);
//camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
//camera->setClearColor(osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f));
//camera->setProjectionMatrixAsPerspective(
// 30.0f, static_cast<double>(traits->width) / static_cast<double>(traits->height), 1.0, 1000.0);
// add this slave camera to the viewer, with a shift left of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0, 0.0, 0.0), osg::Matrixd());
}
示例4: setViewer
void setViewer(osgViewer::Viewer& viewer, float width, float height, float distance)
{
double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0);
// double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0);
viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0);
}
示例5: writeEventQueue
void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer)
{
osg::notify(osg::INFO)<<"received events = "<<_events.size()<<std::endl;
// copy the events to osgProducer style events.
viewer.getEventQueue()->appendEvents(_events);
}
示例6: addDeviceTo
void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name)
{
osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device_name);
if (dev.valid())
{
OSG_INFO << "Adding Device : " << device_name << std::endl;
viewer.addDevice(dev.get());
if (dev->getCapabilities() & osgGA::Device::SEND_EVENTS)
viewer.getEventHandlers().push_front(new ForwardToDeviceEventHandler(dev.get()));
}
else
{
OSG_WARN << "could not open device: " << device_name << std::endl;
}
}
示例7: endTiming
/// Utility function you call after something you want to time, so that the
/// recorded times will all be consistent using the viewer's time.
void endTiming(osgViewer::Viewer& viewer, const std::string& name)
{
osg::Timer_t tick = osg::Timer::instance()->tick();
double currentTime = osg::Timer::instance()->delta_s(viewer.getStartTick(), tick);
int framenumber = viewer.getFrameStamp()->getFrameNumber();
viewer.getViewerStats()->setAttribute(framenumber, name + " end", currentTime);
double begin = 0.0;
double elapsed = 0.0;
if (viewer.getViewerStats()->getAttribute(framenumber, name + " begin", begin))
{
elapsed = currentTime - begin;
}
viewer.getViewerStats()->setAttribute(framenumber, name + " time taken", elapsed);
}
示例8: readEventQueue
void CameraPacket::readEventQueue(osgViewer::Viewer& viewer)
{
_events.clear();
viewer.getEventQueue()->copyEvents(_events);
osg::notify(osg::INFO)<<"written events = "<<_events.size()<<std::endl;
}
示例9: SetCameraProjectionMatrix
void SetCameraProjectionMatrix (osgViewer::Viewer& viewer, dFloat viewAngleInDegress, dFloat aspectRatio, dFloat nearPlane, dFloat farPlane)
{
osg::Camera* const camera = viewer.getCamera();
camera->setProjectionMatrixAsPerspective (viewAngleInDegress, aspectRatio, nearPlane, farPlane);
// camera->setViewMatrixAsLookAt (osg::Vec3 (-3.0f, -5.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 1.0f));
camera->setViewMatrixAsLookAt (osg::Vec3 (-0.0f, -5.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 1.0f));
}
示例10:
void
viewerSetUp( osgViewer::Viewer& viewer, double aspect, osg::Node* node )
{
viewer.getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
viewer.getCamera()->setProjectionMatrixAsPerspective( 35., aspect, .1, 50. );
viewer.getCamera()->setClearMask( 0 );
viewer.setSceneData( backdropFX::Manager::instance()->getManagedRoot() );
// No longer needed, apparently. Seems like Viewer used to focus the
// camera manipulator on the entire SkyDome, putting it too far away from
// the scene. This code compensated for that.
//osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator();
//viewer.setCameraManipulator( tb );
//tb->setNode( root.get() );
//tb->home( 0 );
viewer.addEventHandler( new osgViewer::StatsHandler );
viewer.addEventHandler( new osgViewer::ThreadingHandler );
osgGA::TrackballManipulator* tbm = new osgGA::TrackballManipulator;
viewer.setCameraManipulator( tbm );
tbm->setNode( node );
tbm->home( 0 );
}
示例11: setViewer
void setViewer(osgViewer::Viewer& viewer, float width, float height, float distance)
{
double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0);
// double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0);
viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0);
OSG_NOTICE<<"setProjectionMatrixAsPerspective( "<<vfov<<", "<<width/height<<", "<<0.1<<", "<<1000.0<<");"<<std::endl;
}
示例12: InitWindowsSystem
void InitWindowsSystem (osgViewer::Viewer& viewer, const char* const title, int x, int y, int width, int height)
{
viewer.setUpViewInWindow(x, y, width, height);
//Get the traits of the current window
osg::ref_ptr< osg::GraphicsContext::Traits > traits = new osg::GraphicsContext::Traits( *viewer.getCamera()->getGraphicsContext()->getTraits());
//Set the title
traits->windowName = title;
// disable vertical sync
traits->vsync = false;
//Create a new graphics context with the modified traits
osg::ref_ptr< osg::GraphicsContext > gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
gc->realize();
gc->makeCurrent();
// set the vertical black off by default
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); itr != windows.end(); ++itr) {
osgViewer::GraphicsWindow* const graphicsWindow = (*itr);
graphicsWindow->setSyncToVBlank (false);
}
//Create the new camera which is a copy of the current camera in the viewer
osg::ref_ptr<osg::Camera> cam = new osg::Camera( *viewer.getCamera() );
//Set the cameras graphics context to the gc we made above
cam->setGraphicsContext( gc );
//assign the viewer the new camera
viewer.setCamera( cam.get() );
// int the camera default perspective matrix
SetCameraProjectionMatrix (viewer, 60.0f, dFloat (width) / height, 0.01, 1000.0f);
// set the file find callback
osg::ref_ptr<DemosFindFileCallback> filecallback = new DemosFindFileCallback;
osgDB::Registry::instance()->setFindFileCallback (filecallback.get());
}
示例13: run
/**
Run the dynamics for a cycle.
*/
void run( Real dt ) {
// fetch the command in the buffer
//get_command();
#ifdef USE_OSG
if (ONSCREEN_RENDER)
{
if (viewer.done())
return;
viewer.frame();
}
#endif
// Note: research how the original driver sets up all the parameters that
// drive step size. sim->step(dt) is not sufficient in and of itself so
// there must be another or more parameters that manipulate this state info
//sim->step( dt );
// step the sim forward
STEP_SIZE = dt;
step((void*) &sim);
// publish any state change
//publish_state();
//#ifdef USE_OSG
//usleep(DYNAMICS_FREQ);
//#endif
}
示例14: main
int main(int argc, char** argv)
{
viewer.setSceneData(root.get());
filename = argv[1];
startMenu = new StartMenu(&viewer, startApplication);
root->addChild(startMenu->_camera);
if(root.valid())
{
//viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.realize();
while(!viewer.done())
{
viewer.frame();
//update();
}
}
else
{
std::cout << "Invalid Graph!" << std::endl;
}
return 0;
}
示例15: addChild
Level::Level(const std::string &mapfile) :
_numDeaths(0),
_reachedFinish(false)
{
_shadowedScene = new osgShadow::ShadowedScene;
_shadowedScene->setReceivesShadowTraversalMask(RECEIVE_SHADOW_MASK);
_shadowedScene->setCastsShadowTraversalMask(CAST_SHADOW_MASK);
_shadowedScene->setShadowTechnique(new osgShadow::ShadowMap);
addChild(_shadowedScene);
_headUpDisplay = new HeadUpDisplay();
addChild(_headUpDisplay->getCamera());
addChild((new Sky())->getCamera());
initializePhysicsWorld();
// load map from file
loadMapFromFile(mapfile);
// add player to level
_shadowedScene->addChild(Player::getInstance());
addChild(Player::getInstance()->getParticleEffects());
// add player ghost object to world
_physicsWorld->addCollisionObject(Player::getInstance()->getGhostObject(),
btBroadphaseProxy::CharacterFilter,
btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
// register player controller
_physicsWorld->addAction(Player::getInstance()->getController());
// initialize members
LazyCameraManipulator *cameraManipulator = new LazyCameraManipulator();
// setup manipulator to track the player
cameraManipulator->setTrackNode(Player::getInstance());
cameraManipulator->setHomePosition(LEVEL_CAMERA_HOME_EYE, LEVEL_CAMERA_HOME_CENTER, LEVEL_CAMERA_HOME_UP);
// player must be updated after physic is updated
Player::getInstance()->setUpdateCallback(new PlayerUpdater());
// set _cameraManipulator as manipulator for the scene
viewer.setCameraManipulator(cameraManipulator);
LevelUpdater *stepCallback = new LevelUpdater(this);
setUpdateCallback(stepCallback);
// player keyboard control
_keyboardHandler = new LevelKeyboardHandler();
viewer.addEventHandler(_keyboardHandler);
initializeLighting();
Sound::getInstance()->stop(MENU_MUSIC_FILE);
Sound::getInstance()->playInLoop(LEVEL_MUSIC_FILE);
}