26 using std::make_unique;
28 using std::unique_ptr;
50 PointsParticleSystemInternal::PointsParticleSystemInternal(
const string&
id,
ParticleEmitter* emitter, int32_t maxPoints,
float pointSize,
bool autoEmit,
Texture* texture, int32_t textureHorizontalSprites, int32_t textureVerticalSprites,
float fps)
56 this->emitter = unique_ptr<ParticleEmitter>(
emitter);
72 this->texture =
texture !=
nullptr?
texture:TextureReader::read(
"resources/engine/textures",
"point.png");
119 float distanceFromCamera;
122 auto activeParticles = 0;
124 for (
auto i = 0; i <
particles.size(); i++) {
126 if (particle.active ==
false)
130 particle.lifeTimeCurrent += timeDelta;
132 if (particle.lifeTimeCurrent >= particle.lifeTimeMax) {
133 particle.active =
false;
137 particle.spriteIndex+= (
static_cast<float>(timeDelta) / 1000.0f) *
fps;
139 if (particle.mass > Math::EPSILON)
140 particle.velocity.sub(
Vector3(0.0f, 0.5f * Math::G *
static_cast<float>(timeDelta) / 1000.0f, 0.0f));
145 particle.position.add(velocityForTime.
set(particle.velocity).
scale(
static_cast<float>(timeDelta) / 1000.0f));
147 auto& color = particle.color;
148 const auto& colorAdd = particle.colorAdd;
149 color[0] += colorAdd[0] *
static_cast<float>(timeDelta);
150 color[1] += colorAdd[1] *
static_cast<float>(timeDelta);
151 color[2] += colorAdd[2] *
static_cast<float>(timeDelta);
152 color[3] += colorAdd[3] *
static_cast<float>(timeDelta);
156 point = localTransformMatrix.multiply(particle.position);
159 if (first ==
false) {
172 if (activeParticles == 0) {
196 auto particlesToSpawn = 0;
200 particlesToSpawn =
static_cast<int32_t
>(particlesToSpawnWithFraction);
207 particlesToSpawn =
emitter->getCount();
211 if (particlesToSpawn == 0)
return 0;
215 auto particlesSpawned = 0;
216 for (
auto i = 0; i <
particles.size(); i++) {
218 if (particle.active ==
true)
224 auto timeDeltaRnd =
static_cast<int64_t
>((Math::random() * timeDelta));
225 if (particle.mass > Math::EPSILON)
226 particle.velocity.sub(
Vector3(0.0f, 0.5f * Math::G *
static_cast<float>(timeDeltaRnd) / 1000.0f, 0.0f));
227 particle.position.add(velocityForTime.
set(particle.velocity).
scale(timeDeltaRnd / 1000.0f));
231 if (particlesSpawned == particlesToSpawn)
break;
234 return particlesSpawned;
Color 4 definition class.
void set(float r, float g, float b, float a)
Sets this color by its components.
int64_t getDeltaTime()
Gets the time passed between last and current frame.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
void extend(BoundingBox *boundingBox)
Extend bounding box with given bounding box.
void fromBoundingVolumeWithTransformMatrix(BoundingBox *original, const Matrix4x4 &transformMatrix)
Create bounding volume from given original(of same type) with applied transform matrix.
void update()
Updates this bounding box.
void updateParticles() override
Updates the particle entity.
Transform parentTransform
unique_ptr< ParticleEmitter > emitter
void initialize()
Initialize.
BoundingBox worldBoundingBox
int32_t textureHorizontalSprites
unique_ptr< TransparentRenderPointsPool > pointsRenderPool
void update() override
Update transform.
vector< Particle > particles
int32_t textureVerticalSprites
Matrix4x4 entityTransformMatrix
void setTransform(const Transform &transform) override
Set transform.
virtual ~PointsParticleSystemInternal()
Destructor.
float particlesToSpawnRemainder
void updateInternal()
Update bounding volume.
int emitParticles() override
Adds particles to this particle entity at given position.
Transparent render points pool.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Matrix4x4 & identity()
Creates identity matrix.
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
void getTranslation(Vector3 &translation) const
Get translation.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector3 & add(float scalar)
Adds a scalar.
Vector3 & sub(float scalar)
Subtracts a scalar.
Vector3 & scale(float scalar)
Scales by scalar.
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
virtual void releaseReference()
Releases a reference, thus decrementing the counter and delete it if reference counter is zero.
Particle emitter interface.
Particle system entity internal interface.