summaryrefslogtreecommitdiff
path: root/scene/3d/cpu_particles.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/3d/cpu_particles.cpp
parentbf0c54ecf235a071e937cb608393aa464df07cdd (diff)
parent5fc8691176f97e9fdeb609012b0061fbb4de8eb4 (diff)
Merge pull request #30357 from simonpuchert/spheres
Particles / CPUParticles: Return uniform density spheres.
Diffstat (limited to 'scene/3d/cpu_particles.cpp')
-rw-r--r--scene/3d/cpu_particles.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp
index 358c4bdb44..86b407b9e6 100644
--- a/scene/3d/cpu_particles.cpp
+++ b/scene/3d/cpu_particles.cpp
@@ -643,7 +643,9 @@ void CPUParticles::_particles_process(float p_delta) {
//do none
} break;
case EMISSION_SHAPE_SPHERE: {
- p.transform.origin = Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0).normalized() * emission_sphere_radius;
+ float s = 2.0 * Math::randf() - 1.0, t = 2.0 * Math_PI * Math::randf();
+ float radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
+ p.transform.origin = Vector3(radius * Math::cos(t), radius * Math::sin(t), emission_sphere_radius * s);
} break;
case EMISSION_SHAPE_BOX: {
p.transform.origin = Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_box_extents;