2015-03-02 13:07:32 +08:00
|
|
|
/****************************************************************************
|
2015-03-02 16:05:26 +08:00
|
|
|
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-02 13:07:32 +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
|
|
|
|
2015-03-02 13:07:32 +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
|
|
|
|
2015-03-02 13:07:32 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#ifndef __AX_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
|
|
|
|
#define __AX_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "math/CCMath.h"
|
2015-03-05 13:24:06 +08:00
|
|
|
#include "extensions/Particle3D/PU/CCPUListener.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
2015-03-02 13:07:32 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
struct PUParticle3D;
|
2015-03-05 13:24:06 +08:00
|
|
|
class PUObserver;
|
|
|
|
class PUEmitter;
|
2015-03-02 13:07:32 +08:00
|
|
|
class PUParticleSystem3D;
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_EX_DLL PUDoPlacementParticleEventHandler : public PUEventHandler, public PUListener
|
2015-03-02 13:07:32 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constants
|
|
|
|
static const unsigned int DEFAULT_NUMBER_OF_PARTICLES;
|
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
static PUDoPlacementParticleEventHandler* create();
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Getters/Setters
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
bool isInheritPosition() const { return _inheritPosition; };
|
|
|
|
bool isInheritDirection() const { return _inheritDirection; };
|
|
|
|
bool isInheritOrientation() const { return _inheritOrientation; };
|
|
|
|
bool isInheritTimeToLive() const { return _inheritTimeToLive; };
|
|
|
|
bool isInheritMass() const { return _inheritMass; };
|
|
|
|
bool isInheritTextureCoordinate() const { return _inheritTextureCoordinate; };
|
|
|
|
bool isInheritColour() const { return _inheritColour; };
|
|
|
|
bool isInheritParticleWidth() const { return _inheritParticleWidth; };
|
|
|
|
bool isInheritParticleHeight() const { return _inheritParticleHeight; };
|
|
|
|
bool isInheritParticleDepth() const { return _inheritParticleDepth; };
|
|
|
|
|
|
|
|
void setInheritPosition(bool inheritPosition) { _inheritPosition = inheritPosition; };
|
|
|
|
void setInheritDirection(bool inheritDirection) { _inheritDirection = inheritDirection; };
|
|
|
|
void setInheritOrientation(bool inheritOrientation) { _inheritOrientation = inheritOrientation; };
|
|
|
|
void setInheritTimeToLive(bool inheritTimeToLive) { _inheritTimeToLive = inheritTimeToLive; };
|
|
|
|
void setInheritMass(bool inheritMass) { _inheritMass = inheritMass; };
|
|
|
|
void setInheritTextureCoordinate(bool inheritTextureCoordinate)
|
|
|
|
{
|
|
|
|
_inheritTextureCoordinate = inheritTextureCoordinate;
|
|
|
|
};
|
|
|
|
void setInheritColour(bool inheritColour) { _inheritColour = inheritColour; };
|
|
|
|
void setInheritParticleWidth(bool inheritParticleWidth) { _inheritParticleWidth = inheritParticleWidth; };
|
|
|
|
void setInheritParticleHeight(bool inheritParticleHeight) { _inheritParticleHeight = inheritParticleHeight; };
|
|
|
|
void setInheritParticleDepth(bool inheritParticleDepth) { _inheritParticleDepth = inheritParticleDepth; };
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Get the name of the emitter that is used to emit its particles.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view getForceEmitterName() const { return _forceEmitterName; };
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Set the name of the emitter that is used to emit its particles.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void setForceEmitterName(std::string_view forceEmitterName);
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Returns a pointer to the emitter that is used as a force emitter.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
PUEmitter* getForceEmitter() const;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Remove this as a listener from the technique.
|
|
|
|
@remarks
|
2021-12-25 10:04:45 +08:00
|
|
|
If a new force-emitter name has been set, the removeAsListener must be called, to remove the
|
|
|
|
DoPlacementParticleEventHandler from the old technique (to which the force-emitter belongs. Only then the new
|
|
|
|
force-emitter is used. The reason why it is not called automatically in the setForceEmitterName() function is to
|
|
|
|
offer some flexibility on the moment the removeAsListener() is called.
|
2015-03-02 13:07:32 +08:00
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
void removeAsListener();
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Get the number of particles to emit.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
unsigned int getNumberOfParticles() const { return _numberOfParticles; };
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Set the number of particles to emit.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
void setNumberOfParticles(unsigned int numberOfParticles) { _numberOfParticles = numberOfParticles; };
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Boolean that determines whether always the position of the particle that is handled must be used for emission of
|
2015-03-02 13:07:32 +08:00
|
|
|
the new particle.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool alwaysUsePosition() const { return _alwaysUsePosition; };
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Set the boolean to indicate whether the position of the particle that is handled must be used for emission of
|
|
|
|
the new particle or whether the contact point of the physics actor must be used. This only applies if a physics
|
|
|
|
engine is used, otherwise the default is used.
|
2015-03-02 13:07:32 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setAlwaysUsePosition(bool alwaysUsePosition) { _alwaysUsePosition = alwaysUsePosition; };
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** If the _handle() function of this class is invoked (by an Observer), it searches the
|
|
|
|
ParticleEmitter defined by the mForceEmitterName. This ParticleEmitter is either part of
|
2015-03-02 13:07:32 +08:00
|
|
|
the ParticleTechnique in which the DoPlacementParticleEventHandler is defined, and if the ParticleEmitter
|
|
|
|
is not found, other ParticleTechniques are searched. The ParticleEmitter is 'forced' to emit the
|
|
|
|
requested number of particles.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void handle(PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Initialise the emitted particle. This means that its position is set.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2015-03-02 13:07:32 +08:00
|
|
|
virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
|
|
|
|
|
|
|
|
/** No implementation.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2016-11-16 09:48:37 +08:00
|
|
|
virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void copyAttributesTo(PUEventHandler* eventHandler) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
PUDoPlacementParticleEventHandler();
|
2019-07-22 09:38:46 +08:00
|
|
|
virtual ~PUDoPlacementParticleEventHandler();
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Identifies the name of emitter
|
|
|
|
std::string _forceEmitterName;
|
|
|
|
|
|
|
|
// The number of particles to emit
|
|
|
|
unsigned int _numberOfParticles;
|
|
|
|
|
|
|
|
/** Store the technique value to keep up to speed.
|
|
|
|
@remarks
|
2015-12-11 23:43:19 +08:00
|
|
|
If the ParticleTechnique has been destroyed, the DoPlacementParticleEventHandler isn't automatically
|
2015-03-02 13:07:32 +08:00
|
|
|
notified. Using the pointer causes an exception.
|
|
|
|
*/
|
|
|
|
PUParticleSystem3D* _system;
|
|
|
|
|
|
|
|
/** Store the emitter value to keep up to speed.
|
|
|
|
@remarks
|
2015-12-11 23:43:19 +08:00
|
|
|
If the ParticleEmitter has been destroyed, the DoPlacementParticleEventHandler isn't automatically
|
2015-03-02 13:07:32 +08:00
|
|
|
notified. Using the pointer causes an exception.
|
|
|
|
*/
|
2015-03-05 13:24:06 +08:00
|
|
|
PUEmitter* _emitter;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
/** Used to determine whether the emitter used by the DoPlacementParticleEventHandler, is already found.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2015-03-02 13:07:32 +08:00
|
|
|
bool _found;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** By default the place where to put a new particle is on the position of the particle in the _handle function. If
|
|
|
|
mAlwaysUsePosition is set to false, it tries the contact point of the physics actor that is associated with the
|
2015-03-02 13:07:32 +08:00
|
|
|
particle.
|
|
|
|
*/
|
|
|
|
bool _alwaysUsePosition;
|
|
|
|
|
|
|
|
/** The base particle from which the attributes are inherited
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2015-03-02 13:07:32 +08:00
|
|
|
PUParticle3D* _baseParticle;
|
|
|
|
|
|
|
|
/** These flags are used to determine which attributes must be inherited from the base particle.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2015-03-02 13:07:32 +08:00
|
|
|
bool _inheritPosition;
|
|
|
|
bool _inheritDirection;
|
|
|
|
bool _inheritOrientation;
|
|
|
|
bool _inheritTimeToLive;
|
|
|
|
bool _inheritMass;
|
|
|
|
bool _inheritTextureCoordinate;
|
|
|
|
bool _inheritColour;
|
|
|
|
bool _inheritParticleWidth;
|
|
|
|
bool _inheritParticleHeight;
|
|
|
|
bool _inheritParticleDepth;
|
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
#endif
|