47PointsParticleSystemInternal::PointsParticleSystemInternal(
const string&
id,
ParticleEmitter* emitter, int32_t maxPoints,
float pointSize,
bool autoEmit,
Texture* texture, int32_t textureHorizontalSprites, int32_t textureVerticalSprites,
float fps)
113 auto haveBoundingBox =
false;
115 float distanceFromCamera;
120 auto activeParticles = 0;
122 for (
auto i = 0; i <
particles.size(); i++) {
124 if (particle.active ==
false)
128 particle.lifeTimeCurrent += timeDelta;
130 if (particle.lifeTimeCurrent >= particle.lifeTimeMax) {
131 particle.active =
false;
135 particle.spriteIndex+= (
static_cast<float>(timeDelta) / 1000.0f) *
fps;
137 if (particle.mass > Math::EPSILON)
138 particle.velocity.sub(
Vector3(0.0f, 0.5f * Math::g *
static_cast<float>(timeDelta) / 1000.0f, 0.0f));
143 particle.position.add(velocityForTime.
set(particle.velocity).
scale(
static_cast<float>(timeDelta) / 1000.0f));
145 auto& color = particle.color.getArray();
146 auto& colorAdd = particle.colorAdd.getArray();
147 color[0] += colorAdd[0] *
static_cast<float>(timeDelta);
148 color[1] += colorAdd[1] *
static_cast<float>(timeDelta);
149 color[2] += colorAdd[2] *
static_cast<float>(timeDelta);
150 color[3] += colorAdd[3] *
static_cast<float>(timeDelta);
154 point = localTransformationsMatrix.multiply(particle.position);
158 if (haveBoundingBox ==
false) {
161 haveBoundingBox =
true;
163 if (pointXYZ[0] < bbMinXYZ[0]) bbMinXYZ[0] = pointXYZ[0];
164 if (pointXYZ[1] < bbMinXYZ[1]) bbMinXYZ[1] = pointXYZ[1];
165 if (pointXYZ[2] < bbMinXYZ[2]) bbMinXYZ[2] = pointXYZ[2];
166 if (pointXYZ[0] > bbMaxXYZ[0]) bbMaxXYZ[0] = pointXYZ[0];
167 if (pointXYZ[1] > bbMaxXYZ[1]) bbMaxXYZ[1] = pointXYZ[1];
168 if (pointXYZ[2] > bbMaxXYZ[2]) bbMaxXYZ[2] = pointXYZ[2];
176 if (activeParticles == 0) {
199 auto particlesToSpawn = 0;
203 particlesToSpawn =
static_cast< int32_t
>(particlesToSpawnWithFraction);
214 if (particlesToSpawn == 0)
return 0;
220 auto particlesSpawned = 0;
221 for (
auto i = 0; i <
particles.size(); i++) {
223 if (particle.active ==
true)
229 auto timeDeltaRnd =
static_cast< int64_t
>((Math::random() * timeDelta));
230 if (particle.mass > Math::EPSILON)
231 particle.velocity.sub(
Vector3(0.0f, 0.5f * Math::g *
static_cast<float>(timeDeltaRnd) / 1000.0f, 0.0f));
232 particle.position.add(velocityForTime.
set(particle.velocity).
scale(timeDeltaRnd / 1000.0f));
236 if (particlesSpawned == particlesToSpawn)
break;
239 return particlesSpawned;
static TextureManager * getTextureManager()
int64_t getDeltaTime()
Gets the time passed between last and current frame.
const string & getId() const
void set(const array< float, 4 > &color)
Set up color.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
void fromBoundingVolumeWithTransformations(BoundingBox *original, const Transformations &transformations)
Create bounding volume from given original(of same type) with applied transformations.
void update()
Updates this bounding box.
void removeTexture(const string &textureId)
Removes a texture from manager / open gl stack.
TextureManager_TextureManaged * addTexture(const string &id, bool &created)
Adds a texture to manager.
void updateParticles() override
Updates the particle entity.
BoundingBox boundingBoxTransformed
void initialize()
Initialize.
int32_t textureHorizontalSprites
void update() override
Update transformations.
vector< Particle > particles
ParticleEmitter * emitter
int32_t textureVerticalSprites
virtual ~PointsParticleSystemInternal()
Destructor.
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
TransparentRenderPointsPool * getRenderPointsPool()
TransparentRenderPointsPool * pointsRenderPool
Transformations localTransformations
float particlesToSpawnRemainder
void updateInternal()
Update bounding volume.
int32_t emitParticles() override
Adds particles to this particle entity at given position.
int32_t CONTEXTINDEX_DEFAULT
Transparent render points pool.
void addPoint(const Vector3 &point, uint16_t spriteIndex, const Color4 &color, int particleSystemType, void *particleSystem)
Creates an transparent render point entity in pool.
void getTranslation(Vector3 &translation) const
Get translation.
Vector3 multiply(const Vector3 &v) const
Multiplies a vector3 with this matrix into destination vector.
Vector3 & set(float x, float y, float z)
Set up vector.
Vector3 & sub(const Vector3 &v)
Subtracts a vector.
Vector3 & add(const Vector3 &v)
Adds a vector.
Vector3 & scale(float scale)
Scale this vector.
array< float, 3 > & getArray() const
void releaseReference()
releases a reference, thus decrementing the counter and delete it if reference counter is zero
void acquireReference()
acquires a reference, incrementing the counter
Particle emitter interface.
virtual int32_t getCount() const =0
virtual const Vector3 & getCenter() const =0
virtual void emit(Particle *particle)=0
Emits particles.
Particle system entity internal interface.