本文整理汇总了C++中WindowEventProducerRecPtr::connectUpdate方法的典型用法代码示例。如果您正苦于以下问题:C++ WindowEventProducerRecPtr::connectUpdate方法的具体用法?C++ WindowEventProducerRecPtr::connectUpdate怎么用?C++ WindowEventProducerRecPtr::connectUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindowEventProducerRecPtr
的用法示例。
在下文中一共展示了WindowEventProducerRecPtr::connectUpdate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Sound Emitter Node
SoundEmitterRecPtr TheEmitter = SoundEmitter::create();
TheEmitter->attachUpdateProducer(TutorialWindow);
NodeUnrecPtr TheEmitterNode = Node::create();
TheEmitterNode->setCore(TheEmitter);
//Sphere Transformation Node
Matrix Translate;
Translate.setTranslate(0.0,0.0,-5.0);
Matrix Rotation;
Rotation.setRotate(Quaternion(Vec3f(0.0,1.0,0.0), 0.0));
Matrix Total(Translate);
Total.mult(Rotation);
TransformRecPtr TheSphereTransform = Transform::create();
TheSphereTransform->setMatrix(Total);
NodeUnrecPtr SphereTransformNode = Node::create();
SphereTransformNode->setCore(TheSphereTransform);
SphereTransformNode->addChild(makeSphere(2, 1.0));
SphereTransformNode->addChild(TheEmitterNode);
// create the scene
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SphereTransformNode);
// tell the manager what to manage
sceneManager.setRoot (scene);
CameraUnrecPtr TheCamera = sceneManager.getCamera();
TheCamera->setNear(0.1);
TheCamera->setFar(100.0);
//Initialize the Sound Manager
SoundManager::the()->attachUpdateProducer(TutorialWindow);
SoundManager::the()->setCamera(sceneManager.getCamera());
SoundRecPtr PopSound = SoundManager::the()->createSound();
PopSound->setFile(BoostPath("./Data/pop.wav"));
PopSound->setVolume(1.0);
PopSound->setStreaming(false);
PopSound->setLooping(-1);
PopSound->setEnable3D(true);
PopSound->connectSoundPlayed (boost::bind(handleSoundPlayed, _1));
PopSound->connectSoundStopped (boost::bind(handleSoundStopped, _1));
PopSound->connectSoundPaused (boost::bind(handleSoundPaused, _1));
PopSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
PopSound->connectSoundLooped (boost::bind(handleSoundLooped, _1));
//Attach this sound to the emitter node
TheEmitter->setSound(PopSound);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
TheEmitter.get()));
TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1,
TheSphereTransform.get()));
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"02 Sound3D Window");
//Enter main loop
TutorialWindow->mainLoop();
}
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
DefaultCollisionParams->setMu(1.0);
DefaultCollisionParams->setMu2(0.0);
DefaultCollisionParams->setBounce(0.0);
DefaultCollisionParams->setBounceSpeedThreshold(0.0);
DefaultCollisionParams->setSoftCFM(0.1);
DefaultCollisionParams->setSoftERP(0.2);
DefaultCollisionParams->setMotion1(0.0);
DefaultCollisionParams->setMotion2(0.0);
DefaultCollisionParams->setMotionN(0.0);
DefaultCollisionParams->setSlip1(0.0);
DefaultCollisionParams->setSlip2(0.0);
physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams);
PhysicsHandlerRecPtr physHandler = PhysicsHandler::create();
physHandler->setWorld(physicsWorld);
physHandler->pushToSpaces(physicsSpace);
physHandler->setUpdateNode(rootNode);
physHandler->attachUpdateProducer(TutorialWindow);
rootNode->addAttachment(physHandler);
rootNode->addAttachment(physicsWorld);
rootNode->addAttachment(physicsSpace);
/************************************************************************/
/* create spaces, geoms and bodys */
/************************************************************************/
//create a group for our space
GroupRefPtr spaceGroup;
NodeRecPtr spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
//create the ground terrain
GeometryRefPtr TerrainGeo = buildTerrain(Vec2f(400.0,400.0),25,25);
//and its Material
SimpleMaterialRefPtr TerrainMat = SimpleMaterial::create();
TerrainMat->setAmbient(Color3f(0.3,0.5,0.3));
TerrainMat->setDiffuse(Color3f(0.5,0.9,0.5));
TerrainGeo->setMaterial(TerrainMat);
NodeRefPtr TerrainNode = Node::create();
TerrainNode->setCore(TerrainGeo);
//create ODE data
PhysicsGeomRefPtr TerrainODEGeom = PhysicsTriMeshGeom::create();
//add geom to space for collision
TerrainODEGeom->setSpace(physicsSpace);
//set the geometryNode to fill the ode-triMesh
dynamic_pointer_cast<PhysicsTriMeshGeom>(TerrainODEGeom)->setGeometryNode(TerrainNode);
//add attachments
//add Attachments to nodes...
spaceGroupNode->addAttachment(physicsSpace);
spaceGroupNode->addChild(TerrainNode);
TerrainNode->addAttachment(TerrainODEGeom);
TutorialLightNode->addChild(spaceGroupNode);
//Create Character
PhysicsBodyRefPtr CharacterPhysicsBody = buildCharacter(Vec3f(5.0,5.0,10.0),
Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0),
spaceGroupNode,
physicsWorld,
physicsSpace);
PhysicsLMotorJointRefPtr CharacterMover = buildMover(CharacterPhysicsBody);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
spaceGroupNode.get(),
physicsWorld.get(),
physicsSpace.get()));
TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1,
CharacterPhysicsBody.get(),
CharacterMover.get()));
// tell the manager what to manage
sceneManager.setRoot (rootNode);
// show the whole rootNode
sceneManager.showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"03CharacterTerrain");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例3: main
//.........这里部分代码省略.........
plane_mat->setAmbient(Color3f(0.7,0.7,0.7));
plane_mat->setDiffuse(Color3f(0.9,0.6,1.0));
plane->setMaterial(plane_mat);
//create Physical Attachments
PhysicsBoxGeomRecPtr planeGeom = PhysicsBoxGeom::create();
planeGeom->setLengths(Vec3f(30.0, 30.0, 1.0));
//add geoms to space for collision
planeGeom->setSpace(physicsSpace);
//add Attachments to nodes...
spaceGroupNode->addAttachment(physicsSpace);
spaceGroupNode->addAttachment(physHandler);
spaceGroupNode->addAttachment(physicsWorld);
spaceGroupNode->addChild(planeNode);
planeNode->addAttachment(planeGeom);
scene->addChild(spaceGroupNode);
//Create Statistics Foreground
SimpleStatisticsForegroundRecPtr PhysicsStatForeground = SimpleStatisticsForeground::create();
PhysicsStatForeground->setSize(25);
PhysicsStatForeground->setColor(Color4f(0,1,0,0.7));
PhysicsStatForeground->addElement(WindowEventProducer::statWindowLoopTime, "Draw FPS: %r.3f");
PhysicsStatForeground->getCollector()->getElem(WindowEventProducer::statWindowLoopTime, true);
PhysicsStatForeground->addElement(RenderAction::statNGeometries,
"%d Nodes drawn");
PhysicsStatForeground->getCollector()->getElem(RenderAction::statNGeometries, true);
PhysicsStatForeground->addElement(PhysicsHandler::statPhysicsTime,
"Physics time: %.3f s");
PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statPhysicsTime, true);
PhysicsStatForeground->addElement(PhysicsHandler::statCollisionTime,
"Collision time: %.3f s");
PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statCollisionTime, true);
PhysicsStatForeground->addElement(PhysicsHandler::statSimulationTime,
"Simulation time: %.3f s");
PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statSimulationTime, true);
PhysicsStatForeground->addElement(PhysicsHandler::statNCollisions,
"%d collisions");
PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statNCollisions, true);
PhysicsStatForeground->addElement(PhysicsHandler::statNCollisionTests,
"%d collision tests");
PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statNCollisionTests, true);
PhysicsStatForeground->addElement(PhysicsHandler::statNPhysicsSteps,
"%d simulation steps per frame");
PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statNPhysicsSteps, true);
TutorialWindow->connectUpdate(boost::bind(handleStatisticsReset, _1), boost::signals2::at_front);
StatCollector::setGlobalCollector(PhysicsStatForeground->getCollector());
SimpleStatisticsForegroundRecPtr RenderStatForeground = SimpleStatisticsForeground::create();
RenderStatForeground->setSize(25);
RenderStatForeground->setColor(Color4f(0,1,0,0.7));
// tell the manager what to manage
sceneManager.setRoot (rootNode);
sceneManager.getWindow()->getPort(0)->addForeground(PhysicsStatForeground);
sceneManager.getWindow()->getPort(0)->addForeground(RenderStatForeground);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TriGeometryBase.get(),
spaceGroupNode.get(),
PhysDrawableNode.get(),
physicsWorld.get(),
physicsSpace.get()));
// show the whole rootNode
sceneManager.getNavigator()->set(Pnt3f(20.0,20.0,10.0), Pnt3f(0.0,0.0,0.0), Vec3f(0.0,0.0,1.0));
sceneManager.getNavigator()->setMotionFactor(1.0f);
sceneManager.getCamera()->setFar(10000.0f);
sceneManager.getCamera()->setNear(0.1f);
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"01SimplePhysics");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}