本文整理汇总了C++中PUParticleSystem3D类的典型用法代码示例。如果您正苦于以下问题:C++ PUParticleSystem3D类的具体用法?C++ PUParticleSystem3D怎么用?C++ PUParticleSystem3D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PUParticleSystem3D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertToUnixStylePath
PUParticleSystem3D* PUParticleSystem3D::create( const std::string &filePath )
{
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
convertToUnixStylePath(fullPath);
std::string::size_type pos = fullPath.find_last_of("/");
std::string materialFolder = "materials";
if (pos != std::string::npos){
std::string temp = fullPath.substr(0, pos);
pos = temp.find_last_of("/");
if (pos != std::string::npos){
materialFolder = temp.substr(0, pos + 1) + materialFolder;
}
}
static std::vector<std::string> loadedFolder;
if (std::find(loadedFolder.begin(), loadedFolder.end(), materialFolder) == loadedFolder.end())
{
PUMaterialCache::Instance()->loadMaterialsFromSearchPaths(materialFolder);
loadedFolder.push_back(materialFolder);
}
PUParticleSystem3D* ps = PUParticleSystem3D::create();
if (!ps->initSystem(fullPath)){
CC_SAFE_DELETE(ps);
}
return ps;
}
示例2:
void PUParticleSystem3D::resumeParticleSystem()
{
if (_state == State::PAUSE)
{
//if (_emitter)
//{
// auto emitter = static_cast<PUEmitter*>(_emitter);
// emitter->notifyResume();
//}
for (auto& it : _emitters) {
auto emitter = static_cast<PUEmitter*>(it);
emitter->notifyResume();
}
for (auto& it : _affectors) {
auto affector = static_cast<PUAffector*>(it);
affector->notifyResume();
}
_state = State::RUNNING;
}
for (auto iter : _children)
{
PUParticleSystem3D *system = dynamic_cast<PUParticleSystem3D *>(iter);
if (system)
system->resumeParticleSystem();
}
}
示例3: if
void PUParticleSystem3D::initParticleForExpiration( PUParticle3D* particle, float timeElapsed )
{
if (particle->particleType == PUParticle3D::PT_EMITTER){
PUEmitter *emitter = static_cast<PUEmitter *>(particle->particleEntityPtr);
emitter->unPrepare();
}else if (particle->particleType == PUParticle3D::PT_TECHNIQUE){
PUParticleSystem3D *system = static_cast<PUParticleSystem3D *>(particle->particleEntityPtr);
system->unPrepared();
}
particle->initForExpiration(timeElapsed);
for (auto it : _listeners){
it->particleExpired(this, particle);
}
///** Externs are also called to perform expiration activities. If needed, affectors and emitters may be added, but at the moment
// there is no reason for (and we don´t want to waste cpu resources).
//*/
//if (!mExterns.empty())
//{
// ExternIterator itExtern;
// ExternIterator itExternEnd = mExterns.end();
// for (itExtern = mExterns.begin(); itExtern != itExternEnd; ++itExtern)
// {
// (*itExtern)->_initParticleForExpiration(particle);
// }
//}
}
示例4: if
void PUEmitter::prepare()
{
if (!_emitsEntity){
if (_emitsType == PUParticle3D::PT_EMITTER){
auto emitter = static_cast<PUParticleSystem3D *>(_particleSystem)->getEmitter(_emitsName);
if (emitter){
emitter->setMarkedForEmission(true);
_emitsEntity = emitter;
}
}
else if (_emitsType == PUParticle3D::PT_TECHNIQUE){
PUParticleSystem3D *system = static_cast<PUParticleSystem3D *>(_particleSystem)->getParentParticleSystem();
if (system){
auto children = system->getChildren();
for (auto it : children){
if (it->getName() == _emitsName)
{
static_cast<PUParticleSystem3D *>(it)->setMarkedForEmission(true);
_emitsEntity = it;
break;
}
}
}
}
}
_latestPosition = getDerivedPosition(); // V1.3.1
}
示例5:
const Vec3& PUAffector::getDerivedPosition()
{
PUParticleSystem3D *ps = static_cast<PUParticleSystem3D *>(_particleSystem);
if (ps){
Mat4 rotMat;
Mat4::createRotation(ps->getDerivedOrientation(), &rotMat);
_derivedPosition = ps->getDerivedPosition() + rotMat * Vec3(_position.x * _affectorScale.x, _position.y * _affectorScale.y, _position.z * _affectorScale.z);
//_particleSystem->getNodeToWorldTransform().transformPoint(_position, &_derivedPosition);
}
else
_derivedPosition = _position;
return _derivedPosition;
//if (mMarkedForEmission)
//{
// // Use the affector position, because it is emitted
// // If a particle is emitted, position and derived position are the same
// _derivedPosition = position;
//}
//else
//{
// // Add the techniques' derived position
// _derivedPosition = mParentTechnique->getDerivedPosition() +
// mParentTechnique->getParentSystem()->getDerivedOrientation() * (_mAffectorScale * position);
//}
//return _derivedPosition;
}
示例6: handle
//-----------------------------------------------------------------------
void PUDoPlacementParticleEventHandler::handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed)
{
if (!particle)
return;
if (!_found)
{
auto system = particleSystem;
auto emitter = system->getEmitter(_forceEmitterName);
//ParticleTechnique* technique = particleTechnique;
//ParticleEmitter* emitter = particleTechnique->getEmitter(_forceEmitterName);
if (!emitter)
{
// Search all techniques in this ParticleSystem for an emitter with the correct name
PUParticleSystem3D* parentSystem = particleSystem->getParentParticleSystem();
if (parentSystem){
auto children = parentSystem->getChildren();
for(auto iter : children)
{
PUParticleSystem3D *child = dynamic_cast<PUParticleSystem3D *>(iter);
if (child){
system = child;
emitter = system->getEmitter(_forceEmitterName);
if (emitter)
{
break;
}
}
}
}
}
if (emitter)
{
_system = system;
_emitter = emitter;
if (_system)
{
_system->addListener(this);
}
_found = true;
}
else
{
return;
}
}
// Emit 1 or more particles
if (_system)
{
_baseParticle = particle;
_system->forceEmission(_emitter, _numberOfParticles);
}
_baseParticle = 0;
}
示例7: copyAttributesTo
PUParticleSystem3D* PUParticleSystem3D::clone()
{
auto ps = PUParticleSystem3D::create();
copyAttributesTo(ps);
for (auto &iter : _children){
PUParticleSystem3D *child = dynamic_cast<PUParticleSystem3D *>(iter);
if (child)
ps->addChild(child->clone());
}
return ps;
}
示例8:
const Vec3& PUEmitter::getDerivedPosition()
{
if (_isMarkedForEmission){
_derivedPosition = _position;
}else {
PUParticleSystem3D *ps = static_cast<PUParticleSystem3D *>(_particleSystem);
Mat4 rotMat;
Mat4::createRotation(ps->getDerivedOrientation(), &rotMat);
_derivedPosition = ps->getDerivedPosition() + rotMat * Vec3(_position.x * _emitterScale.x, _position.y * _emitterScale.y, _position.z * _emitterScale.z);
//_particleSystem->getNodeToWorldTransform().transformPoint(_position, &_derivedPosition);
}
return _derivedPosition;
}
示例9: new
PUParticleSystem3D* PUParticleSystem3D::create( const std::string &filePath )
{
PUParticleSystem3D *ret = new (std::nothrow) PUParticleSystem3D();
if (ret && ret->initWithFilePath(filePath))
{
ret->autorelease();
return ret;
}
else
{
CC_SAFE_DELETE(ret);
return nullptr;
}
}
示例10: preUpdateAffector
void PUVortexAffector::preUpdateAffector( float deltaTime )
{
PUParticleSystem3D* sys = static_cast<PUParticleSystem3D *>(_particleSystem);
if (sys)
{
Mat4 rotMat;
Mat4::createRotation(sys->getDerivedOrientation(), &rotMat);
_rotation.set(rotMat * _rotationVector, float(calculateRotationSpeed() * deltaTime));
}
else
{
_rotation.set(_rotationVector, float(calculateRotationSpeed() * deltaTime));
}
getDerivedPosition();
}
示例11: setPropsWithFlatBuffers
Node* Particle3DReader::createNodeWithFlatBuffers(const flatbuffers::Table *particle3DOptions)
{
auto options = (Particle3DOptions*)particle3DOptions;
auto fileData = options->fileData();
std::string path = fileData->path()->c_str();
PUParticleSystem3D* ret = PUParticleSystem3D::create();
if (FileUtils::getInstance()->isFileExist(path))
{
ret->initWithFilePath(path);
}
setPropsWithFlatBuffers(ret, particle3DOptions);
if(ret)
{
ret->startParticleSystem();
}
return ret;
}
示例12: handle
//-----------------------------------------------------------------------
void PUDoAffectorEventHandler::handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed)
{
/** Search for the affector.
*/
PUParticleSystem3D* technique = 0;
PUAffector* affector = particleSystem->getAffector(_affectorName);
if (!affector)
{
// Search all techniques in this ParticleSystem for an affector with the correct name
PUParticleSystem3D* system = particleSystem->getParentParticleSystem();
auto children = system->getChildren();
for(auto iter : children)
{
technique = dynamic_cast<PUParticleSystem3D *>(iter);
if (technique){
affector = technique->getAffector(_affectorName);
if (affector)
{
break;
}
}
}
}
if (affector)
{
// Call the affector even if it has enabled set to 'false'.
if (_prePost)
{
affector->preUpdateAffector(timeElapsed);
affector->updatePUAffector(particle, timeElapsed);
affector->postUpdateAffector(timeElapsed);
}
else
{
affector->updatePUAffector(particle, timeElapsed);
}
}
}
示例13: stopParticleSystem
void PUParticleSystem3D::startParticleSystem()
{
stopParticleSystem();
if (_state != State::RUNNING)
{
forceStopParticleSystem();
if (_render)
_render->notifyStart();
for (auto &it : _observers){
it->notifyStart();
}
for (auto& it : _emitters) {
auto emitter = static_cast<PUEmitter*>(it);
emitter->notifyStart();
}
for (auto& it : _affectors) {
auto affector = static_cast<PUAffector*>(it);
affector->notifyStart();
}
scheduleUpdate();
_state = State::RUNNING;
_latestPosition = getDerivedPosition(); // V1.3.1
}
for (auto iter : _children)
{
PUParticleSystem3D *system = dynamic_cast<PUParticleSystem3D *>(iter);
if (system){
system->_parentParticleSystem = this;
system->startParticleSystem();
}
}
}
示例14: translate
void PUTechniqueTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
{
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
// Create the technique
_system = PUParticleSystem3D::create();
//mTechnique = ParticleSystemManager::getSingletonPtr()->createTechnique();
//if (!mTechnique)
//{
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
// return;
//}
if (parent && parent->context)
{
PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
system->addChild(_system);
}
//else
//{
// // It is an alias
// mTechnique->setAliasName(parent->name); // PU 1.4
// ParticleSystemManager::getSingletonPtr()->addAlias(mTechnique);
//}
_system->setName(obj->name);
obj->context = _system; // Add this to the context, because it is needed for the underlying emitters, affectors, ...
// Get the name of the technique
//if(!obj->name.empty())
// mTechnique->setName(obj->name);
for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
{
if((*i)->type == ANT_PROPERTY)
{
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
if (prop->name == token[TOKEN_ENABLED])
{
// Property: enabled
if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL))
{
bool val;
if(getBoolean(*prop->values.front(), &val))
{
_system->setEnabled(val);
}
}
}
else if (prop->name == token[TOKEN_POSITION])
{
// Property: positon
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
{
Vec3 val;
if(getVector3(prop->values.begin(), prop->values.end(), &val))
{
_system->setPosition3D(val);
}
}
}
else if (prop->name == token[TOKEN_KEEP_LOCAL])
{
// Property: keep_local
if (passValidateProperty(compiler, prop, token[TOKEN_KEEP_LOCAL], VAL_BOOL))
{
bool val;
if(getBoolean(*prop->values.front(), &val))
{
_system->setKeepLocal(val);
}
}
}
else if (prop->name == token[TOKEN_TECH_VISUAL_PARTICLE_QUOTA])
{
// Property: visual_particle_quota
if (passValidateProperty(compiler, prop, token[TOKEN_TECH_VISUAL_PARTICLE_QUOTA], VAL_UINT))
{
unsigned int val = 0;
if(getUInt(*prop->values.front(), &val))
{
_system->setParticleQuota(val);
}
}
}
else if (prop->name == token[TOKEN_TECH_EMITTED_EMITTER_QUOTA])
{
// Property: emitted_emitter_quota
if (passValidateProperty(compiler, prop, token[TOKEN_TECH_EMITTED_EMITTER_QUOTA], VAL_UINT))
{
unsigned int val = 0;
if(getUInt(*prop->values.front(), &val))
{
_system->setEmittedEmitterQuota(val);
}
}
}
else if (prop->name == token[TOKEN_TECH_EMITTED_AFFECTOR_QUOTA])
{
//.........这里部分代码省略.........
示例15: translate
//-------------------------------------------------------------------------
void PUAffectorTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
{
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
// The name of the obj is the type of the affector
// Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for later
std::string type;
if(!obj->name.empty())
{
type = obj->name;
}
//// Get the factory
//ParticleAffectorFactory* particleAffectorFactory = ParticleSystemManager::getSingletonPtr()->getAffectorFactory(type);
//if (!particleAffectorFactory)
//{
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
// return;
//}
PUScriptTranslator *particleAffectorTranlator = PUAffectorManager::Instance()->getTranslator(type);
if (!particleAffectorTranlator) return;
//// Create the affector
//mAffector = ParticleSystemManager::getSingletonPtr()->createAffector(type);
//if (!mAffector)
//{
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
// return;
//}
_affector = PUAffectorManager::Instance()->createAffector(type);
if (!_affector) return;
_affector->setAffectorType(type);
if (parent && parent->context)
{
PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
system->addAffector(_affector);
}
// The first value is the (optional) name
std::string name;
if(!obj->values.empty())
{
getString(*obj->values.front(), &name);
_affector->setName(name);
}
// Set it in the context
obj->context = _affector;
// Run through properties
for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
{
if((*i)->type == ANT_PROPERTY)
{
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
if (prop->name == token[TOKEN_ENABLED])
{
// Property: enabled
if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL))
{
bool val;
if(getBoolean(*prop->values.front(), &val))
{
_affector->setEnabled(val);
}
}
}
else if (prop->name == token[TOKEN_POSITION])
{
// Property: position
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
{
Vec3 val;
if(getVector3(prop->values.begin(), prop->values.end(), &val))
{
//mAffector->position = val;
//mAffector->originalPosition = val;
_affector->setLocalPosition(val);
}
}
}
else if (prop->name == token[TOKEN_AFFECTOR_MASS])
{
if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_MASS], VAL_REAL))
{
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
_affector->setMass(val);
}
}
}
else if (prop->name == token[TOKEN_AFFECTOR_SPECIALISATION])
{
if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_SPECIALISATION], VAL_STRING))
{
std::string val;
if(getString(*prop->values.front(), &val))
//.........这里部分代码省略.........