Make able to emit from within portion of ellipsoid volume

This commit is contained in:
David Rowe 2015-09-17 23:49:57 -07:00
parent 9e2b5b75b6
commit 8634b59914
2 changed files with 22 additions and 2 deletions

View file

@ -30,7 +30,7 @@
ZERO_EMIT_ACCELERATON = { x: 0.0, y: 0.0, z: 0.0 },
PI = 3.141593,
DEG_TO_RAD = PI / 180.0,
NUM_PARTICLE_EXAMPLES = 17;
NUM_PARTICLE_EXAMPLES = 18;
function onClickDownOnEntity(entityID) {
if (entityID === box || entityID === sphere || entityID === particles) {
@ -171,6 +171,18 @@
});
break;
case 16:
print("Emit within quarter of sphere volume");
Entities.editEntity(particles, {
polarStart: 0.0,
polarFinish: PI / 2.0,
azimuthStart: 0,
azimuthFinish: PI / 2.0,
emitRadiusStart: 0.0,
alphaFinish: 1.0,
emitSpeed: 0.0
});
break;
case 17:
print("Stop emitting");
Entities.editEntity(particles, {
emitDimensions: pointDimensions,

View file

@ -693,6 +693,7 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
// Emit around point or from ellipsoid
// - Distribute directions evenly around point
// - Distribute points relatively evenly over ellipsoid surface
// - Distribute points relatively evenly within ellipsoid volume
float elevationMinZ = sin(PI_OVER_TWO - _polarFinish);
float elevationMaxZ = sin(PI_OVER_TWO - _polarStart);
@ -715,7 +716,14 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
} else {
// Ellipsoid
glm::vec3 radiuses = 0.5f * _emitDimensions;
float radiusScale = 1.0f;
if (_emitRadiusStart < 1.0f) {
float emitRadiusStart = glm::max(_emitRadiusStart, EPSILON); // Avoid math complications at center
float randRadius = emitRadiusStart + (1.0f - emitRadiusStart) * randFloat();
radiusScale = 1.0f - std::pow(1.0f - randRadius, 3);
}
glm::vec3 radiuses = radiusScale * 0.5f * _emitDimensions;
float x = radiuses.x * cos(elevation) * cos(azimuth);
float y = radiuses.y * cos(elevation) * sin(azimuth);
float z = radiuses.z * sin(elevation);