add 'angle_spread' property

This commit is contained in:
MihailRis
2024-12-23 16:04:48 +03:00
parent 90b1f63406
commit c6de7f62fe
5 changed files with 28 additions and 4 deletions
+6 -1
View File
@@ -23,8 +23,9 @@ Emitter::Emitter(
texture(texture),
count(count),
preset(std::move(preset)) {
random.setSeed(rand());
this->prototype.emitter = this;
timer = preset.spawnInterval;
timer = preset.spawnInterval * random.randFloat();
}
const Texture* Emitter::getTexture() const {
@@ -83,6 +84,10 @@ void Emitter::update(
Particle particle = prototype;
particle.emitter = this;
particle.random = random.rand32();
if (glm::abs(preset.angleSpread) >= 0.005f) {
particle.angle =
random.randFloat() * preset.angleSpread * glm::pi<float>() * 2;
}
glm::vec3 spawnOffset = generate_coord(preset.spawnShape);
spawnOffset *= preset.spawnSpread;
+3 -1
View File
@@ -27,6 +27,8 @@ struct Particle {
float lifetime;
/// @brief UV region
UVRegion region;
/// @brief Current rotation angle
float angle;
};
class Texture;
@@ -39,7 +41,7 @@ class Emitter {
EmitterOrigin origin;
/// @brief Particle prototype
Particle prototype;
/// @brief Particle
/// @brief Particle texture
const Texture* texture;
/// @brief Number of particles should be spawned before emitter deactivation.
/// -1 is infinite.
+15 -2
View File
@@ -91,10 +91,23 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) {
}
float scale = 1.0f + ((particle.random ^ 2628172) % 1000) *
0.001f * preset.sizeSpread;
glm::vec3 localRight = right;
glm::vec3 localUp = preset.globalUpVector ? glm::vec3(0, 1, 0) : up;
float angle = particle.angle;
if (glm::abs(angle) >= 0.005f) {
glm::vec3 rotatedRight(glm::cos(angle), -glm::sin(angle), 0.0f);
glm::vec3 rotatedUp(glm::sin(angle), glm::cos(angle), 0.0f);
localRight = right * rotatedRight.x + localUp * rotatedRight.y +
camera.front * rotatedRight.z;
localUp = right * rotatedUp.x + localUp * rotatedUp.y +
camera.front * rotatedUp.z;
}
batch->quad(
particle.position,
right,
preset.globalUpVector ? glm::vec3(0, 1, 0) : up,
localRight,
localUp,
preset.size * scale,
light,
glm::vec3(1.0f),