mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:17:02 +02:00
Make able to emit in specified range of directions
Controlled by polar and azimuth start and finish angles, around point or from specified part of spheroid surface.
This commit is contained in:
parent
f647dcf147
commit
9e2b5b75b6
2 changed files with 77 additions and 38 deletions
|
@ -22,13 +22,15 @@
|
||||||
particleExample = -1,
|
particleExample = -1,
|
||||||
PARTICLE_RADIUS = 0.04,
|
PARTICLE_RADIUS = 0.04,
|
||||||
SLOW_EMIT_RATE = 2.0,
|
SLOW_EMIT_RATE = 2.0,
|
||||||
|
HALF_EMIT_RATE = 50.0,
|
||||||
FAST_EMIT_RATE = 100.0,
|
FAST_EMIT_RATE = 100.0,
|
||||||
SLOW_EMIT_SPEED = 0.05,
|
SLOW_EMIT_SPEED = 0.025,
|
||||||
FAST_EMIT_SPEED = 1.0,
|
FAST_EMIT_SPEED = 1.0,
|
||||||
GRAVITY_EMIT_ACCELERATON = { x: 0.0, y: -0.3, z: 0.0 },
|
GRAVITY_EMIT_ACCELERATON = { x: 0.0, y: -0.3, z: 0.0 },
|
||||||
ZERO_EMIT_ACCELERATON = { x: 0.0, y: 0.0, z: 0.0 },
|
ZERO_EMIT_ACCELERATON = { x: 0.0, y: 0.0, z: 0.0 },
|
||||||
PI = 3.141593,
|
PI = 3.141593,
|
||||||
NUM_PARTICLE_EXAMPLES = 13;
|
DEG_TO_RAD = PI / 180.0,
|
||||||
|
NUM_PARTICLE_EXAMPLES = 17;
|
||||||
|
|
||||||
function onClickDownOnEntity(entityID) {
|
function onClickDownOnEntity(entityID) {
|
||||||
if (entityID === box || entityID === sphere || entityID === particles) {
|
if (entityID === box || entityID === sphere || entityID === particles) {
|
||||||
|
@ -116,23 +118,24 @@
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
print("Emit in all directions from point");
|
print("Emit in a spread beam");
|
||||||
Entities.editEntity(particles, {
|
Entities.editEntity(particles, {
|
||||||
colorStart: { red: 255, green: 255, blue: 255 },
|
colorStart: { red: 255, green: 255, blue: 255 },
|
||||||
colorFinish: { red: 255, green: 255, blue: 255 },
|
colorFinish: { red: 255, green: 255, blue: 255 },
|
||||||
|
alphaFinish: 0.0,
|
||||||
emitRate: FAST_EMIT_RATE,
|
emitRate: FAST_EMIT_RATE,
|
||||||
|
polarFinish: 2.0 * DEG_TO_RAD
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
print("Emit in all directions from point");
|
||||||
|
Entities.editEntity(particles, {
|
||||||
emitSpeed: SLOW_EMIT_SPEED,
|
emitSpeed: SLOW_EMIT_SPEED,
|
||||||
emitAcceleration: ZERO_EMIT_ACCELERATON,
|
emitAcceleration: ZERO_EMIT_ACCELERATON,
|
||||||
polarFinish: PI
|
polarFinish: PI
|
||||||
});
|
});
|
||||||
Entities.editEntity(box, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
Entities.editEntity(sphere, {
|
|
||||||
visible: true
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 12:
|
||||||
print("Emit from sphere surface");
|
print("Emit from sphere surface");
|
||||||
Entities.editEntity(particles, {
|
Entities.editEntity(particles, {
|
||||||
colorStart: { red: 255, green: 255, blue: 255 },
|
colorStart: { red: 255, green: 255, blue: 255 },
|
||||||
|
@ -147,15 +150,39 @@
|
||||||
visible: true
|
visible: true
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 13:
|
||||||
|
print("Emit from hemisphere of sphere surface");
|
||||||
|
Entities.editEntity(particles, {
|
||||||
|
polarFinish: PI / 2.0
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
print("Emit from equator of sphere surface");
|
||||||
|
Entities.editEntity(particles, {
|
||||||
|
polarStart: PI / 2.0,
|
||||||
|
emitRate: HALF_EMIT_RATE
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
print("Emit from half equator of sphere surface");
|
||||||
|
Entities.editEntity(particles, {
|
||||||
|
azimuthStart: -PI / 2.0,
|
||||||
|
azimuthFinish: PI / 2.0
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
print("Stop emitting");
|
print("Stop emitting");
|
||||||
Entities.editEntity(particles, {
|
Entities.editEntity(particles, {
|
||||||
emitDimensions: pointDimensions,
|
emitDimensions: pointDimensions,
|
||||||
emitOrientation: verticalOrientation,
|
emitOrientation: verticalOrientation,
|
||||||
|
alphaFinish: 1.0,
|
||||||
emitRate: SLOW_EMIT_RATE,
|
emitRate: SLOW_EMIT_RATE,
|
||||||
emitSpeed: FAST_EMIT_SPEED,
|
emitSpeed: FAST_EMIT_SPEED,
|
||||||
emitAcceleration: GRAVITY_EMIT_ACCELERATON,
|
emitAcceleration: GRAVITY_EMIT_ACCELERATON,
|
||||||
|
polarStart: 0.0,
|
||||||
polarFinish: 0.0,
|
polarFinish: 0.0,
|
||||||
|
azimuthStart: -PI,
|
||||||
|
azimuthFinish: PI,
|
||||||
animationIsPlaying: false
|
animationIsPlaying: false
|
||||||
});
|
});
|
||||||
Entities.editEntity(box, {
|
Entities.editEntity(box, {
|
||||||
|
|
|
@ -66,7 +66,7 @@ const float ParticleEffectEntityItem::DEFAULT_EMIT_RADIUS_START = 1.0f; // Emit
|
||||||
const float ParticleEffectEntityItem::DEFAULT_POLAR_START = 0.0f; // Emit along z-axis
|
const float ParticleEffectEntityItem::DEFAULT_POLAR_START = 0.0f; // Emit along z-axis
|
||||||
const float ParticleEffectEntityItem::DEFAULT_POLAR_FINISH = 0.0f; // ""
|
const float ParticleEffectEntityItem::DEFAULT_POLAR_FINISH = 0.0f; // ""
|
||||||
const float ParticleEffectEntityItem::DEFAULT_AZIMUTH_START = -PI; // Emit full circumference (when polarFinish > 0)
|
const float ParticleEffectEntityItem::DEFAULT_AZIMUTH_START = -PI; // Emit full circumference (when polarFinish > 0)
|
||||||
const float ParticleEffectEntityItem::DEFAULT_AZIMUTH_FINISH = -PI; // ""
|
const float ParticleEffectEntityItem::DEFAULT_AZIMUTH_FINISH = PI; // ""
|
||||||
const glm::vec3 ParticleEffectEntityItem::DEFAULT_EMIT_ACCELERATION(0.0f, -9.8f, 0.0f);
|
const glm::vec3 ParticleEffectEntityItem::DEFAULT_EMIT_ACCELERATION(0.0f, -9.8f, 0.0f);
|
||||||
const glm::vec3 ParticleEffectEntityItem::DEFAULT_ACCELERATION_SPREAD(0.0f, 0.0f, 0.0f);
|
const glm::vec3 ParticleEffectEntityItem::DEFAULT_ACCELERATION_SPREAD(0.0f, 0.0f, 0.0f);
|
||||||
const float ParticleEffectEntityItem::DEFAULT_PARTICLE_RADIUS = 0.025f;
|
const float ParticleEffectEntityItem::DEFAULT_PARTICLE_RADIUS = 0.025f;
|
||||||
|
@ -689,34 +689,46 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
|
||||||
(_emitSpeed + (2.0f * randFloat() - 1.0f) * _speedSpread) * (_emitOrientation * Z_AXIS);
|
(_emitSpeed + (2.0f * randFloat() - 1.0f) * _speedSpread) * (_emitOrientation * Z_AXIS);
|
||||||
_particleAccelerations[i] = _emitAcceleration + (2.0f * randFloat() - 1.0f) * _accelerationSpread;
|
_particleAccelerations[i] = _emitAcceleration + (2.0f * randFloat() - 1.0f) * _accelerationSpread;
|
||||||
|
|
||||||
} else if (_emitDimensions == glm::vec3()) {
|
|
||||||
// Emit around point
|
|
||||||
float elevation = asin(2.0f * randFloat() - 1.0f); // Distribute points evenly over surface
|
|
||||||
glm::vec3 emitDirection = _emitOrientation * fromSpherical(elevation, randFloat() * TWO_PI);
|
|
||||||
|
|
||||||
_particlePositions[i] = getPosition();
|
|
||||||
_particleVelocities[i] =
|
|
||||||
(_emitSpeed + (2.0f * randFloat() - 1.0f) * _speedSpread) * (_emitOrientation * emitDirection);
|
|
||||||
_particleAccelerations[i] = _emitAcceleration + (2.0f * randFloat() - 1.0f) * _accelerationSpread;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Emit from ellipsoid
|
// Emit around point or from ellipsoid
|
||||||
float elevation = asin(2.0f * randFloat() - 1.0f); // Distribute points approximately evenly over surface
|
// - Distribute directions evenly around point
|
||||||
float azimuth = (2.0f * randFloat() - 1.0f) * PI;
|
// - Distribute points relatively evenly over ellipsoid surface
|
||||||
// TODO: Sort out ellipsoid equations to distribute completely evenly over surface.
|
|
||||||
|
float elevationMinZ = sin(PI_OVER_TWO - _polarFinish);
|
||||||
glm::vec3 radiuses = 0.5f * _emitDimensions;
|
float elevationMaxZ = sin(PI_OVER_TWO - _polarStart);
|
||||||
float x = radiuses.x * cos(elevation) * cos(azimuth);
|
float elevation = asin(elevationMinZ + (elevationMaxZ - elevationMinZ) * randFloat());
|
||||||
float y = radiuses.y * cos(elevation) * sin(azimuth);
|
|
||||||
float z = radiuses.z * sin(elevation);
|
float azimuth;
|
||||||
glm::vec3 emitPosition = glm::vec3(x, y, z);
|
if (_azimuthFinish >= _azimuthStart) {
|
||||||
glm::vec3 emitDirection = glm::normalize(glm::vec3(
|
azimuth = _azimuthStart + (_azimuthFinish - _azimuthStart) * randFloat();
|
||||||
x / (radiuses.x * radiuses.x),
|
} else {
|
||||||
y / (radiuses.y * radiuses.y),
|
azimuth = _azimuthStart + (2.0 * PI + _azimuthFinish - _azimuthStart) * randFloat();
|
||||||
z / (radiuses.z * radiuses.z)
|
}
|
||||||
));
|
|
||||||
|
glm::vec3 emitDirection;
|
||||||
|
|
||||||
|
if (_emitDimensions == glm::vec3()) {
|
||||||
|
// Point
|
||||||
|
emitDirection = _emitOrientation * fromSpherical(elevation, azimuth);
|
||||||
|
|
||||||
|
_particlePositions[i] = getPosition();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Ellipsoid
|
||||||
|
glm::vec3 radiuses = 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);
|
||||||
|
glm::vec3 emitPosition = glm::vec3(x, y, z);
|
||||||
|
emitDirection = glm::normalize(glm::vec3(
|
||||||
|
x / (radiuses.x * radiuses.x),
|
||||||
|
y / (radiuses.y * radiuses.y),
|
||||||
|
z / (radiuses.z * radiuses.z)
|
||||||
|
));
|
||||||
|
|
||||||
|
_particlePositions[i] = getPosition() + _emitOrientation * emitPosition;
|
||||||
|
}
|
||||||
|
|
||||||
_particlePositions[i] = getPosition() + _emitOrientation * emitPosition;
|
|
||||||
_particleVelocities[i] =
|
_particleVelocities[i] =
|
||||||
(_emitSpeed + (2.0f * randFloat() - 1.0f) * _speedSpread) * (_emitOrientation * emitDirection);
|
(_emitSpeed + (2.0f * randFloat() - 1.0f) * _speedSpread) * (_emitOrientation * emitDirection);
|
||||||
_particleAccelerations[i] = _emitAcceleration + (2.0f * randFloat() - 1.0f) * _accelerationSpread;
|
_particleAccelerations[i] = _emitAcceleration + (2.0f * randFloat() - 1.0f) * _accelerationSpread;
|
||||||
|
|
Loading…
Reference in a new issue