Improved random direction for fireworks particles
@@ -47,14 +47,11 @@ fn main() {
if time > explosion_time {
time = 0.0;
let start_position = vec3(20.0 * rng.gen::<f32>() - 10.0, 40.0 + 20.0 * rng.gen::<f32>(), 20.0 * rng.gen::<f32>() - 10.0);
- let start_direction = vec3(rng.gen::<f32>() - 0.5, 0.5 + 0.5 * rng.gen::<f32>(), rng.gen::<f32>() - 0.5).normalize();
- let tangent = start_direction.cross(vec3(1.0, 0.0, 0.0));
- let cotangent = start_direction.cross(tangent);
let mut data = Vec::new();
for _ in 0..300 {
- let explosion_direction = ((rng.gen::<f32>() - 0.5) * start_direction
- + (rng.gen::<f32>() - 0.5) * tangent
- + (rng.gen::<f32>() - 0.5) * cotangent).normalize();
+ let theta = rng.gen::<f32>() * std::f32::consts::PI;
+ let phi = rng.gen::<f32>() * 2.0 * std::f32::consts::PI;
+ let explosion_direction = vec3(theta.sin() * phi.cos(), theta.sin() * phi.sin(), theta.cos());
data.push(ParticleData {
start_position,
start_velocity: (rng.gen::<f32>()*0.2 + 0.9) * explosion_speed * explosion_direction
