本文整理汇总了C++中WindowEventProducerRecPtr::connectMouseReleased方法的典型用法代码示例。如果您正苦于以下问题:C++ WindowEventProducerRecPtr::connectMouseReleased方法的具体用法?C++ WindowEventProducerRecPtr::connectMouseReleased怎么用?C++ WindowEventProducerRecPtr::connectMouseReleased使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindowEventProducerRecPtr
的用法示例。
在下文中一共展示了WindowEventProducerRecPtr::connectMouseReleased方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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));
//Particle System Material
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(10.0f);
PSPointChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.2f,0.6f,0.5f,0.3f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.2f,0.9f,0.1f,0.3f));
PSMaterialChunkChunk->setSpecular(Color4f(0.5f,0.4f,0.2f,0.6f));
PSMaterialChunkChunk->setEmission(Color4f(0.2f,0.6f,0.5f,0.3f));
PSMaterialChunkChunk->setColorMaterial(GL_NONE);
//enable depth test
DepthChunkRefPtr PSDepthChunk = DepthChunk::create();
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
PSMaterial->addChunk(PSDepthChunk);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer
//Point
PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create();
//ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true);
//Line
LineParticleSystemDrawerRecPtr ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create();
ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE);
ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X);
ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(1.0,0.0));
//Quad
QuadParticleSystemDrawerRecPtr ExampleQuadParticleSystemDrawer = QuadParticleSystemDrawer::create();
ExampleQuadParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.1,0.1));
ExampleQuadParticleSystemDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_PARTICLE_NORMAL,QuadParticleSystemDrawer::UP_STATIC);
RateParticleGeneratorRefPtr ExampleGeneratorTheSequel = RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGeneratorTheSequel->setPositionDistribution(createPositionDistribution());
ExampleGeneratorTheSequel->setLifespanDistribution(createLifespanDistribution());
ExampleGeneratorTheSequel->setGenerationRate(300.0);
ExampleGeneratorTheSequel->setVelocityDistribution(createVelocityDistribution());
//Attach the Generator to the Particle System
//ExampleParticleSystem->pushToGenerators(ExampleGenerator);
ExampleParticleSystem->setMaxParticles(500);
ExampleParticleSystem->pushToGenerators(ExampleGeneratorTheSequel);
//Particle System Node
ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleQuadParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager,
ParticleNodeCore.get(),
//.........这里部分代码省略.........
示例2: main
int main(int argc, char **argv)
{
preloadSharedObject("OSGImageFileIO");
// 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->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
// Creating the Particle System Material
// Here, the image is loaded. The entire image sequence is conatined in one image,
// which reduces texture memory overhead and runs faster.
TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/SpriteExplode.png");
QuadTextureChunk->setImage(LoadedImage);
TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
QuadTextureEnvChunk->setEnvMode(GL_MODULATE);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setAmbient(Color4f(0.3f,0.0f,0.0f,1.0f));
PSMaterialChunk->setDiffuse(Color4f(0.7f,0.0f,0.0f,1.0f));
PSMaterialChunk->setSpecular(Color4f(0.9f,0.0f,0.0f,1.0f));
PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(QuadTextureChunk);
PSMaterial->addChunk(QuadTextureEnvChunk);
PSMaterial->addChunk(PSMaterialChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Age Particle Function. Controls which image is shown when, based on the age of a particle.
AgeParticleFunctionRecPtr AgeFunc = AgeParticleFunction::create();
AgeFunc->setSequenceTime(0.1f); // image changes every 0.1 seconds.
AgeFunc->setSequenceOrder(AgeParticleFunction::CUSTOM); // using the custom sequence below.
/*
Here, a custom sequence for the image ordering is assembled. The image sequence will be shown in
the order specified here. Once the end of the sequence is reached, the sequence repeats.
*/
AgeFunc->editMFCustomSequence()->push_back(0);
AgeFunc->editMFCustomSequence()->push_back(1);
AgeFunc->editMFCustomSequence()->push_back(2);
AgeFunc->editMFCustomSequence()->push_back(3);
AgeFunc->editMFCustomSequence()->push_back(4);
AgeFunc->editMFCustomSequence()->push_back(5);
AgeFunc->editMFCustomSequence()->push_back(4);
AgeFunc->editMFCustomSequence()->push_back(3);
AgeFunc->editMFCustomSequence()->push_back(2);
AgeFunc->editMFCustomSequence()->push_back(1);
//Particle System Drawer -
QuadSequenceParticleSystemDrawerRecPtr ExampleParticleSystemDrawer = QuadSequenceParticleSystemDrawer::create();
// image dimensions (in pixels) are required if there is a border on the images.
ExampleParticleSystemDrawer->setImageDimensions(Vec2us(780,520));
// The "dimensions" of the sequence contained in the image. For this image,
// there are 3 images in the "x" direction, and two in the "y" direction, for a
// total of 6.
ExampleParticleSystemDrawer->setSequenceDimensions(Vec2b(3,2));
// width of the border on each side of the image, in pixels.
ExampleParticleSystemDrawer->setBorderOffsets(Vec2b(0,0));
// this is the age function we just created above.
ExampleParticleSystemDrawer->setSequenceFunction(AgeFunc);
RateParticleGeneratorRecPtr ExampleParticleGenerator = RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleParticleGenerator->setPositionDistribution(createPositionDistribution());
ExampleParticleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleParticleGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleParticleGenerator->setAccelerationDistribution(createAccelerationDistribution());
ExampleParticleGenerator->setSizeDistribution(createSizeDistribution());
ExampleParticleGenerator->setGenerationRate(40.0f);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
//.........这里部分代码省略.........
示例3: 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));
BoostPath FilePath("../Animation/Data/Nanobot.dae");
if(argc >= 2)
{
FilePath = BoostPath(argv[1]);
if(!boost::filesystem::exists(FilePath))
{
std::cerr << "Could not load file: "<< FilePath.string()
<< ", because no such files exists."<< std::endl;
FilePath = BoostPath("../Animation/Data/Nanobot.dae");
}
}
NodeRefPtr LoadedRoot;
std::vector<AnimationRecPtr> LoadedAnimations;
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>();
//.........这里部分代码省略.........
示例4: 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();
// 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->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
TutorialWindow->connectKeyReleased(boost::bind(keyReleased, _1));
//Make Main Scene Node
NodeRefPtr scene = makeCoredNode<Group>();
setName(scene, "scene");
NodeRecPtr rootNode = Node::create();
setName(rootNode, "rootNode");
ComponentTransformRefPtr Trans = ComponentTransform::create();
rootNode->setCore(Trans);
rootNode->addChild(scene);
//Light Beacon
Matrix LightTransformMat;
LightTransformMat.setTranslate(Vec3f(50.0,0.0,100.0));
TransformRefPtr LightTransform = Transform::create();
LightTransform->setMatrix(LightTransformMat);
NodeRefPtr TutorialLightBeacon = Node::create();
TutorialLightBeacon->setCore(LightTransform);
//Light Node
PointLightRefPtr TutorialLight = PointLight::create();
TutorialLight->setBeacon(TutorialLightBeacon);
NodeRefPtr TutorialLightNode = Node::create();
TutorialLightNode->setCore(TutorialLight);
scene->addChild(TutorialLightNode);
scene->addChild(TutorialLightBeacon);
//Setup Physics Scene
PhysicsWorldRecPtr physicsWorld = PhysicsWorld::create();
physicsWorld->setWorldContactSurfaceLayer(0.005);
physicsWorld->setAutoDisableFlag(1);
physicsWorld->setAutoDisableTime(0.75);
physicsWorld->setWorldContactMaxCorrectingVel(100.0);
physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81));
PhysicsHashSpaceRecPtr physicsSpace = PhysicsHashSpace::create();
//Setup the default collision parameters
CollisionContactParametersRefPtr DefaultCollisionParams = CollisionContactParameters::createEmpty();
DefaultCollisionParams->setMode(dContactApprox1);
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;
//.........这里部分代码省略.........
示例5: 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;
}
示例6: main
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->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Particle System Material
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSMaterialChunkChunk);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Pnt3f PositionReturnValue;
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
for(UInt32 i(0) ; i<500 ; ++i)//controls how many particles are created
{
if(PositionDistribution != NULL)
{
PositionReturnValue = Pnt3f(PositionDistribution->generate());
}
ExampleParticleSystem->addParticle(
PositionReturnValue,
PositionReturnValue,
Vec3f(0.0f,0.0f,1.0f),
Color4f(1.0,0.0,0.0,1.0),
Vec3f(1.0,1.0,1.0),
-1, 0,
Vec3f(0.0,0.0,0.0), Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f), //acceleration
StringToUInt32Map() );
}
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
RandomMovementParticleAffectorRecPtr ExampleRMA = RandomMovementParticleAffector::create();
ExampleRMA->setAmplitude(100.0f);
AttributeAttractRepelParticleAffectorRecPtr ExampleAttributeAttractRepelParticleAffector = AttributeAttractRepelParticleAffector::create();
ExampleAttributeAttractRepelParticleAffector->setAttributeAffected(RandomMovementParticleAffector::POSITION_ATTRIBUTE);
ExampleAttributeAttractRepelParticleAffector->setMinDistance(0.0);
ExampleAttributeAttractRepelParticleAffector->setMaxDistance(10000000000000.0);
ExampleAttributeAttractRepelParticleAffector->setQuadratic(0.01);
ExampleAttributeAttractRepelParticleAffector->setLinear(0.01);
ExampleAttributeAttractRepelParticleAffector->setConstant(0.0);
ExampleParticleSystem->pushToAffectors(ExampleRMA);
ExampleParticleSystem->pushToAffectors(ExampleAttributeAttractRepelParticleAffector);
ExampleParticleSystem->setUpdateSecAttribs(false);
//Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
ExampleParticleSystem.get(),
//.........这里部分代码省略.........
示例7: main
int main(int argc, char **argv)
{
preloadSharedObject("OSGImageFileIO");
// 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->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager));
//Particle System Material
//point material
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(5.0f);
PSPointChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSPointMaterial = ChunkMaterial::create();
PSPointMaterial->addChunk(PSPointChunk);
PSPointMaterial->addChunk(PSMaterialChunkChunk);
PSPointMaterial->addChunk(PSBlendChunk);
//smoke material
TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Smoke.png");
QuadTextureObjChunk->setImage(LoadedImage);
TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
QuadTextureEnvChunk->setEnvMode(GL_MODULATE);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSSmokeMaterial = ChunkMaterial::create();
PSSmokeMaterial->addChunk(QuadTextureObjChunk);
PSSmokeMaterial->addChunk(PSMaterialChunk);
PSSmokeMaterial->addChunk(PSBlendChunk);
PSSmokeMaterial->addChunk(QuadTextureEnvChunk);
//Particle System
//Rocket
ParticleSystemRecPtr RocketParticleSystem = ParticleSystem::create();
RocketParticleSystem->attachUpdateProducer(TutorialWindow);
//smoke
ParticleSystemRecPtr SmokeParticleSystem = ParticleSystem::create();
SmokeParticleSystem->attachUpdateProducer(TutorialWindow);
//Shrapnel
ParticleSystemRecPtr ShrapnelParticleSystem = ParticleSystem::create();
ShrapnelParticleSystem->attachUpdateProducer(TutorialWindow);
//Fireball
ParticleSystemRecPtr FireballParticleSystem = ParticleSystem::create();
FireballParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer
//Rocket does not have a drawer because it is being attached to a special node core
//Smoke
QuadParticleSystemDrawerRecPtr SmokeParticleSystemDrawer = QuadParticleSystemDrawer::create();
//SmokeParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.5f,0.5f));
//Shrapnel
PointParticleSystemDrawerRecPtr ExampleShrapnelParticleSystemDrawer = PointParticleSystemDrawer::create();
ExampleShrapnelParticleSystemDrawer->setForcePerParticleSizing(true);
//Fireball
PointParticleSystemDrawerRecPtr ExampleFireballParticleSystemDrawer = PointParticleSystemDrawer::create();
ExampleFireballParticleSystemDrawer->setForcePerParticleSizing(true);
//Particle System Node
//collision node
//NodeRefPtr EnvironmentNode = makeSphere(2,4.0f);
//.........这里部分代码省略.........
示例8: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
//Initialize Window
TutorialWindow->initWindow();
// 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));
//Print key command info
std::cout << "\n\nKEY COMMANDS:" << std::endl;
std::cout << "space Play/Pause the animation" << std::endl;
std::cout << "B Show/Hide the bind pose skeleton" << std::endl;
std::cout << "P Show/Hide the current pose skeleton" << std::endl;
//std::cout << "1 Play first example animation" << std::endl;
//std::cout << "2 Play second example animation" << std::endl;
std::cout << "CTRL-Q Exit\n\n" << std::endl;
//SkeletonDrawer System Material
LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
ExampleLineChunk->setWidth(2.0f);
ExampleLineChunk->setSmooth(true);
BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));
ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
ExampleMaterial->addChunk(ExampleLineChunk);
ExampleMaterial->addChunk(ExampleMaterialChunk);
ExampleMaterial->addChunk(ExampleBlendChunk);
GeometryRefPtr SphereGeometry = makeSphereGeo(2, 0.25f);
GeometryRefPtr BoxGeometry = makeBoxGeo(0.5f,0.5f,0.5f,1,1,1);
//Skeleton
SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create();
//Joint
TransformRecPtr ExampleRootJoint = Transform::create();
NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint);
//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
//.........这里部分代码省略.........
示例9: 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->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Make Base Geometry Node
NodeRecPtr TriGeometryBase = makeTorus(0.5, 1.0, 24, 24);
//Make Main Scene Node
NodeRecPtr scene = makeCoredNode<Group>();
setName(scene, "scene");
NodeRecPtr rootNode = Node::create();
setName(rootNode, "rootNode");
ComponentTransformRecPtr Trans;
Trans = ComponentTransform::create();
rootNode->setCore(Trans);
// add the torus as a child
rootNode->addChild(scene);
//Make The Physics Characteristics Node
PhysicsCharacteristicsDrawableRecPtr PhysDrawable = PhysicsCharacteristicsDrawable::create();
PhysDrawable->setRoot(rootNode);
NodeRecPtr PhysDrawableNode = Node::create();
PhysDrawableNode->setCore(PhysDrawable);
PhysDrawableNode->setTravMask(TypeTraits<UInt32>::getMin());
rootNode->addChild(PhysDrawableNode);
//Setup Physics Scene
PhysicsWorldRecPtr physicsWorld = PhysicsWorld::create();
physicsWorld->setWorldContactSurfaceLayer(0.005);
physicsWorld->setAutoDisableFlag(1);
physicsWorld->setAutoDisableTime(0.75);
physicsWorld->setWorldContactMaxCorrectingVel(100.0);
physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81));
PhysicsHashSpaceRecPtr physicsSpace = PhysicsHashSpace::create();
PhysicsHandlerRecPtr physHandler = PhysicsHandler::create();
physHandler->setWorld(physicsWorld);
physHandler->pushToSpaces(physicsSpace);
physHandler->setUpdateNode(rootNode);
physHandler->attachUpdateProducer(TutorialWindow);
/************************************************************************/
/* create spaces, geoms and bodys */
/************************************************************************/
//create a group for our space
GroupRecPtr spaceGroup;
NodeRecPtr spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
//create the ground plane
GeometryRecPtr plane;
NodeRecPtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1);
plane = dynamic_cast<Geometry*>(planeNode->getCore());
//and its Material
SimpleMaterialRecPtr plane_mat = SimpleMaterial::create();
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);
//.........这里部分代码省略.........
示例10: main
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));
//Particle System Material
PointChunkRecPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(5.0f);
PSPointChunk->setSmooth(true);
BlendChunkRecPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRecPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.5f,0.5f,0.5f,0.3f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.8f,0.8f,0.8f,0.3f));
PSMaterialChunkChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,0.3f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRecPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
for(UInt32 i(0) ; i<10 ; ++i)
{
ExampleParticleSystem->addParticle(Pnt3f(i,i,i),
Vec3f(0.0,0.0f,1.0f),
Color4f(1.0,0.0,0.0,0.5),
Vec3f(1.0,1.0,1.0),
-1.0,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
}
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer
//Point
PointParticleSystemDrawerRecPtr ExamplePointDrawer = PointParticleSystemDrawer::create();
//ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true);
//Line
LineParticleSystemDrawerRecPtr ExampleLineDrawer = LineParticleSystemDrawer::create();
ExampleLineDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE);
ExampleLineDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X);
//Quad
QuadParticleSystemDrawerRecPtr ExampleQuadDrawer = QuadParticleSystemDrawer::create();
//Disc
DiscParticleSystemDrawerRecPtr ExampleDiscDrawer = DiscParticleSystemDrawer::create();
ExampleDiscDrawer->setSegments(16);
ExampleDiscDrawer->setCenterAlpha(1.0);
ExampleDiscDrawer->setEdgeAlpha(0.0);
//Particle System Node
ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleLineDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRecPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
sceneManager.setRoot(scene);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
ParticleNodeCore.get(),
ExamplePointDrawer,
ExampleLineDrawer,
//.........这里部分代码省略.........
示例11: main
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));
//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));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
VideoWrapperRecPtr TheVideo = getDefaultVideoManager()->createVideoWrapper();
TheVideo->attachUpdateProducer(TutorialWindow);
TheVideo->connectStarted(boost::bind(handleVideoStarted, _1));
TheVideo->connectPaused(boost::bind(handleVideoPaused, _1));
TheVideo->connectUnpaused(boost::bind(handleVideoUnpaused, _1));
TheVideo->connectStopped(boost::bind(handleVideoStopped, _1));
TheVideo->connectClosed(boost::bind(handleVideoClosed, _1));
TheVideo->connectSeeked(boost::bind(handleVideoSeeked, _1));
TheVideo->connectCycled(boost::bind(handleVideoCycled, _1));
TheVideo->connectOpened(boost::bind(handleVideoOpened, _1));
TheVideo->connectEnded(boost::bind(handleVideoEnded, _1));
BoostPath VideoFilePath("./Data/ExampleVideo.avi");
if(argc >= 2)
{
VideoFilePath = BoostPath(argv[1]);
if(!boost::filesystem::exists(VideoFilePath))
{
std::cerr << "Could not load file: "<< VideoFilePath.string()
<< ", because no such files exists."<< std::endl;
VideoFilePath = BoostPath("./Data/ExampleVideo.avi");
}
}
TheVideo->open(VideoFilePath, TutorialWindow);
TheVideo->pause();
if(TheVideo->hasAudio())
{
TheVideo->enableAudio();
TheVideo->setAudioVolume(0.5f);
}
//Wait for the video to initialize
std::cout << "Dimensions: " << TheVideo->getWidth()
<< "x" << TheVideo->getHeight()
<< std::endl;
Real32 AspectRatio(static_cast<Real32>(TheVideo->getWidth())/static_cast<Real32>(TheVideo->getHeight()));
//Real32 AspectRatio(4.0f/3.0f);
// Set filtering modes. LINEAR is cheap and good if the image size
// changes very little (i.e. the window is about the same size as
// the images).
//TheVideo->setMinFilter(GL_LINEAR);
TheVideo->setMinFilter(GL_NEAREST);
TheVideo->setMagFilter(GL_LINEAR);
//TheVideo->setMagFilter(GL_NEAREST);
// Set the wrapping modes. We don't need repetition, it might actually
// introduce artifactes at the borders, so switch it off.
TheVideo->setWrapS(GL_CLAMP_TO_EDGE);
TheVideo->setWrapT(GL_CLAMP_TO_EDGE);
TheVideo->setScale(false);
ChunkMaterialUnrecPtr VideoMaterial = ChunkMaterial::create();
VideoMaterial->addChunk(TheVideo);
StateChunkUnrecPtr pMChunk = MaterialChunk::create();
VideoMaterial->addChunk(pMChunk);
// create the scene
//Plane Geometry
GeometryRecPtr PlaneGeometry = makePlaneGeo(10.0*AspectRatio,10.0,10,10);
PlaneGeometry->setMaterial(VideoMaterial);
NodeRecPtr PlaneGeometryNode = Node::create();
PlaneGeometryNode->setCore(PlaneGeometry);
//Box Geometry
GeometryRecPtr BoxGeometry = makeBoxGeo(10.0*AspectRatio,10.0,10.0,2,2,2);
BoxGeometry->setMaterial(VideoMaterial);
NodeRecPtr BoxGeometryNode = Node::create();
BoxGeometryNode->setCore(BoxGeometry);
//.........这里部分代码省略.........
示例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
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->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager));
//Particle System Material
LineChunkRefPtr PSLineChunk = LineChunk::create();
PSLineChunk->setWidth(2.0f);
PSLineChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,0.5f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,0.5f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSLineChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->addParticle(Pnt3f(-400,-400,0),
Vec3f(0.0,0.0f,1.0f),
Color4f(1.0,1.0,1.0,1.0),
Vec3f(1.0,1.0,1.0),
0.25,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->addParticle(Pnt3f(400,400,0),
Vec3f(0.0,0.0f,1.0f),
Color4f(1.0,1.0,1.0,1.0),
Vec3f(1.0,1.0,1.0),
0.25,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer (Line)
LineParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = LineParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY);
ExampleParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SPEED);
ExampleParticleSystemDrawer->setLineLengthScaling(0.001);
ExampleParticleSystemDrawer->setEndPointFading(Vec2f(0.0f,1.0f));
//Create a Rate Particle Generator
RateParticleGeneratorRefPtr ExampleGenerator = RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setGenerationRate(300.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
//Attach the Generator to the Particle System
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
//.........这里部分代码省略.........
示例13: main
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);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));
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));
BoostPath EffectFilePath("./Data/goochyPt.cgfx");
if(argc >= 2)
{
EffectFilePath = BoostPath(argv[1]);
if(!boost::filesystem::exists(EffectFilePath))
{
std::cerr << "Could not load file: "<< EffectFilePath.string()
<< ", because no such files exists."<< std::endl;
EffectFilePath = BoostPath("./Data/goochyPt.cgfx");
}
}
//Make the CgFX Material
CgFXMaterialRecPtr ExampleMaterial = CgFXMaterial::create();
ExampleMaterial->setEffectFile(EffectFilePath.string());
// Make Torus Node (creates Torus in background of scene)
GeometryRefPtr TorusGeometry = makeTorusGeo(.5, 2, 16, 16);
//GeometryRefPtr TorusGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1);
TorusGeometry->setMaterial(ExampleMaterial);
TorusGeometry->setDlistCache(false);
NodeRefPtr TorusGeometryNode = makeNodeFor(TorusGeometry);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(TorusGeometryNode);
sceneManager.setRoot(scene);
//Create the Documentation Foreground and add it to the viewport
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,
"04CgFXMaterial");
commitChanges();
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例14: 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);
//.........这里部分代码省略.........
示例15: 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();
}
//.........这里部分代码省略.........