2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CC_PU_PARTICLE_3D_AFFECTOR_H__
|
|
|
|
#define __CC_PU_PARTICLE_3D_AFFECTOR_H__
|
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "math/CCMath.h"
|
|
|
|
#include "extensions/Particle3D/CCParticle3DAffector.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
struct PUParticle3D;
|
|
|
|
class PUParticleSystem3D;
|
|
|
|
|
2020-10-07 00:15:11 +08:00
|
|
|
class CC_EX_DLL PUAffector : public Particle3DAffector
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
friend class PUParticleSystem3D;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
|
|
|
The AffectSpecialisation enumeration is used to specialise the affector even more. This enumeration
|
|
|
|
isn't used by all affectors; in some cases it isn't even applicable.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
enum AffectSpecialisation
|
|
|
|
{
|
|
|
|
AFSP_DEFAULT,
|
|
|
|
AFSP_TTL_INCREASE,
|
|
|
|
AFSP_TTL_DECREASE
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void notifyStart();
|
|
|
|
virtual void notifyStop();
|
|
|
|
virtual void notifyPause();
|
|
|
|
virtual void notifyResume();
|
|
|
|
virtual void notifyRescaled(const Vec3& scale);
|
|
|
|
virtual void prepare();
|
|
|
|
virtual void unPrepare();
|
|
|
|
virtual void preUpdateAffector(float deltaTime);
|
|
|
|
virtual void updatePUAffector(PUParticle3D* particle, float delta);
|
|
|
|
virtual void postUpdateAffector(float deltaTime);
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void firstParticleUpdate(PUParticle3D* particle, float deltaTime);
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void initParticleForEmission(PUParticle3D* particle);
|
|
|
|
void process(PUParticle3D* particle, float delta, bool firstParticle);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void setLocalPosition(const Vec3& pos) { _position = pos; };
|
2019-11-23 20:27:39 +08:00
|
|
|
const Vec3 getLocalPosition() const { return _position; };
|
|
|
|
void setMass(float mass);
|
|
|
|
float getMass() const;
|
|
|
|
|
|
|
|
/** Calculate the derived position of the affector.
|
|
|
|
@remarks
|
|
|
|
Note, that in script, the position is set as localspace, while if the affector is
|
2021-12-25 10:04:45 +08:00
|
|
|
emitted, its position is automatically transformed. This function always returns
|
2019-11-23 20:27:39 +08:00
|
|
|
the derived position.
|
|
|
|
*/
|
|
|
|
const Vec3& getDerivedPosition();
|
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
const AffectSpecialisation& getAffectSpecialisation() const { return _affectSpecialisation; };
|
|
|
|
void setAffectSpecialisation(const AffectSpecialisation& affectSpecialisation)
|
|
|
|
{
|
|
|
|
_affectSpecialisation = affectSpecialisation;
|
|
|
|
};
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string_view getAffectorType() const { return _affectorType; };
|
|
|
|
void setAffectorType(std::string_view affectorType) { _affectorType = affectorType; };
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Add a ParticleEmitter name that excludes Particles emitted by this ParticleEmitter from being
|
|
|
|
affected.
|
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
void addEmitterToExclude(std::string_view emitterName);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Remove a ParticleEmitter name that excludes Particles emitted by this ParticleEmitter.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
void removeEmitterToExclude(std::string_view emitterName);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string_view getName() const { return _name; };
|
|
|
|
void setName(std::string_view name) { _name = name; };
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void copyAttributesTo(PUAffector* affector);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS : PUAffector();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUAffector();
|
|
|
|
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
float calculateAffectSpecialisationFactor(const PUParticle3D* particle);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Vec3 _position;
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Although the scale is on a Particle System level, the affector can also be scaled.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
Vec3 _affectorScale;
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Because the public attribute position is sometimes used for both localspace and worldspace
|
|
|
|
position, the mDerivedPosition attribute is introduced.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
Vec3 _derivedPosition;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** The mAffectSpecialisation is used to specialise the affector. This attribute is comparable with the
|
2019-11-23 20:27:39 +08:00
|
|
|
mAutoDirection of the ParticleEmitter, it is an optional attribute and used in some of the Particle
|
|
|
|
Affectors.
|
|
|
|
*/
|
|
|
|
AffectSpecialisation _affectSpecialisation;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// Type of the affector
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string _affectorType;
|
|
|
|
|
|
|
|
std::vector<std::string> _excludedEmitters;
|
|
|
|
|
|
|
|
// Name of the affector (optional)
|
|
|
|
std::string _name;
|
|
|
|
|
|
|
|
float _mass;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif
|