本文整理汇总了C++中osg::ref_ptr::addEventHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ ref_ptr::addEventHandler方法的具体用法?C++ ref_ptr::addEventHandler怎么用?C++ ref_ptr::addEventHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::ref_ptr
的用法示例。
在下文中一共展示了ref_ptr::addEventHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// Main
int main( int argc, char **argv )
{
glutInit(&argc, argv);
if (argc < 2)
{
std::cout << argv[0] <<": requires filename argument." << std::endl;
return 1;
}
// Load the scene.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(argv[1]);
if (!loadedModel)
{
std::cout << argv[0] <<": No data loaded." << std::endl;
return 1;
}
// OpenGL stuff
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA );
glutInitWindowPosition( 0, 0);
glutInitWindowSize( 1280, 800 );
glutCreateWindow( argv[0] );
glutDisplayFunc( displayCB );
glutReshapeFunc( reshapeCB );
glutMouseFunc( mouseButtonCB );
glutMotionFunc( mouseMoveCB );
glutKeyboardFunc( keyboardCB );
// Create the view of the scene.
viewer = new osgViewer::Viewer;
// Convenience method for setting up the viewer so it can be used embedded in an external managed window.
// Returns the GraphicsWindowEmbedded that can be used by applications to pass in events to the viewer.
window = viewer->setUpViewerAsEmbeddedInWindow(0,0,1280,800);
// Scene data compromising the OSG 3D surface model
viewer->setSceneData(loadedModel.get());
// Set the CameraManipulator that moves the View's master Camera position in response to events.
// The parameter resetPosition determines whether manipulator is set to its home position.
viewer->setCameraManipulator(new osgGA::TrackballManipulator);
// Add an EventHandler that adds handling of events to the View.
viewer->addEventHandler(new osgViewer::StatsHandler);
// Set up windows and associated threads
viewer->realize();
// GLUT main loops
glutMainLoop();
return 0;
}
示例2: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
// construct the viewer
rViewer = new osgViewer::Viewer;
// set up the camera manipulators.
{
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
rViewer->setCameraManipulator( keyswitchManipulator.get() );
}
// make the viewer create a 800x600 window and position it at 32, 32
rViewer->setUpViewInWindow( 32, 32, 800, 600 );
// create a console
osg::ref_ptr<CSulConsoleDisplay> rConsoleDisplay = new CSulConsoleDisplay( rViewer.get() );
rConsoleDisplay->Init();
osg::Group* pGroup = new osg::Group;
pGroup->addChild( CreateScene() );
pGroup->addChild( rConsoleDisplay->GetNode() );
// create object to receive console commands
osg::ref_ptr<CMyConsoleClass> rTest = new CMyConsoleClass( rConsoleDisplay.get() );
// FIXME: grass still gets culled
rViewer->getCamera()->setCullingMode( osg::CullSettings::NO_CULLING );
////////////////////////////////////////////////////////////////////////////////
// set the scene-graph data the viewer will render
////////////////////////////////////////////////////////////////////////////////
rViewer->setSceneData( pGroup );
// setup an event handle for statistics
rViewer->addEventHandler( new osgViewer::StatsHandler );
// execute main loop
return rViewer->run();
}
示例3: main
int main( int argc, char **argv )
{
glutInit(&argc, argv);
if (argc<2)
{
std::cout << argv[0] <<": requires filename argument." << std::endl;
return 1;
}
// load the scene.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(argv[1]);
if (!loadedModel)
{
std::cout << argv[0] <<": No data loaded." << std::endl;
return 1;
}
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA );
glutInitWindowPosition( 100, 100 );
glutInitWindowSize( 800, 600 );
glutCreateWindow( argv[0] );
glutDisplayFunc( display );
glutReshapeFunc( reshape );
glutMouseFunc( mousebutton );
glutMotionFunc( mousemove );
glutKeyboardFunc( keyboard );
// create the view of the scene.
viewer = new osgViewer::Viewer;
window = viewer->setUpViewerAsEmbeddedInWindow(100,100,800,600);
viewer->setSceneData(loadedModel.get());
viewer->setCameraManipulator(new osgGA::TrackballManipulator);
viewer->addEventHandler(new osgViewer::StatsHandler);
viewer->realize();
glutMainLoop();
return 0;
}
示例4: main
// main
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc, argv);
// Let's use the convenience system from ALVAR for capturing.
// We initialize Highgui through the CaptureFactory (see manual for other options like AVI)
alvar::CaptureFactory *factory = alvar::CaptureFactory::instance();
alvar::CaptureFactory::CaptureDeviceVector devices = factory->enumerateDevices("highgui");
// Check to ensure that a device was found
if (devices.size() > 0) {
capture = factory->createCapture(devices.front());
}
// Capture is central feature, so if we fail, we get out of here.
if (capture && capture->start()) {
// Let's capture one frame to get video resolution
IplImage *tempImg = capture->captureImage();
videoXRes = tempImg->width;
videoYRes = tempImg->height;
// Calibration. See manual and ALVAR internal samples how to calibrate your camera
// Calibration will make the marker detecting and marker pose calculation more accurate.
if (! camera.SetCalib("calib.xml", videoXRes, videoYRes)) {
camera.SetRes(videoXRes, videoYRes);
}
//Create the osg::Image for the video
videoImage = new osg::Image;
//Create the osg::Image for the texture (marker hiding)
texImage = new osg::Image;
//IplImage for the texture generation.
markerHiderImage=cvCreateImage(cvSize(64, 64), 8, 4);
// construct the viewer
viewer = new osgViewer::Viewer(arguments);
// Let's use window size of the video (approximate).
viewer->setUpViewInWindow (200, 200, videoXRes, videoYRes);
// Viewport is the same
viewer->getCamera()->setViewport(0,0,videoXRes,videoYRes);
viewer->setLightingMode(osg::View::HEADLIGHT);
// Attach our own event handler to the system so we can catch the resizing events
viewer->addEventHandler(new CSimpleWndSizeHandler(videoXRes,videoYRes ));
// Set projection matrix as ALVAR recommends (based on the camera calibration)
double p[16];
camera.GetOpenglProjectionMatrix(p,videoXRes,videoYRes);
viewer->getCamera()->setProjectionMatrix(osg::Matrix(p));
// Create main root for everything
arRoot = new osg::Group;
arRoot->setName("ALVAR stuff (c) VTT");
// Init the video background class and add it to the graph
videoBG.Init(videoXRes,videoYRes,(tempImg->origin?true:false));
arRoot->addChild(videoBG.GetOSGGroup());
// Create model switch and add it the to graph
modelSwitch = new osg::Switch;
arRoot->addChild(modelSwitch.get());
// Create model transformation for the markers and add them under the switch
mtForMarkerFive = new osg::MatrixTransform;
mtForMarkerTen = new osg::MatrixTransform;
modelSwitch->addChild(mtForMarkerFive.get());
modelSwitch->addChild(mtForMarkerTen.get());
// add the texture under the marker transformation node
mtForMarkerFive->addChild(texOnMarker.GetDrawable());
// All models off
modelSwitch->setAllChildrenOff();
// load the data (models).
modelForMarkerFive = osgDB::readNodeFile("grid.osg");
modelForMarkerTen = osgDB::readNodeFile("axes.osg");
// If loading ok, add models under the matrixtransformation nodes.
if(modelForMarkerFive)
mtForMarkerFive->addChild(modelForMarkerFive.get());
if(modelForMarkerTen)
mtForMarkerTen->addChild(modelForMarkerTen.get());
// Tell the ALVAR the markers' size (same to all)
// You can also specify different size for each individual markers
markerDetector.SetMarkerSize(MARKER_SIZE);
// Set scene data
viewer->setSceneData(arRoot.get());
// And start the main loop
while(!viewer->done()){
//Call the rendering function over and over again.
renderer();
//.........这里部分代码省略.........
示例5: InitOSG
/*
Initialize OSG, create a Viewer
*/
bool InitOSG(int w, int h, bool flip_image, std::string model_file, std::string camera_file)
{
int offx = 10;
int offy = 30;
viewer = new osgViewer::Viewer;
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
if (!wsi)
{
osg::notify(osg::NOTICE) << "Error, no WindowSystemInterface available, cannot create windows." << std::endl;
return false;
}
unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = offx;
traits->y = offy;
traits->width = w;
traits->height = h;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid())
{
osg::notify(osg::INFO) << " GraphicsWindow has been created successfully." << std::endl;
// need to ensure that the window is cleared make sure that the complete window is set the correct colour
// rather than just the parts of the window that are under the camera's viewports
gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
else
{
osg::notify(osg::NOTICE) << " GraphicsWindow has not been created successfully." << std::endl;
}
model_node = osgDB::readNodeFile(model_file.c_str());
model_transform = new osg::MatrixTransform;
model_transform->addChild(model_node.get());
model_switch = new osg::Switch;
model_switch->addChild(model_transform.get());
model_switch->setAllChildrenOff();
root_group = new osg::Group;
root_group->addChild(model_switch.get());
osg::StateSet *state_set = new osg::StateSet;
state_set->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
model_node->setStateSet(state_set);
root_group->setStateSet(state_set);
viewer->getCamera()->setViewport(new osg::Viewport(0, 0, w, h));
viewer->getCamera()->setGraphicsContext(gc.get());
viewer->addEventHandler(new PickHandler());
viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
viewBG = new ViewWithBackGroundImage(viewer, w, h, flip_image, root_group);
cam.SetCalib(camera_file.c_str(), w, h);
double p[16];
cam.GetOpenglProjectionMatrix(p, w, h);
viewer->getCamera()->setProjectionMatrix(osg::Matrix(p));
return true;
}