axmol/extensions/Particle3D/ParticleUniverse/ParticleAffectors/CCPUParticle3DAffector.cpp

232 lines
6.2 KiB
C++
Raw Normal View History

2015-02-11 18:14:22 +08:00
/****************************************************************************
2015-03-02 16:05:26 +08:00
Copyright (C) 2013 Henry van Merode. All rights reserved.
Copyright (c) 2015 Chukong Technologies Inc.
2015-02-11 18:14:22 +08:00
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2015-03-02 16:05:26 +08:00
#include "extensions/Particle3D/ParticleUniverse/ParticleAffectors/CCPUParticle3DAffector.h"
#include "extensions/Particle3D/ParticleUniverse/ParticleEmitters/CCPUParticle3DEmitter.h"
#include "extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3D.h"
2015-02-11 18:14:22 +08:00
NS_CC_BEGIN
PUParticle3DAffector::PUParticle3DAffector()
: _affectorScale(Vec3::ONE)
, _affectSpecialisation(AFSP_DEFAULT)
, _mass(1.0f)
{
}
PUParticle3DAffector::~PUParticle3DAffector()
{
_particleSystem = nullptr;
}
void PUParticle3DAffector::updatePUAffector(PUParticle3D* particle, float delta)
{
}
const Vec3& PUParticle3DAffector::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
2015-03-02 13:07:32 +08:00
_derivedPosition = _position;
2015-02-11 18:14:22 +08:00
return _derivedPosition;
2015-03-02 13:07:32 +08:00
2015-02-11 18:14:22 +08:00
//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;
}
float PUParticle3DAffector::calculateAffectSpecialisationFactor( const PUParticle3D* particle )
{
// Assume that particle->totalTimeToLive != 0, which is reasonable
switch (_affectSpecialisation)
{
case AFSP_DEFAULT:
return 1.0f;
break;
// This means that older particles will be affected MORE than just emitted particles
case AFSP_TTL_INCREASE:
{
if (particle)
{
return particle->timeFraction;
}
else
{
return 1.0f;
}
}
break;
// This means that older particles will be affected LESS than just emitted particles
case AFSP_TTL_DECREASE:
{
if (particle)
{
return 1.0f - particle->timeFraction;
}
else
{
return 1.0f;
}
}
break;
default:
return 1.0f;
break;
}
}
void PUParticle3DAffector::notifyStart()
{
}
void PUParticle3DAffector::notifyStop()
{
}
void PUParticle3DAffector::notifyPause()
{
}
void PUParticle3DAffector::notifyResume()
{
}
void PUParticle3DAffector::preUpdateAffector( float deltaTime )
{
}
void PUParticle3DAffector::postUpdateAffector( float deltaTime )
{
}
void PUParticle3DAffector::prepare()
{
}
void PUParticle3DAffector::unPrepare()
{
}
void PUParticle3DAffector::initParticleForEmission( PUParticle3D* particle )
{
}
void PUParticle3DAffector::notifyRescaled(const Vec3& scale)
{
_affectorScale = scale;
}
void PUParticle3DAffector::firstParticleUpdate( PUParticle3D *particle, float deltaTime )
{
}
void PUParticle3DAffector::setMass( float mass )
{
_mass = mass;
}
float PUParticle3DAffector::getMass() const
{
return _mass;
}
2015-03-02 13:07:32 +08:00
void PUParticle3DAffector::copyAttributesTo( PUParticle3DAffector* affector )
{
affector->setName(_name);
affector->_isEnabled = _isEnabled;
affector->_particleSystem = _particleSystem;
affector->_affectorScale = _affectorScale;
affector->_affectSpecialisation = _affectSpecialisation;
}
void PUParticle3DAffector::addEmitterToExclude( const std::string& emitterName )
{
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
if (iter == _excludedEmitters.end()){
_excludedEmitters.push_back(emitterName);
}
}
void PUParticle3DAffector::removeEmitterToExclude( const std::string& emitterName )
{
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
if (iter != _excludedEmitters.end()){
_excludedEmitters.erase(iter);
}
}
void PUParticle3DAffector::process( PUParticle3D* particle, float delta, bool firstParticle )
{
if (firstParticle){
firstParticleUpdate(particle, delta);
}
if (!_excludedEmitters.empty() && particle->parentEmitter){
// Return if the emitter which emits this particle is part of the vector
std::string emitterName = particle->parentEmitter->getName();
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
if (iter != _excludedEmitters.end())
{
return;
}
}
updatePUAffector(particle, delta);
}
2015-02-11 18:14:22 +08:00
NS_CC_END