本文整理汇总了C++中WindowEventProducerRecPtr::connectKeyPressed方法的典型用法代码示例。如果您正苦于以下问题:C++ WindowEventProducerRecPtr::connectKeyPressed方法的具体用法?C++ WindowEventProducerRecPtr::connectKeyPressed怎么用?C++ WindowEventProducerRecPtr::connectKeyPressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindowEventProducerRecPtr
的用法示例。
在下文中一共展示了WindowEventProducerRecPtr::connectKeyPressed方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
FCFileType::FCPtrStore ObjStore;
try
{
ObjStore = FCFileHandler::the()->read(FilePath);
}
catch(std::exception &ex)
{
std::cerr << "Failed to load file: " << FilePath.string() << ", error:"
<< ex.what() << std::endl;
return -1;
}
for(FCFileType::FCPtrStore::iterator StorItor(ObjStore.begin());
StorItor != ObjStore.end();
++StorItor)
{
//Animations
if((*StorItor)->getType().isDerivedFrom(Animation::getClassType()))
{
LoadedAnimations.push_back(dynamic_pointer_cast<Animation>(*StorItor));
LoadedAnimations.back()->attachUpdateProducer(TutorialWindow);
LoadedAnimations.back()->start();
}
//Root Node
if((*StorItor)->getType() == Node::getClassType() &&
dynamic_pointer_cast<Node>(*StorItor)->getParent() == NULL)
{
LoadedRoot = dynamic_pointer_cast<Node>(*StorItor);
}
}
if(LoadedRoot == NULL)
{
LoadedRoot = SceneFileHandler::the()->read(FilePath.string().c_str());
}
if(LoadedRoot == NULL)
{
LoadedRoot= makeTorus(.5, 2, 32, 32);
}
//Make the fog node
PostShaderStageRecPtr PostShaderStageCore = PostShaderStage::create();
PostShaderStageCore->clearPasses();
PostShaderStageCore->addPass("", generateNoEffectProg());
DirectionalLightRecPtr SceneLightCore = DirectionalLight::create();
SceneLightCore->setAmbient(Color4f(0.2f, 0.2f, 0.2f, 1.0f));
SceneLightCore->setDiffuse(Color4f(0.8f, 0.8f, 0.8f, 1.0f));
SceneLightCore->setSpecular(Color4f(1.0f, 1.0f, 1.0f, 1.0f));
NodeRefPtr SceneLight = makeNodeFor(SceneLightCore);
SceneLight->addChild(LoadedRoot);
NodeRefPtr PostShaderStageNode = makeNodeFor(PostShaderStageCore);
PostShaderStageNode->addChild(SceneLight);
//Make Main Scene Node
NodeRefPtr scene = makeCoredNode<Group>();
scene->addChild(PostShaderStageNode);
// tell the manager what to manage
sceneManager.setRoot (scene);
SceneLightCore->setBeacon(sceneManager.getCamera()->getBeacon());
//Create the Documentation Foreground and add it to the viewport
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
sceneManager.getWindow()->getPort(0)->setTravMask(1);
RenderOptionsRecPtr ViewportRenderOptions = RenderOptions::create();
ViewportRenderOptions->setRenderProperties(0x0);
ViewportRenderOptions->setRenderProperties(RenderPropertiesPool::the()->getFrom1("Default"));
ViewportRenderOptions->setRenderProperties(0x01);
sceneManager.getWindow()->getPort(0)->setRenderOptions(ViewportRenderOptions);
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"Collada Loader");
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TutorialWindow.get(),
PostShaderStageCore.get()));
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例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
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
OSG::preloadSharedObject("OSGFileIO");
OSG::preloadSharedObject("OSGImageFileIO");
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
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));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));
//Box Geometry
GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1);
ChunkMaterialUnrecPtr TheBoxMaterial = ChunkMaterial::create();
BoxGeometry->setMaterial(TheBoxMaterial);
NodeUnrecPtr BoxGeometryNode = Node::create();
BoxGeometryNode->setCore(BoxGeometry);
//Make Box Node
NodeUnrecPtr BoxNode = Node::create();
TransformUnrecPtr BoxNodeTrans;
BoxNodeTrans = Transform::create();
BoxNode->setCore(BoxNodeTrans);
BoxNode->addChild(BoxGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
scene->setCore(Trans);
// add the torus as a child
scene->addChild(BoxNode);
//Setup the Animation
AnimationUnrecPtr TheAnimation = setupAnimation(TheBoxMaterial);
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
// tell the manager what to manage
sceneManager.setRoot (scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"09TextureSelectAnimation");
//Main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例4: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
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));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));
//Torus Node
NodeUnrecPtr TorusGeometryNode = makeTorus(.5, 2, 32, 32);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TransformUnrecPtr TorusNodeTrans;
TorusNodeTrans = Transform::create();
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans;
Trans = ComponentTransform::create();
scene->setCore(Trans);
// add the torus as a child
scene->addChild(TorusNode);
//Make a gradient Background
GradientBackgroundUnrecPtr TutorialBackground = GradientBackground::create();
TutorialBackground->addLine(Color3f(1.0,0.0,0.0),0.0);
TutorialBackground->addLine(Color3f(0.0,1.0,0.0),0.5);
TutorialBackground->addLine(Color3f(0.0,0.0,1.0),1.0);
setName(TutorialBackground, std::string("TutorialGradientBackground"));
AnimationUnrecPtr TheAnimation = setupAnimation(TutorialBackground);
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
// tell the manager what to manage
sceneManager.setRoot (scene);
sceneManager.getWindow()->getPort(0)->setBackground(TutorialBackground);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"03MFieldAnimation");
//Main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例5: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
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));
//Torus Material
SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create();
TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3));
TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7));
TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0));
TheTorusMaterial->setShininess(20.0);
//Torus Geometry
GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
TorusGeometry->setMaterial(TheTorusMaterial);
NodeUnrecPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TransformUnrecPtr TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans = ComponentTransform::create();
setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Trans);
// add the torus as a child
scene->addChild(TorusNode);
AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TheAnimation.get(),
TutorialWindow.get()));
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
// tell the manager what to manage
sceneManager.setRoot (scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"07AnimationGroup");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例6: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
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));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));
//Shader Chunk
SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create();
TheSHLChunk->setVertexProgram(createSHLVertexProg());
TheSHLChunk->setFragmentProgram(createSHLFragProg());
//TheSHLChunk->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
//TheSHLChunk->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));
//Shader Parameter Chunk
SimpleSHLVariableChunkUnrecPtr SHLParameters = SimpleSHLVariableChunk::create();
//Color Parameter
SHLParameters->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
SHLParameters->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));
ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create();
ShaderMaterial->addChunk(TheSHLChunk);
ShaderMaterial->addChunk(SHLParameters);
//Torus Node
GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32);
TorusGeometry->setMaterial(ShaderMaterial);
NodeUnrecPtr TorusNode = Node::create();
TorusNode->setCore(TorusGeometry);
// Make Main Scene Node
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusNode);
sceneManager.setRoot(scene);
// Show the whole Scene
sceneManager.showAll();
//Create the Animations
ShaderVariableVec4fUnrecPtr Color1Parameter;
ShaderVariableVec4fUnrecPtr Color2Parameter;
Color1Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color1")));
Color2Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color2")));
commitChanges();
AnimationUnrecPtr TheAnimation = setupAnimation(Color1Parameter, "value");
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"04ShaderAnimation");
//Main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例7: main
//.........这里部分代码省略.........
ExampleParticleSystem->setMaxParticles(5); // 5 rockets max to avoid collisions. they are bad.
ExampleParticleSystem->pushToAffectors(AgeFadeAffector);
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Creating Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_VIEW_DIRECTION,
QuadParticleSystemDrawer::UP_VELOCITY);
QuadParticleSystemDrawerRefPtr ExampleTrailDrawer = QuadParticleSystemDrawer::create();
//ExampleTrailDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_VIEW_DIRECTION,
//QuadParticleSystemDrawer::UP_PARTICLE_NORMAL);
// Attaching affector and generator to the particle system
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
//Particle System Core, setting its system, drawer, and material
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
// create Particle System Particle Trail generator
ParticleSystemParticleTrailGeneratorRecPtr ExamplePSTrailGenerator = ParticleSystemParticleTrailGenerator::create();
ExamplePSTrailGenerator->setTrailResolution(0.05f);
ExamplePSTrailGenerator->setTrailLength(1.2);
ExamplePSTrailGenerator->setTrailLengthMethod(ParticleTrailGenerator::TIME);
ExamplePSTrailGenerator->setTrailResolutionMethod(ParticleTrailGenerator::TIME_SPACING);
ExamplePSTrailGenerator->setTrailMaterial(TrailMaterial);
ExamplePSTrailGenerator->setTrailDrawer(ExampleTrailDrawer);
ExamplePSTrailGenerator->setSizeDistribution(createTrailSizeDistribution());
ExamplePSTrailGenerator->setColorDistribution(createColorDistribution());
ExamplePSTrailGenerator->setNormalDistribution(createNormalDistribution());
ExamplePSTrailGenerator->setVelocityDistribution(createNormalDistribution());
// create affectors for particle trails
GravityParticleAffectorRefPtr GravAffector = GravityParticleAffector::create();
GravAffector->setBeacon(ExamplePSTrailGenerator);
AgeFadeParticleAffectorRefPtr TrailAgeFadeAffector = AgeFadeParticleAffector::create();
TrailAgeFadeAffector->setFadeInTime(0.2f);
TrailAgeFadeAffector->setStartAlpha(0.0f);
TrailAgeFadeAffector->setEndAlpha(0.0f);
TrailAgeFadeAffector->setFadeOutTime(1.0f);
TrailAgeFadeAffector->setFadeToAlpha(0.6f);
// now we attach the affector to the particle trail generator's particle system
ExamplePSTrailGenerator->getParticleSystem()->pushToAffectors(TrailAgeFadeAffector);
// attach listener for trail generator to the particle system
ExamplePSTrailGenerator->setSystemToTrail(ExampleParticleSystem);
//Attach the the update producer to the particle system particle trail generator.
ExamplePSTrailGenerator->attachUpdateProducer(TutorialWindow);
// Set up node with the particle system at its core
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
ParticleNode->addChild(ExamplePSTrailGenerator);
// Make Main Scene Node
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, &sceneManager, ExampleParticleSystem.get(), ExamplePSTrailGenerator.get()));
sceneManager.setRoot(scene);
// Show the whole Scene
sceneManager.getNavigator()->set(Pnt3f(0.0,0.0,100.0), Pnt3f(0.0,0.0,0.0), Vec3f(0.0,1.0,0.0));
sceneManager.getNavigator()->setMotionFactor(1.0f);
sceneManager.getCamera()->setFar(10000.0f);
sceneManager.getCamera()->setNear(0.1f);
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"02ParticleSystemParticleTrail");
std::cout << "Controls: " << std::endl
<< "P: Increase Trail Resolution" << std::endl
<< "L: Decrease Trail Resolution" << std::endl
<< "O: Increase Trail Length" << std::endl
<< "K: Decrease Trail Length" << std::endl
<< "J: Toggle calculating trail length by num points/time" << std::endl
<< "Y: Toggle calculating trail point spacing by time/distance" << std::endl
<< "B: Particle burst" << std::endl;
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例8: main
//.........这里部分代码省略.........
<< " IntersectingNodeCount: " << TheOctree->getIntersectingNodeCount() << std::endl
<< " IntersectingLeafNodeCount: " << TheOctree->getIntersectingLeafNodeCount() << std::endl;
//Make the Nanobot Nodes
BoostPath NanobotFilePath(".//Data//Nanobot.osb");
NodeRecPtr NanobotGeoNode =
SceneFileHandler::the()->read(NanobotFilePath.string().c_str());
NanobotVector Nanobots;
UInt32 NumNanobots(3);
for(UInt32 i(0) ; i<NumNanobots ; ++i)
{
NanobotDetails TheDetails;
//Get the Transform node for the Nanobot
TheDetails._Transform = Transform::create();
Matrix NanobotMatrix;
Pnt3f Min,Max;
SceneGeometryNode->getVolume().getBounds(Min,Max);
Min = Min + ShrinkFactor;
Max = Max - ShrinkFactor;
NanobotMatrix.setTranslate(randomOpenPosition(Min,Max,TheOctree).subZero());
NanobotMatrix.setScale(0.06f);
TheDetails._Transform->setMatrix(NanobotMatrix);
TheDetails._Node = makeNodeFor(TheDetails._Transform);
TheDetails._Node->addChild(cloneTree(NanobotGeoNode));
TheDetails._Node->setTravMask(NanobotMask);
TheDetails._PathVisNode = Node::create();
Nanobots.push_back(TheDetails);
makeNanobotPath(Nanobots.back(), TheOctree, TutorialWindow, Min,Max);
}
for(UInt32 i(0) ; i<Nanobots.size() ; ++i)
{
RootNode->addChild(Nanobots[i]._Node);
RootNode->addChild(Nanobots[i]._PathVisNode);
}
commitChanges();
//NodeRecPtr StartNode = makeSphere(1.0, 2);
//TransformRecPtr StartNodeTransform = Transform::create();
//Matrix StartNodeMatrix;
//StartNodeMatrix.setTranslate(Start);
//StartNodeMatrix.setScale(0.1f);
//StartNodeTransform->setMatrix(StartNodeMatrix);
//NodeRecPtr StartNodeTransformNode = makeNodeFor(StartNodeTransform);
//StartNodeTransformNode->addChild(StartNode);
//StartNodeTransformNode->setTravMask(PathMask);
//RootNode->addChild(StartNodeTransformNode);
//NodeRecPtr GoalNode = makeSphere(1.0, 2);
//TransformRecPtr GoalNodeTransform = Transform::create();
//Matrix GoalNodeMatrix;
//GoalNodeMatrix.setScale(0.1f);
//GoalNodeMatrix.setTranslate(Goal);
//GoalNodeTransform->setMatrix(GoalNodeMatrix);
//NodeRecPtr GoalNodeTransformNode = makeNodeFor(GoalNodeTransform);
//GoalNodeTransformNode->addChild(GoalNode);
//GoalNodeTransformNode->setTravMask(PathMask);
//RootNode->addChild(GoalNodeTransformNode);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TutorialWindow.get(),
SceneGeometryNode.get(),
TheOctree,
Nanobots));
//Set the background
SolidBackgroundRecPtr TheBackground = SolidBackground::create();
TheBackground->setColor(Color3f(0.0f,0.0f,0.0f));
// tell the manager what to manage
sceneManager.setRoot (RootNode);
sceneManager.getWindow()->getPort(0)->setBackground(TheBackground);
// show the whole RootNode
sceneManager.showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"01AStarPathing");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例9: 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;
}
示例10: main
//.........这里部分代码省略.........
//Add this joint to the skeleton
ExampleSkeleton->pushToJoints(ExampleRootJointNode, Matrix());
NodeRecPtr TempRootJointNode = ExampleRootJointNode;
NodeRefPtr GeoNode = makeNodeFor(BoxGeometry);
TempRootJointNode->addChild(GeoNode);
Matrix TempMat;
//Create a set of randomly placed child joints
for (Real32 i = 0.0f; i < 5.0f; ++i)
{
TransformRecPtr ExampleChildJoint = Transform::create();
NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint);
GeoNode = makeNodeFor(SphereGeometry);
ExampleChildJointNode->addChild(GeoNode);
//TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
switch((static_cast<UInt32>(i) % 3))
{
case 0:
TempMat.setTranslate(2.0f,0.0f,0.0f);
break;
case 1:
TempMat.setTranslate(0.0f,2.0f,0.0f);
break;
case 2:
TempMat.setTranslate(0.0f,0.0f,2.0f);
break;
}
//Set bind and current transformations to TempMat (calculated above)
ExampleChildJoint->setMatrix(TempMat);
//Add ExampleChildJoint as a child to the previous joint
TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint
//ExampleChildJoint will be the next parent joint
TempRootJointNode = ExampleChildJointNode;
//Add this joint to the skeleton
Matrix InvBind(TempRootJointNode->getToWorld());
InvBind.invert();
ExampleSkeleton->pushToJoints(ExampleChildJointNode, InvBind);
}
//SkeletonDrawer
SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we won't draw the skeleton's bind pose
ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When the skeleton's bind pose is rendered, it will be green
ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose
ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose is rendered in blue
//Skeleton Node
NodeUnrecPtr SkeletonNode = Node::create();
SkeletonNode->setCore(ExampleSkeletonDrawable);
//Create scene
NodeUnrecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(SkeletonNode);
scene->addChild(ExampleRootJointNode);
sceneManager.setRoot(scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
//Setup the Animation
AnimationUnrecPtr TheAnimation = setupAnimation(ExampleRootJoint,
dynamic_cast<Transform*>(ExampleRootJointNode->getChild(1)->getCore()));
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TheAnimation.get(),
SkeletonNode.get(),
TutorialWindow.get()));
// Show the whole Scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"11BoneAnimation");
//Main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例11: main
// Initialize GLUT & OpenSG and set up the rootNode
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed,_1));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
UInt32 SceneMask(1),
PathMask(4);
BoostPath SceneFilePath(".//Data//CellParts.osb");
if(argc >= 2)
{
SceneFilePath = BoostPath(argv[1]);
if(!boost::filesystem::exists(SceneFilePath))
{
SceneFilePath = BoostPath(".//Data//CellParts.osb");
}
}
//Make Base Geometry Node
NodeRecPtr SceneGeometryNode =
SceneFileHandler::the()->read(SceneFilePath.string().c_str());
SceneGeometryNode->setTravMask(SceneMask);
if(SceneGeometryNode == NULL)
{
SceneGeometryNode = makeTorus(1.0, 10.0, 24, 24);
}
//Construct the Root Node
NodeRecPtr RootNode = makeCoredNode<Group>();
RootNode->addChild(SceneGeometryNode);
commitChanges();
//Create the Octree
SLOG << "Started Building Octree" << std::endl;
SLOG << "This may take some time ..." << std::endl;
Time StartTime;
StartTime = getSystemTime();
OctreePtr TheOctree =
Octree::buildTree(RootNode,SceneMask,6,1.5,true);
SLOG << "Building Octree: " << getSystemTime() - StartTime << " s" << std::endl;
Pnt3f Min,Max;
TheOctree->getRoot()->getVolume();
SLOG << "Octree: "<< std::endl
<< " Depth: " << TheOctree->getDepth() << std::endl
<< " Bounds: " << TheOctree->getRoot()->getVolume().getMin() << " : " << TheOctree->getRoot()->getVolume().getMax() << std::endl
<< " NodeCount: " << TheOctree->getNodeCount() << std::endl
<< " LeafNodeCount: " << TheOctree->getLeafNodeCount() << std::endl
<< " BranchNodeCount: " << TheOctree->getBranchNodeCount() << std::endl
<< " IntersectingNodeCount: " << TheOctree->getIntersectingNodeCount() << std::endl
<< " IntersectingLeafNodeCount: " << TheOctree->getIntersectingLeafNodeCount() << std::endl;
//Create the Path Geometry
//Generate the Path
OctreeAStarAlgorithm AlgorithmObj;
SLOG << "Started AStar Search" << std::endl;
StartTime = getSystemTime();
Pnt3f Start(-4.01f,1.01f,10.01f),Goal(-4.01f,-0.01f,-7.01f);
std::vector<Pnt3f> Path =
AlgorithmObj.search(TheOctree,Start,Goal);
Path.front() = Start;
Path.back() = Goal;
SLOG << "Finished AStar Search: " << getSystemTime() - StartTime << " s" << std::endl;
NodeRecPtr PathNode = createPathGeometry(Path);
PathNode->setTravMask(PathMask);
RootNode->addChild(PathNode);
NodeRecPtr StartNode = makeSphere(1.0, 2);
TransformRecPtr StartNodeTransform = Transform::create();
Matrix StartNodeMatrix;
StartNodeMatrix.setTranslate(Start);
StartNodeMatrix.setScale(0.1f);
StartNodeTransform->setMatrix(StartNodeMatrix);
NodeRecPtr StartNodeTransformNode = makeNodeFor(StartNodeTransform);
StartNodeTransformNode->addChild(StartNode);
StartNodeTransformNode->setTravMask(PathMask);
RootNode->addChild(StartNodeTransformNode);
//.........这里部分代码省略.........
示例12: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create();
TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager));
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));
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1));
// Tell the Manager what to manage
sceneManager->setWindow(TutorialWindow);
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(90, 270, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr TutorialGraphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
/******************************************************
The Drawing Surface is created the
same as with previous Tutorials
(however the MainInternalWindow is created
in a function below).
******************************************************/
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->setCursorAsImage(WindowEventProducer::CURSOR_POINTER,
BoostPath("./Data/cursor.png"),
Vec2f(-1.0f,-1.0f),
Vec2f(-12.0f,-20.0f));
InternalWindowRecPtr MainUIWindow = createMainInternalWindow();
TutorialDrawingSurface->openWindow(MainUIWindow);
/******************************************************
Create the 3D UIRectangle. This allows
the DrawingSurface to be rotated relative
to the screen, allowing a 3D aspect to
the DrawingSurface. The Surface
can still be interacted with, so Buttons,
Menus, etc. all will still function
normally.
-setPoint(Pnt3f): Determine the location
of the UIRectangle in 3D space. Keep
in mind that (0,0,0) is located
directly in the center of the sceen.
(For our purposes it is the center
of the tori.) The point is located
on the lower left corner of the
rectangle.
-setWidth(float): Determine the Width
of the UIRectangle. This may
physically appear different depending
on where the UIRectangle is placed
as above (due to it being located
further away, etc).
-setHeight(float): Determine the Height
of the UIRectangle. This may
physically appear different depending
on where the UIRectangle is placed
as above (due to it being located
further away, etc).
-setDrawingSurface(DrawingSurface):
Determine what DrawingSurface is
drawn on the UIRectangle. This
will typically be the main
DrawingSurface, however, multiple
DrawingSurfaces can be used with
multiple UIRectangles.
******************************************************/
//Make A 3D Rectangle to draw the UI on
//.........这里部分代码省略.........