Skip to content

Commit

Permalink
add 'min_angular_vel', 'max_angular_vel' properties
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Dec 23, 2024
1 parent 6ac088f commit 7f95306
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/graphics/render/Emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ void Emitter::update(
particle.angle =
random.randFloat() * preset.angleSpread * glm::pi<float>() * 2;
}
particle.angularVelocity =
(preset.minAngularVelocity +
random.randFloat() *
(preset.maxAngularVelocity - preset.minAngularVelocity)) *
((random.rand() % 2) * 2 - 1);

glm::vec3 spawnOffset = generate_coord(preset.spawnShape);
spawnOffset *= preset.spawnSpread;
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/render/Emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct Particle {
UVRegion region;
/// @brief Current rotation angle
float angle;
/// @brief Angular velocity
float angularVelocity;
};

class Texture;
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/render/ParticlesRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ static inline void update_particle(
const auto& preset = particle.emitter->preset;
auto& pos = particle.position;
auto& vel = particle.velocity;
auto& angle = particle.angle;

vel += delta * preset.acceleration;
if (preset.collision && chunks.isObstacleAt(pos + vel * delta)) {
vel *= 0.0f;
}
pos += vel * delta;
angle += particle.angularVelocity * delta;
particle.lifetime -= delta;
}

Expand Down
4 changes: 4 additions & 0 deletions src/presets/ParticlesPreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ dv::value ParticlesPreset::serialize() const {
root["size"] = dv::to_value(size);
root["size_spread"] = sizeSpread;
root["angle_spread"] = angleSpread;
root["min_angular_vel"] = minAngularVelocity;
root["max_angular_vel"] = maxAngularVelocity;
root["spawn_spread"] = dv::to_value(size);
root["spawn_shape"] = to_string(spawnShape);
root["random_sub_uv"] = randomSubUV;
Expand All @@ -60,6 +62,8 @@ void ParticlesPreset::deserialize(const dv::value& src) {
src.at("lifetime").get(lifetime);
src.at("lifetime_spread").get(lifetimeSpread);
src.at("angle_spread").get(angleSpread);
src.at("min_angular_vel").get(minAngularVelocity);
src.at("max_angular_vel").get(maxAngularVelocity);
src.at("random_sub_uv").get(randomSubUV);
if (src.has("velocity")) {
dv::get_vec(src["velocity"], velocity);
Expand Down
4 changes: 4 additions & 0 deletions src/presets/ParticlesPreset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct ParticlesPreset : public Serializable {
float sizeSpread = 0.2f;
/// @brief Random initial angle spread
float angleSpread = 0.0f;
/// @brief Minimum angular velocity
float minAngularVelocity = 0.0f;
/// @brief Maximum angular velocity
float maxAngularVelocity = 0.0f;
/// @brief Spawn spread shape
ParticleSpawnShape spawnShape = BALL;
/// @brief Spawn spread
Expand Down

0 comments on commit 7f95306

Please sign in to comment.