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
|
|
|
|
2022-07-10 09:47:27 +08:00
|
|
|
https://adxeproject.github.io/
|
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_FORCE_FIELD_AFFECTOR_H__
|
|
|
|
#define __CC_PU_PARTICLE_3D_FORCE_FIELD_AFFECTOR_H__
|
|
|
|
|
|
|
|
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUForceField.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
class CC_EX_DLL PUForceFieldAffector : public PUAffector
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constants
|
|
|
|
static const PUForceField::ForceFieldType DEFAULT_FORCEFIELD_TYPE;
|
|
|
|
static const float DEFAULT_DELTA;
|
|
|
|
static const float DEFAULT_FORCE;
|
|
|
|
static const unsigned short DEFAULT_OCTAVES;
|
|
|
|
static const double DEFAULT_FREQUENCY;
|
|
|
|
static const double DEFAULT_AMPLITUDE;
|
|
|
|
static const double DEFAULT_PERSISTENCE;
|
|
|
|
static const unsigned int DEFAULT_FORCEFIELDSIZE;
|
|
|
|
static const Vec3 DEFAULT_WORLDSIZE;
|
|
|
|
static const Vec3 DEFAULT_MOVEMENT;
|
|
|
|
static const float DEFAULT_MOVEMENT_FREQUENCY;
|
|
|
|
|
|
|
|
static PUForceFieldAffector* create();
|
|
|
|
|
|
|
|
virtual void notifyStart() override;
|
|
|
|
virtual void preUpdateAffector(float deltaTime) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void updatePUAffector(PUParticle3D* particle, float deltaTime) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void prepare() override;
|
|
|
|
|
|
|
|
/** Get/Set Forcefield type
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
PUForceField::ForceFieldType getForceFieldType() const;
|
|
|
|
void setForceFieldType(const PUForceField::ForceFieldType forceFieldType);
|
|
|
|
|
|
|
|
/** Get/Set Delta
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getDelta() const;
|
|
|
|
void setDelta(float delta);
|
|
|
|
|
|
|
|
/** Get/Set scale Force
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getScaleForce() const;
|
|
|
|
void setScaleForce(float scaleForce);
|
|
|
|
|
|
|
|
/** Get/Set scale Octaves
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
unsigned short getOctaves() const;
|
|
|
|
void setOctaves(unsigned short octaves);
|
|
|
|
|
|
|
|
/** Get/Set scale Frequency
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
double getFrequency() const;
|
|
|
|
void setFrequency(double frequency);
|
|
|
|
|
|
|
|
/** Get/Set scale Amplitude
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
double getAmplitude() const;
|
|
|
|
void setAmplitude(double amplitude);
|
|
|
|
|
|
|
|
/** Get/Set scale Persistence
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
double getPersistence() const;
|
|
|
|
void setPersistence(double persistence);
|
|
|
|
|
|
|
|
/** Get/Set scale ForceFieldSize
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
unsigned int getForceFieldSize() const;
|
|
|
|
void setForceFieldSize(unsigned int forceFieldSize);
|
|
|
|
|
|
|
|
/** Get/Set scale worldSize
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
Vec3 getWorldSize() const;
|
|
|
|
void setWorldSize(const Vec3& worldSize);
|
|
|
|
|
|
|
|
/** Get/Set scale flip attributes
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool getIgnoreNegativeX() const;
|
|
|
|
void setIgnoreNegativeX(bool ignoreNegativeX);
|
|
|
|
bool getIgnoreNegativeY() const;
|
|
|
|
void setIgnoreNegativeY(bool ignoreNegativeY);
|
|
|
|
bool getIgnoreNegativeZ() const;
|
|
|
|
void setIgnoreNegativeZ(bool ignoreNegativeZ);
|
|
|
|
|
|
|
|
/** Get/Set Movement
|
|
|
|
@remarks
|
2021-12-25 10:04:45 +08:00
|
|
|
The movement vector determines the position of the movement. This movement is a displacement of the particle
|
|
|
|
position mapped to the forcefield.
|
2019-11-23 20:27:39 +08:00
|
|
|
*/
|
|
|
|
const Vec3& getMovement() const;
|
|
|
|
void setMovement(const Vec3& movement);
|
|
|
|
|
|
|
|
/** Get/Set Movement frequency
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getMovementFrequency() const;
|
|
|
|
void setMovementFrequency(float movementFrequency);
|
|
|
|
|
|
|
|
/** Suppress (re)generation of the forcefield everytime an attribute is changed.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void suppressGeneration(bool suppress);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void copyAttributesTo(PUAffector* affector) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
PUForceFieldAffector();
|
2019-11-23 20:27:39 +08:00
|
|
|
~PUForceFieldAffector();
|
|
|
|
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
PUForceField _forceField; // Local force field
|
|
|
|
PUForceField::ForceFieldType _forceFieldType; // Type of force field
|
|
|
|
float _delta; // Radius of particle position
|
|
|
|
Vec3 _force; // Force value that is used to calculate the force and reused for all particles
|
|
|
|
float _scaleForce; // Scaling factor used in calculation of the direction vector of the particle
|
|
|
|
unsigned short _octaves; // Used in noise generation
|
|
|
|
double _frequency; // Used in noise generation
|
|
|
|
double _amplitude; // Used in noise generation
|
|
|
|
double _persistence; // Used in noise generation
|
|
|
|
unsigned int
|
|
|
|
_forceFieldSize; // The real size of the force field (is a unit cube in case of a 'realtime' force field type
|
|
|
|
Vec3 _worldSize; // Size of the force field in world coordinates (can be non-cubic)
|
|
|
|
bool _prepared; // Determines whether the force field is generated
|
|
|
|
bool _ignoreNegativeX; // X-force is never negative
|
|
|
|
bool _ignoreNegativeY; // Y-force is never negative
|
|
|
|
bool _ignoreNegativeZ; // Z-force is never negative
|
|
|
|
Vec3 _movement; // The direction to which the forcefield moves
|
|
|
|
bool _movementSet; // Is true if the movement is set
|
|
|
|
float _movementFrequency; // Speed of movement
|
2019-11-23 20:27:39 +08:00
|
|
|
float _movementFrequencyCount;
|
|
|
|
Vec3 _displacement;
|
|
|
|
Vec3 _basePosition;
|
2021-12-25 10:04:45 +08:00
|
|
|
bool _suppressGeneration; // Prevents re-generation of the complete forcefield after a change.
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif
|