本文整理汇总了C++中osgviewer::Viewer::realize方法的典型用法代码示例。如果您正苦于以下问题:C++ Viewer::realize方法的具体用法?C++ Viewer::realize怎么用?C++ Viewer::realize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osgviewer::Viewer
的用法示例。
在下文中一共展示了Viewer::realize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]) {
ref_ptr<Group> root = new Group;
viewer.setUpViewInWindow(0, 0, 640, 480);
viewer.realize();
ref_ptr<Camera> cam = viewer.getCamera();
ref_ptr<Geode> geode = new Geode;
root->addChild(geode.get());
for (int i=0; i < 10; i++) {
osg::Sphere* sphere = new osg::Sphere( Vec3f(i+1,10,0), .1*i);
osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere);
geode->addDrawable(sphereDrawable);
}
// osg::Sphere* sphere = new osg::Sphere( Vec3f(10,10,0), .2);
// osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere);
// sphereDrawable->setColor(osg::Vec4f(1,0,0,1));
// geode->addDrawable(sphereDrawable);
ref_ptr<osgGA::TrackballManipulator> manip = new osgGA::TrackballManipulator();
viewer.setCameraManipulator(manip);
viewer.setSceneData(root.get());
cam->setViewMatrixAsLookAt(Vec3f(10,0,0), Vec3f(10,1,0), Vec3f(0,0,1));
//manip->setHomePosition(Vec3f(10,0,0), Vec3f(11,1,0), Vec3f(10,0,1));
// cam->setProjectionMatrixAsPerspective(49,640/480., .1, 10);
viewer.run();
}
示例2: 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;
}
示例3: init
//.........这里部分代码省略.........
// get the (only) simulation object
for (std::map<std::string, BasePtr>::const_iterator i = READ_MAP.begin(); i != READ_MAP.end(); i++) {
sim = boost::dynamic_pointer_cast<Simulator>(i->second);
if (sim)
break;
}
// make sure that a simulator was found
if (!sim) {
std::cerr << "driver: no simulator found in " << argv[argc-1] << std::endl;
//return -1;
return;
}
// setup osg window if desired
#ifdef USE_OSG
if (ONSCREEN_RENDER) {
// setup any necessary handlers here
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::StatsHandler);
}
// init the main group
MAIN_GROUP = new osg::Group;
#endif
// look for a scene description file
#ifdef USE_OSG
if (scene_path != "") {
std::ifstream in(scene_path.c_str());
if (in.fail()) {
std::cerr << "driver: unable to find scene description from " << scene_path << std::endl;
add_lights();
} else {
in.close();
osg::Node* node = osgDB::readNodeFile(scene_path);
if (!node) {
std::cerr << "driver: unable to open scene description file!" << std::endl;
add_lights();
} else
MAIN_GROUP->addChild(node);
}
} else {
add_lights();
}
#endif
// process XML options
process_xml_options(std::string(argv[argc-1]));
// get the simulator visualization
#ifdef USE_OSG
MAIN_GROUP->addChild(sim->get_persistent_vdata());
MAIN_GROUP->addChild(sim->get_transient_vdata());
#endif
// setup the timers
FIRST_STEP_TIME = get_current_time();
LAST_STEP_TIME = FIRST_STEP_TIME;
// begin timing
start_time = clock();
// prepare to render
#ifdef USE_OSG
if (ONSCREEN_RENDER) {
viewer.setSceneData(MAIN_GROUP);
viewer.realize();
}
#endif
// custom implementation follows
// Get reference to the pendulum for usage in the command publish and response
if( READ_MAP.find("pendulum") == READ_MAP.end() ) {
sprintf( strbuffer, "(dynamics.cpp) init(argc,argv) failed- unable to find pendulum in xml!\n" );
dyn_error_log.write( strbuffer );
// TODO : return error condition
}
pendulum = dynamic_pointer_cast<Moby::RCArticulatedBody>( READ_MAP.find("pendulum")->second );
if( !pendulum ) {
sprintf( strbuffer, "(dynamics.cpp) init(argc,argv)- unable to cast pendulum to type RCArticulatedBody\n" );
dyn_error_log.write( strbuffer );
// TODO : return error condition
}
// open the command buffer
dyn_amsgbuffer = actuator_msg_buffer_c( ACTUATOR_MSG_BUFFER_NAME, ACTUATOR_MSG_BUFFER_MUTEX_NAME, false );
if( dyn_amsgbuffer.open( ) != BUFFER_ERROR_NONE) {
sprintf( strbuffer, "(dynamics.cpp) init(argc,argv) failed calling actuator_msg_buffer_c.open(...,false)\n" );
dyn_error_log.write( strbuffer );
// TODO : return error condition
}
printf( "(dynamics::initialized)\n" );
}
示例4: main
//.........这里部分代码省略.........
// to textures.
std::string search_path = ";";
csp::ospath::addpath(search_path, "./data/images/");
csp::ospath::addpath(search_path, "./data/models/");
csp::ObjectModel::setDataFilePathList(search_path);
// Set paths for shader files.
Shader::instance()->setShaderPath("./data/shaders/");
// =====================================================================
// Manual creation of a object model.
Ref<ObjectModel> my_model = new ObjectModel();
// An external is used to handle the path to the scene graph file.
// It is also ensuring that paths is handled independent on operating
// system.
External modelPath;
modelPath.setSource("industry/refinery_column01/refinery_column01.osg");
my_model->setModelPath(modelPath);
my_model->setSmooth(true);
// Load the model from disc. This will also apply needed shaders.
// smoothing and more things.
my_model->loadModel();
// read osgEarth config file and create the globe
std::cout << "reading osgEarth config file: " << osgEarthFileName << std::endl;
osg::ref_ptr<osg::Node> globe = osgDB::readNodeFile(osgEarthFileName);
osg::ref_ptr<osg::Node> topNode = new osg::Node;
osg::Group* group = new osg::Group;
group->setName("root group");
// =====================================================================
// construct the viewer
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.addEventHandler(new osgViewer::HelpHandler);
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
// modify the key mapping of an osg default event handler
// this is just to demonstrate the principle, no real use case behind it...
osgViewer::View::EventHandlers eventHandlers = viewer.getEventHandlers();
// iterate through the viewer's event handlers and modify their default behavior
for (osgViewer::View::EventHandlers::iterator it = eventHandlers.begin(); it != eventHandlers.end(); ++it)
{
// EventHandlers is a list of osgGA::GUIEventHandlers, so RTTI is used to find out the derived class
if(osgViewer::WindowSizeHandler *winSizeHandler =
dynamic_cast<osgViewer::WindowSizeHandler *>(it->get()))
{
winSizeHandler->setKeyEventToggleFullscreen(osgGA::GUIEventAdapter::KEY_F2);
}
}
// Create overlay data
osg::ref_ptr<osg::Geode> statsGeometry = createStatsGeometry();
group->addChild( statsGeometry );
// add the osgEarth globe to the scene
group->addChild( globe.get() );
group->addChild( my_model->getModel().get() );
//viewer.setSceneData(my_model->getModel().get());
viewer.setSceneData( group );
//viewer.setSceneData(globe.get());
// create camera and context
setupCameraAndContext( viewer, windowWidth, windowHeight );
// the overlay geometry is added to an individual camera
// QUESTION: But why isn't it rendered by the primary cam?!?
statsCamera->addChild( statsGeometry );
//viewer.setCameraManipulator(new osgGA::FlightManipulator);
osgEarth::MapNode* mapNode = osgEarth::MapNode::findMapNode(globe);
manip = new osgEarthUtil::EarthManipulator();
manip->setNode(globe);
if ( mapNode->getMap()->isGeocentric() )
{
manip->setHomeViewpoint(
osgEarthUtil::Viewpoint( osg::Vec3d( -90, 0, 0 ), 0.0, -90.0, 5e7 ) );
}
manip->getSettings()->bindMouseDoubleClick(
osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );
viewer.setCameraManipulator(manip);
viewer.addEventHandler(new inputHandler());
// run the viewers frame loop
viewer.realize();
// main loop (note, window toolkits which take control over the main loop will require
// a window redraw callback containing the code below.)
while(!viewer.done())
{
viewer.frame();
}
}
示例5: init
//.........这里部分代码省略.........
// setup osg window if desired
#ifdef USE_OSG
if (ONSCREEN_RENDER)
{
// setup any necessary handlers here
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::StatsHandler);
}
// init the main group
MAIN_GROUP = new osg::Group;
#endif
/**
// Note: In this architecture, Moby doesn't have any direct relationship to
// controllers, so the ability to load control plugins is removed
// call the initializers, if any
if (!INIT.empty())
{
#ifdef USE_OSG
BOOST_FOREACH(init_t i, INIT)
(*i)(MAIN_GROUP, READ_MAP, STEP_SIZE);
#else
BOOST_FOREACH(init_t i, INIT)
(*i)(NULL, READ_MAP, STEP_SIZE);
#endif
}
*/
// look for a scene description file
#ifdef USE_OSG
if (scene_path != "")
{
std::ifstream in(scene_path.c_str());
if (in.fail())
{
std::cerr << "driver: unable to find scene description from " << scene_path << std::endl;
add_lights();
}
else
{
in.close();
osg::Node* node = osgDB::readNodeFile(scene_path);
if (!node)
{
std::cerr << "driver: unable to open scene description file!" << std::endl;
add_lights();
}
else
MAIN_GROUP->addChild(node);
}
}
else
add_lights();
#endif
// process XML options
process_xml_options(std::string(argv[argc-1]));
// get the simulator visualization
#ifdef USE_OSG
MAIN_GROUP->addChild(sim->get_persistent_vdata());
MAIN_GROUP->addChild(sim->get_transient_vdata());
#endif
// setup the timers
FIRST_STEP_TIME = get_current_time();
LAST_STEP_TIME = FIRST_STEP_TIME;
// begin timing
start_time = clock();
// prepare to render
#ifdef USE_OSG
if (ONSCREEN_RENDER)
{
viewer.setSceneData(MAIN_GROUP);
viewer.realize();
}
#endif
// custom implementation follows
// Get reference to the pendulum for usage in the command publish and response
if( READ_MAP.find("pendulum") == READ_MAP.end() )
printf( "dynamics.cpp:init()- unable to find pendulum!\n" );
pendulum = dynamic_pointer_cast<Moby::RCArticulatedBody>( READ_MAP.find("pendulum")->second );
if( !pendulum )
printf( "dynamics.cpp:init()- unable to cast pendulum to type RCArticulatedBody\n" );
// open the command buffer
cmdbuffer = CommandBuffer( getpid( ) );
cmdbuffer.open(); // TODO : sanity/safety checking
//printf( "(dynamics::initialized)\n" );
}
示例6: run
int Metrics::run(osgViewer::Viewer& viewer)
{
if (Metrics::enabled())
{
if (!viewer.isRealized())
{
viewer.realize();
}
// If Metrics are enabled, enable stats on the Viewer so that it we can report them for the Metrics
if (Metrics::enabled())
{
osgViewer::ViewerBase::Scenes scenes;
viewer.getScenes(scenes);
for (osgViewer::ViewerBase::Scenes::iterator itr = scenes.begin();
itr != scenes.end();
++itr)
{
osgViewer::Scene* scene = *itr;
osgDB::DatabasePager* dp = scene->getDatabasePager();
if (dp && dp->isRunning())
{
dp->resetStats();
}
}
viewer.getViewerStats()->collectStats("frame_rate", true);
viewer.getViewerStats()->collectStats("event", true);
viewer.getViewerStats()->collectStats("update", true);
viewer.getCamera()->getStats()->collectStats("rendering", true);
viewer.getCamera()->getStats()->collectStats("gpu", true);
}
// Report memory and fps every 10 frames.
unsigned int reportEvery = 10;
while (!viewer.done())
{
{
METRIC_SCOPED_EX("frame", 1, "number", toString<int>(viewer.getFrameStamp()->getFrameNumber()).c_str());
{
METRIC_SCOPED("advance");
viewer.advance();
}
{
METRIC_SCOPED("event");
viewer.eventTraversal();
}
{
METRIC_SCOPED("update");
viewer.updateTraversal();
}
{
METRIC_SCOPED("render");
viewer.renderingTraversals();
}
}
// Report memory and fps periodically. periodically.
if (viewer.getFrameStamp()->getFrameNumber() % reportEvery == 0)
{
// Only report the metrics if they are enabled to avoid computing the memory.
if (Metrics::enabled())
{
Metrics::counter("Memory::WorkingSet", "WorkingSet", Memory::getProcessPhysicalUsage() / 1048576);
Metrics::counter("Memory::PrivateBytes", "PrivateBytes", Memory::getProcessPrivateUsage() / 1048576);
Metrics::counter("Memory::PeakPrivateBytes", "PeakPrivateBytes", Memory::getProcessPeakPrivateUsage() / 1048576);
}
}
double eventTime = 0.0;
if (viewer.getViewerStats()->getAttribute(viewer.getViewerStats()->getLatestFrameNumber(), "Event traversal time taken", eventTime))
{
Metrics::counter("Viewer::Event", "Event", eventTime * 1000.0);
}
double updateTime = 0.0;
if (viewer.getViewerStats()->getAttribute(viewer.getViewerStats()->getLatestFrameNumber(), "Update traversal time taken", updateTime))
{
Metrics::counter("Viewer::Update", "Update", updateTime * 1000.0);
}
double cullTime = 0.0;
if (viewer.getCamera()->getStats()->getAttribute(viewer.getCamera()->getStats()->getLatestFrameNumber(), "Cull traversal time taken", cullTime))
{
Metrics::counter("Viewer::Cull", "Cull", cullTime * 1000.0);
}
double drawTime = 0.0;
if (viewer.getCamera()->getStats()->getAttribute(viewer.getCamera()->getStats()->getLatestFrameNumber(), "Draw traversal time taken", drawTime))
{
Metrics::counter("Viewer::Draw", "Draw", drawTime * 1000.0);
}
double gpuTime = 0.0;
//.........这里部分代码省略.........