summaryrefslogtreecommitdiff
path: root/scene/2d/cpu_particles_2d.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-07-07 11:04:46 +0200
committerGitHub <noreply@github.com>2019-07-07 11:04:46 +0200
commit1fa26b969c296ca62462debf01c22e2cc0aa059e (patch)
tree824b51ef58bee4b9f17f68d336e40f3e35a0d255 /scene/2d/cpu_particles_2d.cpp
parentbf0c54ecf235a071e937cb608393aa464df07cdd (diff)
parent5fc8691176f97e9fdeb609012b0061fbb4de8eb4 (diff)
Merge pull request #30357 from simonpuchert/spheres
Particles / CPUParticles: Return uniform density spheres.
Diffstat (limited to 'scene/2d/cpu_particles_2d.cpp')
-rw-r--r--scene/2d/cpu_particles_2d.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 2091085420..591933d972 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -661,8 +661,9 @@ void CPUParticles2D::_particles_process(float p_delta) {
//do none
} break;
case EMISSION_SHAPE_SPHERE: {
- Vector3 sphere_shape = Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0).normalized() * emission_sphere_radius;
- p.transform[2] = Vector2(sphere_shape.x, sphere_shape.y);
+ float s = Math::randf(), t = 2.0 * Math_PI * Math::randf();
+ float radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
+ p.transform[2] = Vector2(Math::cos(t), Math::sin(t)) * radius;
} break;
case EMISSION_SHAPE_RECTANGLE: {
p.transform[2] = Vector2(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_rect_extents;