25 using std::make_unique;
29 using std::unique_ptr;
49 ObjectParticleSystemInternal::ObjectParticleSystemInternal(
const string&
id,
Model* model,
const Vector3& scale,
bool autoEmit,
bool contributesShadows,
bool receivesShadows, int32_t maxCount,
ParticleEmitter* emitter)
60 for (
auto i = 0; i <
objects.size(); i++) {
74 this->emitter = unique_ptr<ParticleEmitter>(
emitter);
93 for (
auto i = 0; i <
objects.size(); i++) {
101 for (
auto i = 0; i <
objects.size(); i++) {
129 auto particlesToSpawn = 0;
133 particlesToSpawn =
static_cast<int32_t
>(particlesToSpawnWithFraction);
140 particlesToSpawn =
emitter->getCount();
144 if (particlesToSpawn == 0)
return 0;
146 auto particlesSpawned = 0;
147 for (
auto i = 0; i <
particles.size(); i++) {
149 if (particle.active ==
true)
continue;
154 object->setTranslation(particle.position);
156 object->setEnabled(
true);
162 if (particlesSpawned == particlesToSpawn)
break;
165 return particlesSpawned;
180 for (
auto i = 0; i <
particles.size(); i++) {
182 if (particle.active ==
false)
187 particle.lifeTimeCurrent += timeDelta;
188 if (particle.lifeTimeCurrent >= particle.lifeTimeMax) {
189 particle.active =
false;
190 object->setEnabled(
false);
195 if (particle.mass > Math::EPSILON)
196 particle.velocity.sub(
Vector3(0.0f, 0.5f * Math::G *
static_cast<float>(timeDelta) / 1000.0f, 0.0f));
201 particle.position.add(velocityForTime.
set(particle.velocity).
scale(
static_cast<float>(timeDelta) / 1000.0f));
206 point = localTransformMatrix.multiply(particle.position);
211 object->setTranslation(point);
227 for (
auto i = 0; i <
objects.size(); i++) {
Color 4 definition class.
void set(float r, float g, float b, float a)
Sets this color by its components.
Object to be used with engine class.
int64_t getDeltaTime()
Gets the time passed between last and current frame.
Representation of a 3D model.
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.
Particle system which displays objects as particles.
void updateParticles() override
Updates the particle entity.
void setEngine(Engine *engine)
Transform parentTransform
unique_ptr< ParticleEmitter > emitter
vector< Object * > objects
BoundingBox worldBoundingBox
virtual ~ObjectParticleSystemInternal()
Destructor.
void update() override
Update transform.
vector< Particle > particles
const string & getId() override
Matrix4x4 inverseTransformMatrix
Matrix4x4 entityTransformMatrix
void setTransform(const Transform &transform) override
Set transform.
vector< Object * > enabledObjects
void setRenderer(Renderer *renderer)
float particlesToSpawnRemainder
void updateInternal()
Update internal.
int emitParticles() override
Adds particles to this particle entity at given position.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
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 & scale(float scalar)
Scales by scalar.
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Particle emitter interface.