mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Implement particle bounds with Extents
This commit is contained in:
parent
9320623ff5
commit
a71ed7b166
3 changed files with 15 additions and 50 deletions
|
@ -272,37 +272,17 @@ void RenderableParticleEffectEntityItem::updateRenderItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update transform
|
// update transform
|
||||||
glm::quat rot = getRotation();
|
glm::vec3 position = getPosition();
|
||||||
glm::vec3 pos = getPosition();
|
glm::quat rotation = getRotation();
|
||||||
Transform t;
|
Transform transform;
|
||||||
t.setRotation(rot);
|
transform.setTranslation(position);
|
||||||
payload.setModelTransform(t);
|
transform.setRotation(rotation);
|
||||||
|
payload.setModelTransform(transform);
|
||||||
|
|
||||||
// transform _particleMinBound and _particleMaxBound corners into world coords
|
AABox bounds(_particlesBounds);
|
||||||
glm::vec3 d = _particleMaxBound - _particleMinBound;
|
bounds.rotate(rotation);
|
||||||
const size_t NUM_BOX_CORNERS = 8;
|
bounds.shiftBy(position);
|
||||||
glm::vec3 corners[NUM_BOX_CORNERS] = {
|
payload.setBound(bounds);
|
||||||
pos + rot * (_particleMinBound + glm::vec3(0.0f, 0.0f, 0.0f)),
|
|
||||||
pos + rot * (_particleMinBound + glm::vec3(d.x, 0.0f, 0.0f)),
|
|
||||||
pos + rot * (_particleMinBound + glm::vec3(0.0f, d.y, 0.0f)),
|
|
||||||
pos + rot * (_particleMinBound + glm::vec3(d.x, d.y, 0.0f)),
|
|
||||||
pos + rot * (_particleMinBound + glm::vec3(0.0f, 0.0f, d.z)),
|
|
||||||
pos + rot * (_particleMinBound + glm::vec3(d.x, 0.0f, d.z)),
|
|
||||||
pos + rot * (_particleMinBound + glm::vec3(0.0f, d.y, d.z)),
|
|
||||||
pos + rot * (_particleMinBound + glm::vec3(d.x, d.y, d.z))
|
|
||||||
};
|
|
||||||
glm::vec3 min(FLT_MAX, FLT_MAX, FLT_MAX);
|
|
||||||
glm::vec3 max = -min;
|
|
||||||
for (size_t i = 0; i < NUM_BOX_CORNERS; i++) {
|
|
||||||
min.x = std::min(min.x, corners[i].x);
|
|
||||||
min.y = std::min(min.y, corners[i].y);
|
|
||||||
min.z = std::min(min.z, corners[i].z);
|
|
||||||
max.x = std::max(max.x, corners[i].x);
|
|
||||||
max.y = std::max(max.y, corners[i].y);
|
|
||||||
max.z = std::max(max.z, corners[i].z);
|
|
||||||
}
|
|
||||||
AABox bound(min, max - min);
|
|
||||||
payload.setBound(bound);
|
|
||||||
|
|
||||||
bool textured = _texture && _texture->isLoaded();
|
bool textured = _texture && _texture->isLoaded();
|
||||||
if (textured) {
|
if (textured) {
|
||||||
|
|
|
@ -121,8 +121,6 @@ ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityIte
|
||||||
_alphaStarts(DEFAULT_MAX_PARTICLES, DEFAULT_ALPHA),
|
_alphaStarts(DEFAULT_MAX_PARTICLES, DEFAULT_ALPHA),
|
||||||
_alphaMiddles(DEFAULT_MAX_PARTICLES, DEFAULT_ALPHA),
|
_alphaMiddles(DEFAULT_MAX_PARTICLES, DEFAULT_ALPHA),
|
||||||
_alphaFinishes(DEFAULT_MAX_PARTICLES, DEFAULT_ALPHA),
|
_alphaFinishes(DEFAULT_MAX_PARTICLES, DEFAULT_ALPHA),
|
||||||
_particleMaxBound(glm::vec3(1.0f, 1.0f, 1.0f)),
|
|
||||||
_particleMinBound(glm::vec3(-1.0f, -1.0f, -1.0f)) ,
|
|
||||||
_additiveBlending(DEFAULT_ADDITIVE_BLENDING)
|
_additiveBlending(DEFAULT_ADDITIVE_BLENDING)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -631,15 +629,6 @@ void ParticleEffectEntityItem::updateAlpha(quint32 index, float age) {
|
||||||
_alphaFinishes[index], age);
|
_alphaFinishes[index], age);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEffectEntityItem::extendBounds(const glm::vec3& point) {
|
|
||||||
_particleMinBound.x = glm::min(_particleMinBound.x, point.x);
|
|
||||||
_particleMinBound.y = glm::min(_particleMinBound.y, point.y);
|
|
||||||
_particleMinBound.z = glm::min(_particleMinBound.z, point.z);
|
|
||||||
_particleMaxBound.x = glm::max(_particleMaxBound.x, point.x);
|
|
||||||
_particleMaxBound.y = glm::max(_particleMaxBound.y, point.y);
|
|
||||||
_particleMaxBound.z = glm::max(_particleMaxBound.z, point.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ParticleEffectEntityItem::integrateParticle(quint32 index, float deltaTime) {
|
void ParticleEffectEntityItem::integrateParticle(quint32 index, float deltaTime) {
|
||||||
glm::vec3 accel = _particleAccelerations[index];
|
glm::vec3 accel = _particleAccelerations[index];
|
||||||
glm::vec3 atSquared = (0.5f * deltaTime * deltaTime) * accel;
|
glm::vec3 atSquared = (0.5f * deltaTime * deltaTime) * accel;
|
||||||
|
@ -649,9 +638,7 @@ void ParticleEffectEntityItem::integrateParticle(quint32 index, float deltaTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
|
void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
|
||||||
|
_particlesBounds.reset();
|
||||||
_particleMinBound = glm::vec3(-1.0f, -1.0f, -1.0f);
|
|
||||||
_particleMaxBound = glm::vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
|
|
||||||
// update particles between head and tail
|
// update particles between head and tail
|
||||||
for (quint32 i = _particleHeadIndex; i != _particleTailIndex; i = (i + 1) % _maxParticles) {
|
for (quint32 i = _particleHeadIndex; i != _particleTailIndex; i = (i + 1) % _maxParticles) {
|
||||||
|
@ -667,7 +654,7 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
|
||||||
updateColor(i, age);
|
updateColor(i, age);
|
||||||
updateAlpha(i, age);
|
updateAlpha(i, age);
|
||||||
integrateParticle(i, deltaTime);
|
integrateParticle(i, deltaTime);
|
||||||
extendBounds(_particlePositions[i]);
|
_particlesBounds.addPoint(_particlePositions[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,7 +753,7 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
|
||||||
_particleAccelerations[i] = _emitAcceleration + randFloatInRange(-1.0f, 1.0f) * _accelerationSpread;
|
_particleAccelerations[i] = _emitAcceleration + randFloatInRange(-1.0f, 1.0f) * _accelerationSpread;
|
||||||
}
|
}
|
||||||
integrateParticle(i, timeLeftInFrame);
|
integrateParticle(i, timeLeftInFrame);
|
||||||
extendBounds(_particlePositions[i]);
|
_particlesBounds.addPoint(_particlePositions[i]);
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
if (_colorSpread == xColor{ 0, 0, 0 }) {
|
if (_colorSpread == xColor{ 0, 0, 0 }) {
|
||||||
|
|
|
@ -224,7 +224,6 @@ protected:
|
||||||
void updateRadius(quint32 index, float age);
|
void updateRadius(quint32 index, float age);
|
||||||
void updateColor(quint32 index, float age);
|
void updateColor(quint32 index, float age);
|
||||||
void updateAlpha(quint32 index, float age);
|
void updateAlpha(quint32 index, float age);
|
||||||
void extendBounds(const glm::vec3& point);
|
|
||||||
void integrateParticle(quint32 index, float deltaTime);
|
void integrateParticle(quint32 index, float deltaTime);
|
||||||
quint32 getLivingParticleCount() const;
|
quint32 getLivingParticleCount() const;
|
||||||
// the properties of this entity
|
// the properties of this entity
|
||||||
|
@ -289,9 +288,8 @@ protected:
|
||||||
quint32 _particleTailIndex = 0;
|
quint32 _particleTailIndex = 0;
|
||||||
|
|
||||||
// bounding volume
|
// bounding volume
|
||||||
glm::vec3 _particleMaxBound;
|
Extents _particlesBounds;
|
||||||
glm::vec3 _particleMinBound;
|
|
||||||
|
|
||||||
bool _additiveBlending;
|
bool _additiveBlending;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue