本文整理汇总了C++中ParticleSystemRefPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ParticleSystemRefPtr类的具体用法?C++ ParticleSystemRefPtr怎么用?C++ ParticleSystemRefPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParticleSystemRefPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: affect
bool TurbulenceParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
if(getBeacon() != NULL)
{
Matrix BeaconToWorld(getBeacon()->getToWorld());
Vec3f translation, tmp;
Quaternion tmp2;
BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2);
Pnt3f particlePos = System->getPosition(ParticleIndex);
Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z()));
if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range
{
Real32 Xparam, Yparam, Zparam;
Pnt3f pos(System->getPosition(ParticleIndex));
getPerlinDistribution()->setPhase(getPhase()[0]);
Xparam = getPerlinDistribution()->generate(pos[0]);
getPerlinDistribution()->setPhase(getPhase()[1]);
Yparam = getPerlinDistribution()->generate(pos[1]);
getPerlinDistribution()->setPhase(getPhase()[2]);
Zparam = getPerlinDistribution()->generate(pos[2]);
Vec3f fieldAffect(Vec3f(Xparam, Yparam, Zparam));
fieldAffect = fieldAffect * (getAmplitude()*
(elps/(OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax()))));
System->setVelocity(System->getVelocity(ParticleIndex) + fieldAffect, ParticleIndex);
} // end distance conditional
} // end null beacon conditional
return false;
}
示例2: affect
bool AttributeAttractRepelParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
if(System != NULL)
{
Vec3f Displacement(System->getSecPosition(ParticleIndex) - System->getPosition(ParticleIndex) );
Real32 Distance(Displacement.squareLength());
if((Distance > getMinDistance()*getMinDistance()) &&
(Distance < getMaxDistance()*getMaxDistance()))
{
Distance = osgSqrt(Distance);
Displacement.normalize();
Real32 t((getQuadratic() * (Distance*Distance) + getLinear() * Distance + getConstant())*elps);
if(t > Distance)
{
t=Distance;
}
System->setPosition(System->getPosition(ParticleIndex) + (Displacement * t),ParticleIndex) ;
}
}
return false;
}
示例3: affect
bool VortexParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
if(getBeacon() != NULL)
{
Matrix BeaconToWorld(getBeacon()->getToWorld());
Vec3f translation, tmp;
Quaternion tmp2;
BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2);
Pnt3f particlePos = System->getPosition(ParticleIndex);
Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z()));
if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range
{
Vec3f particleDirectionFromVortex(particlePos.x() - translation.x(), particlePos.y() - translation.y(), particlePos.z() - translation.z());
particleDirectionFromVortex = particleDirectionFromVortex.cross(getVortexAxis());
particleDirectionFromVortex.normalize();
particleDirectionFromVortex = particleDirectionFromVortex *
((-getMagnitude() *
elps)/OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax()));
System->setVelocity(particleDirectionFromVortex + System->getVelocity(ParticleIndex),ParticleIndex);
}
}
return false;
}
示例4: affect
void GeometryCollisionParticleSystemAffector::affect(ParticleSystemRefPtr System, const Time& elps)
{
UInt32 NumParticles(System->getNumParticles());
Line ray;
IntersectAction *iAct = IntersectAction::create();
Pnt3f ParticlePos, ParticleSecPos;
Real32 HitT(0.0f);
for(UInt32 i(0) ; i<NumParticles ; ++i)
{
ParticlePos = System->getPosition(i);
ParticleSecPos = System->getSecPosition(i);
ray.setValue(ParticleSecPos, ParticlePos);
iAct->setLine(ray);
iAct->apply(getCollisionNode());
if (iAct->didHit())
{
HitT = iAct->getHitT();
if(HitT > 0.0f && HitT*HitT<ParticlePos.dist2(ParticleSecPos))
{
produceParticleCollision(System, i, iAct);
for(UInt32 j(0) ; j<getMFCollisionAffectors()->size(); ++j)
{
getCollisionAffectors(i)->affect(System,i,elps);
}
}
}
}
}
示例5: affect
bool RandomMovementParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
//System->setUpdateSecAttribs(false);
Real32 x,
y,
z,
age(System->getAge(ParticleIndex));
if(getAttributeAffected() == VELOCITY_ATTRIBUTE)
{
Vec3f vel = System->getSecVelocity(ParticleIndex);
// grab each value independently , and adjust the phase for each
// axis, since we have a 3D phase and the 1D distribution only takes
// one value
Real32 velSum = vel.x() + vel.y() + vel.z();
getPerlinDistribution()->setPhase(getPhase().x() + velSum);
x = getPerlinDistribution()->generate(vel.x() + age);
getPerlinDistribution()->setPhase(getPhase().y() + velSum);
y = getPerlinDistribution()->generate(vel.y() + age);
getPerlinDistribution()->setPhase(getPhase().z() + velSum);
z = getPerlinDistribution()->generate(vel.z() + age);
System->setVelocity(Vec3f(x,y,z) + vel,ParticleIndex);
}else // affecting position
{
Pnt3f pos = System->getSecPosition(ParticleIndex);
Real32 posSum = pos.x() + pos.y() + pos.z();
getPerlinDistribution()->setPhase(getPhase().x() + posSum);
x = getPerlinDistribution()->generate(pos.x() + age);
getPerlinDistribution()->setPhase(getPhase().y() + posSum);
y = getPerlinDistribution()->generate(pos.y() + age);
getPerlinDistribution()->setPhase(getPhase().z() + posSum);
z = getPerlinDistribution()->generate(pos.z() + age);
System->setPosition(Pnt3f(x,y,z) + pos.subZero(),ParticleIndex);
}
return false;
}
示例6: affect
bool AgeSizeParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
if(getMFAges()->size()!=getMFSizes()->size())
{
return false;
}
else
{
Real32 time;
UInt32 i(0);
Real32 Age(System->getAge(ParticleIndex)),Lifespan(System->getLifespan(ParticleIndex));
if(Lifespan < 0.0)
{
return false;
}
time = (Age)/(Lifespan);
for( ;i<getMFAges()->size() && time>getAges(i);++i)
{
}
if(i == getMFSizes()->size())
{
System->setSize(getMFSizes()->back(),ParticleIndex);
}
else if(i == 0.0)
{
System->setSize(getMFSizes()->front(),ParticleIndex);
}
else
{
Vec3f size;
time = (time - getAges(i-1))/(getAges(i)-getAges(i-1));
lerp(getSizes(i-1),getSizes(i),time,size);
System->setSize(size,ParticleIndex);
}
}
return false;
}
示例7: affect
bool AgeFadeParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
Real32 Alpha(0.0f);
if(System->getAge(ParticleIndex)<getFadeInTime())
{
lerp<Real32>(getStartAlpha(), getFadeToAlpha(),1.0f-((getFadeInTime() - System->getAge(ParticleIndex))/getFadeInTime()), Alpha);
}
else if(System->getLifespan(ParticleIndex) < 0 || (System->getAge(ParticleIndex)< System->getLifespan(ParticleIndex)-getFadeOutTime()))
{
Alpha = getFadeToAlpha();
}
else
{
//lerp
lerp<Real32>(getFadeToAlpha(), getEndAlpha(), ((System->getAge(ParticleIndex)-System->getLifespan(ParticleIndex)+getFadeOutTime())/(getFadeOutTime())), Alpha);
}
Color4f Color = System->getColor(ParticleIndex);
Color[3] = Alpha;
System->setColor(Color, ParticleIndex);
return false;
}
示例8: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
//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);
PSMaterial->addChunk(PSBlendChunk);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Pnt3f PositionReturnValue;
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
for(UInt32 i(0) ; i<800 ; ++i)//controls how many particles are created
{
if(PositionDistribution != NULL)
{
PositionReturnValue = Pnt3f(PositionDistribution->generate());
}
ExampleParticleSystem->addParticle(
PositionReturnValue,
Vec3f(0.0f,0.0f,1.0f),
Color4f(1.0,0.0,0.0,1.0),
Vec3f(10.0,10.0,10.0),
-1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f) //acceleration
);
}
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Particle System Drawer
DiscParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::DiscParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setSegments(16);
ExampleParticleSystemDrawer->setCenterAlpha(1.0);
ExampleParticleSystemDrawer->setEdgeAlpha(0.0);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
//AttractionNode
TransformRefPtr AttractionCore = OSG::Transform::create();
Matrix AttractTransform;
AttractTransform.setTranslate(0.0f, 0.0,0.0);
AttractionCore->setMatrix(AttractTransform);
NodeRefPtr AttractionNode = OSG::Node::create();
AttractionNode->setCore(AttractionCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(ParticleNode);
scene->addChild(AttractionNode);
mgr->setRoot(scene);
// Show the whole Scene
//.........这里部分代码省略.........
示例9: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//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 = OSG::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->attachUpdateListener(TutorialWindow);
//Particle System Drawer (Line)
LineParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::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 = OSG::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 = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(ParticleNode);
//.........这里部分代码省略.........
示例10: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
//Add Key Listener
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
//Add Mouse Listeners
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
// open window
/* Set up complete, now performing XML import */
BoostPath ExecutableDirectory(argv[0]);
ExecutableDirectory.remove_leaf();
BoostPath FilePath;
if(argc > 1)
{
FilePath = BoostPath(argv[1]);
}
else
{
FilePath = BoostPath("./Data/mayaExport1.xml");
}
if(!boost::filesystem::exists(FilePath))
{
std::cerr << "Could not find file by path: " << FilePath.string() << std::endl;
osgExit();
return -1;
}
// parse XML file to get field container data
FCFileType::FCPtrStore NewContainers;
NewContainers = FCFileHandler::the()->read(FilePath);
// find root node from container, attach update listeners to particle systems
std::vector<NodeRefPtr> RootNodes;
for(FCFileType::FCPtrStore::iterator Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
{
// get root node
if( (*Itor)->getType() == Node::getClassType() &&
dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL)
{
RootNodes.push_back(dynamic_pointer_cast<Node>(*Itor));
}
else if( (*Itor)->getType() == ParticleSystem::getClassType()) //attach update listeners to particle systems present
{
ParticleSystemRefPtr ExampleParticleSystems = dynamic_pointer_cast<ParticleSystem>(*Itor);
ExampleParticleSystems->attachUpdateListener(TutorialWindow);
}
}
// get root node that was extracted from XML file
if(RootNodes.size() > 0)
{
NodeRefPtr scene = RootNodes[0];
// set root node
mgr->setRoot(scene);
}
// Show the whole Scene
mgr->showAll();
mgr->setHeadlight(true);
mgr->getCamera()->setFar(10000);
// main loop
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"15FCFileTypeIO");
//Enter main Loop
TutorialWindow->mainLoop();
osgExit();
//.........这里部分代码省略.........
示例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));
// 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(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(1.0f,1.0f,1.0f,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(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->addParticle(Pnt3f(0,-100,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.1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->addParticle(Pnt3f(0,100,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.1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer (Point)
PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create();
//Particle System Drawer (line)
LineParticleSystemDrawerRecPtr ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create();
ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY);
ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X);
ExampleLineParticleSystemDrawer->setLineLength(2.0f);
ExampleLineParticleSystemDrawer->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(60.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
VortexParticleAffectorRecPtr ExampleVortexAffector = VortexParticleAffector::create();
ExampleVortexAffector->setMagnitude(20.0);
ExampleVortexAffector->setVortexAxis(Vec3f(0.0,0.0,1.0)); // field rotates around z axis
NodeRefPtr VortexBeacon = Node::create();
ExampleVortexAffector->setBeacon(VortexBeacon); // set to 'emulate' from (0,0,0)
ExampleVortexAffector->setMaxDistance(-1.0); // particles affected regardless of distance
ExampleVortexAffector->setAttenuation(0.25); // strength of uniform field dimishes by dist^attenuation
//Attach the Generator and Affector to the Particle System
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
ExampleParticleSystem->pushToAffectors(ExampleVortexAffector);
ExampleParticleSystem->setMaxParticles(800);
//Particle System Node
ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create();
//.........这里部分代码省略.........
示例12: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
PointParticleSystemDrawerRefPtr ExamplePointParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
//NodeRefPtr ParticlePrototypeNode = makeTorus(1.0,4.0,16,16);
//NodeRefPtr CollisionNode = makeBox(5.0,5.0,5.0,1,1,1);//makeSphere(4,10.0f);
NodeRefPtr CollisionNode = makeSphere(2,4.0f);
//Particle System 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(1.0f,0.0f,0.0f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(1.0f,0.0f,0.0f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(1.0f,0.0f,0.0f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_NONE);
//PSMaterialChunkChunk->setLit(false);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
//Generator
//Attach the function objects to the Generator
RateParticleGeneratorRefPtr ExampleGenerator= RateParticleGenerator::create();
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setGenerationRate(20.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
//Geometry Collision Affector
GeometryCollisionParticleSystemAffectorRefPtr ExampleGeometryCollisionParticleSystemAffector = GeometryCollisionParticleSystemAffector::create();
ExampleGeometryCollisionParticleSystemAffector->setCollisionNode(CollisionNode);
TutorialParticleCollisionListener TheCollisionListener;
ExampleGeometryCollisionParticleSystemAffector->addParticleGeometryCollisionListener(&TheCollisionListener);
ExampleParticleSystem->pushToSystemAffectors(ExampleGeometryCollisionParticleSystemAffector);
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(ParticleNode);
scene->addChild(CollisionNode);
mgr->setRoot(scene);
// Show the whole Scene
mgr->showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"13CollisionGeometry");
//.........这里部分代码省略.........
示例13: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System Material
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(20.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 PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Distribution1DRefPtr LifespanDistribution = createLifespanDistribution();
Pnt3f PositionReturnValue;
Time LifespanReturnValue = -1;
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
for(UInt32 i(0) ; i<200 ; ++i)//controls how many particles are created
{
if(PositionDistribution != NULL)
{
PositionReturnValue = Pnt3f(PositionDistribution->generate());
}
if(LifespanDistribution != NULL)
{
LifespanReturnValue = LifespanDistribution->generate();
}
ExampleParticleSystem->addParticle(
PositionReturnValue,
Vec3f(0.0f,0.0f,1.0f),
Color4f(1.0,0.0,0.0,1.0),
Vec3f(1.0,1.0,1.0),
LifespanReturnValue,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f) //acceleration
);
}
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Particle System Drawer
PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
//Create an CollectiveGravityParticleSystemAffector
CollectiveGravityParticleSystemAffectorRefPtr ExampleCollectiveGravityParticleSystemAffector = OSG::CollectiveGravityParticleSystemAffector::create();
ExampleCollectiveGravityParticleSystemAffector->setParticleMass(10000000000.0f);
ExampleParticleSystem->pushToSystemAffectors(ExampleCollectiveGravityParticleSystemAffector);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(ParticleNode);
//.........这里部分代码省略.........
示例14: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System 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(1.0f,1.0f,1.0f,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(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
ExampleParticleSystem->addParticle(Pnt3f(0,0,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.1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->addParticle(Pnt3f(50,0,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.1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Particle System Drawer (Point)
ExamplePointParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
//Particle System Drawer (line)
ExampleLineParticleSystemDrawer = OSG::LineParticleSystemDrawer::create();
ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY);
ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X);
ExampleLineParticleSystemDrawer->setLineLength(0.5f);
ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(1.0f,0.0f));
//Create a Rate Particle Generator
RateParticleGeneratorRefPtr ExampleGenerator = OSG::RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleGenerator->setGenerationRate(2.0);
ExampleConserveVelocityAffector = OSG::ConserveVelocityParticleAffector::create();
ExampleConserveVelocityAffector->setConserve(0.0); // all velocity conserved initially. Use keys 3 and 4 to change this value while running.
//Attach the Generator and Affector to the Particle System
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
ExampleParticleSystem->pushToAffectors(ExampleConserveVelocityAffector);
ExampleParticleSystem->setMaxParticles(500);
//Particle System Node
ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
//.........这里部分代码省略.........
示例15: particleKilled
virtual void particleKilled(const ParticleEventUnrecPtr e)
{
dynamic_pointer_cast<SphereDistribution3D>(FireballPositionDistribution)->setCenter(e->getParticlePosition());
dynamic_pointer_cast<SphereDistribution3D>(ShrapnelPositionDistribution)->setCenter(e->getParticlePosition());
dynamic_pointer_cast<DiscDistribution3D>(SmokePositionDistribution)->setCenter(e->getParticlePosition());
// if()
{
//Attach the Generator to the Shrapnel Particle System
ShrapnelParticleSystem->pushToGenerators(ShrapnelBurstGenerator);
//Attach the Affector to the Smoke Particle System
SmokeParticleSystem->pushToGenerators(SmokeGenerator);
SmokeParticleSystem->pushToAffectors(SmokeAgeFadeParticleAffector);
SmokeParticleSystem->pushToAffectors(SmokeAgeSizeParticleAffector);
//Attach the Affector to the fireball Particle System
FireballParticleSystem->pushToGenerators(FireballGenerator);
FireballParticleSystem->pushToAffectors(FireballAgeSizeParticleAffector);
}
std::cout << "Rocket Died at: " << e->getParticlePosition() << std::endl;
}