mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 20:44:14 +02:00
added particle life stages
This commit is contained in:
parent
d572feecf9
commit
1f1259cec5
4 changed files with 59 additions and 39 deletions
|
@ -73,7 +73,7 @@ using namespace std;
|
|||
static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt";
|
||||
static char STAR_CACHE_FILE[] = "cachedStars.txt";
|
||||
|
||||
static const bool TESTING_PARTICLE_SYSTEM = true;
|
||||
static const bool TESTING_PARTICLE_SYSTEM = false;
|
||||
|
||||
static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ Hand::Hand(Avatar* owningAvatar) :
|
|||
// initialize all finger particle emitters with an invalid id as default
|
||||
for (int f = 0; f< NUM_FINGERS_PER_HAND; f ++ ) {
|
||||
_fingerParticleEmitter[f] = -1;
|
||||
|
||||
//glm::vec4 color(1.0f, 0.6f, 0.0f, 0.5f);
|
||||
//_particleSystem.setEmitterBaseParticle(f, true, 0.012f, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,17 +184,14 @@ void Hand::updateFingerParticles(float deltaTime) {
|
|||
|
||||
_fingerParticleEmitter[f] = _particleSystem.addEmitter();
|
||||
|
||||
glm::vec4 color(1.0f, 0.6f, 0.0f, 0.5f);
|
||||
|
||||
//_particleSystem.setEmitterParticle(f, true, 0.012f, color);
|
||||
|
||||
ParticleSystem::ParticleAttributes attributes;
|
||||
|
||||
// set attributes for each life stage of the particle:
|
||||
attributes.radius = 0.001f;
|
||||
attributes.radius = 0.0f;
|
||||
attributes.color = glm::vec4( 1.0f, 1.0f, 0.5f, 0.5f);
|
||||
attributes.gravity = 0.0f;
|
||||
attributes.airFriction = 0.0f;
|
||||
attributes.jitter = 0.0f;
|
||||
attributes.jitter = 0.002f;
|
||||
attributes.emitterAttraction = 0.0f;
|
||||
attributes.tornadoForce = 0.0f;
|
||||
attributes.neighborAttraction = 0.0f;
|
||||
|
@ -200,13 +200,20 @@ void Hand::updateFingerParticles(float deltaTime) {
|
|||
attributes.usingCollisionSphere = false;
|
||||
_particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes);
|
||||
|
||||
attributes.radius = 0.002f;
|
||||
attributes.jitter = 0.01f;
|
||||
attributes.radius = 0.01f;
|
||||
attributes.jitter = 0.0f;
|
||||
attributes.gravity = -0.005f;
|
||||
attributes.color = glm::vec4( 1.0f, 0.2f, 0.0f, 0.4f);
|
||||
_particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes);
|
||||
|
||||
attributes.radius = 0.007f;
|
||||
attributes.gravity = -0.01f;
|
||||
attributes.radius = 0.01f;
|
||||
attributes.gravity = 0.0f;
|
||||
attributes.color = glm::vec4( 0.0f, 0.0f, 0.0f, 0.2f);
|
||||
_particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes);
|
||||
|
||||
attributes.radius = 0.02f;
|
||||
attributes.color = glm::vec4( 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
_particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes);
|
||||
}
|
||||
|
||||
_particleSystemInitialized = true;
|
||||
|
@ -233,14 +240,14 @@ void Hand::updateFingerParticles(float deltaTime) {
|
|||
|
||||
glm::quat particleEmitterRotation = rotationBetween(IDENTITY_UP, fingerDirection);
|
||||
|
||||
_particleSystem.setEmitterPosition(_fingerParticleEmitter[0], particleEmitterPosition);
|
||||
_particleSystem.setEmitterRotation(_fingerParticleEmitter[0], particleEmitterRotation);
|
||||
_particleSystem.setEmitterPosition(_fingerParticleEmitter[f], particleEmitterPosition);
|
||||
_particleSystem.setEmitterRotation(_fingerParticleEmitter[f], particleEmitterRotation);
|
||||
|
||||
float radius = 0.005f;
|
||||
glm::vec4 color(1.0f, 0.6f, 0.0f, 0.5f);
|
||||
glm::vec3 velocity = fingerDirection * 0.002f;
|
||||
float lifespan = 0.3f;
|
||||
_particleSystem.emitParticlesNow(_fingerParticleEmitter[0], 1, radius, color, velocity, lifespan);
|
||||
float lifespan = 1.0f;
|
||||
_particleSystem.emitParticlesNow(_fingerParticleEmitter[f], 1, radius, color, velocity, lifespan);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ ParticleSystem::ParticleSystem() {
|
|||
|
||||
for (int s = 0; s<NUM_PARTICLE_LIFE_STAGES; s++) {
|
||||
_emitter[e].particleAttributes[s].radius = DEFAULT_PARTICLE_RADIUS;
|
||||
_emitter[e].particleAttributes[s].color = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
_emitter[e].particleAttributes[s].bounce = DEFAULT_PARTICLE_BOUNCE;
|
||||
_emitter[e].particleAttributes[s].airFriction = DEFAULT_PARTICLE_AIR_FRICTION;
|
||||
_emitter[e].particleAttributes[s].gravity = 0.0f;
|
||||
|
@ -125,6 +126,7 @@ void ParticleSystem::createParticle(int e, glm::vec3 position, glm::vec3 velocit
|
|||
_particle[p].color = color;
|
||||
|
||||
_particle[p].radius = _emitter[e].particleAttributes[0].radius;
|
||||
_particle[p].color = _emitter[e].particleAttributes[0].color;
|
||||
|
||||
_numParticles ++;
|
||||
|
||||
|
@ -175,6 +177,7 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part
|
|||
ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage];
|
||||
|
||||
a->radius = attributes.radius;
|
||||
a->color = attributes.color;
|
||||
a->bounce = attributes.bounce;
|
||||
a->gravity = attributes.gravity;
|
||||
a->airFriction = attributes.airFriction;
|
||||
|
@ -192,19 +195,27 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part
|
|||
void ParticleSystem::updateParticle(int p, float deltaTime) {
|
||||
|
||||
assert(_particle[p].age <= _particle[p].lifespan);
|
||||
|
||||
|
||||
float ageFraction = _particle[p].age / _particle[p].lifespan;
|
||||
|
||||
int lifeStage = (int)( ageFraction * (NUM_PARTICLE_LIFE_STAGES-1) );
|
||||
|
||||
float lifeStageFraction = ageFraction * ( NUM_PARTICLE_LIFE_STAGES - 1 ) - lifeStage;
|
||||
|
||||
/*
|
||||
if ( p == 0 ) {
|
||||
printf( "lifespan = %f ageFraction = %f lifeStage = %d lifeStageFraction = %f\n", _particle[p].lifespan, ageFraction, lifeStage, lifeStageFraction );
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int lifeStage = (int)( ageFraction * NUM_PARTICLE_LIFE_STAGES );
|
||||
|
||||
|
||||
_particle[p].radius = _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage].radius;
|
||||
|
||||
|
||||
|
||||
_particle[p].radius
|
||||
= _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage ].radius * (1.0f - lifeStageFraction)
|
||||
+ _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage+1].radius * lifeStageFraction;
|
||||
|
||||
_particle[p].color
|
||||
= _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage ].color * (1.0f - lifeStageFraction)
|
||||
+ _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage+1].color * lifeStageFraction;
|
||||
|
||||
Emitter myEmitter = _emitter[_particle[p].emitterIndex];
|
||||
|
||||
// apply random jitter
|
||||
|
@ -292,13 +303,13 @@ void ParticleSystem::setCollisionSphere(int e, glm::vec3 position, float radius)
|
|||
_emitter[e].particleAttributes[lifeStage].collisionSphereRadius = radius;
|
||||
}
|
||||
|
||||
void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing ) {
|
||||
void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing ) {
|
||||
|
||||
_emitter[emitterIndex].baseParticle.alive = true;
|
||||
_emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex;
|
||||
}
|
||||
|
||||
void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing, float radius, glm::vec4 color ) {
|
||||
void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing, float radius, glm::vec4 color ) {
|
||||
|
||||
_emitter[emitterIndex].baseParticle.alive = true;
|
||||
_emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex;
|
||||
|
@ -310,7 +321,7 @@ void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing, float ra
|
|||
void ParticleSystem::render() {
|
||||
|
||||
// render the emitters
|
||||
for (unsigned int e = 0; e < _numEmitters; e++) {
|
||||
for (int e = 0; e < _numEmitters; e++) {
|
||||
|
||||
if (_emitter[e].baseParticle.alive) {
|
||||
glColor4f(_emitter[e].baseParticle.color.r, _emitter[e].baseParticle.color.g, _emitter[e].baseParticle.color.b, _emitter[e].baseParticle.color.a );
|
||||
|
@ -370,14 +381,14 @@ void ParticleSystem::renderParticle(int p) {
|
|||
glutSolidSphere(_particle[p].radius, 6, 6);
|
||||
glPopMatrix();
|
||||
|
||||
// render velocity lines
|
||||
glColor4f( _particle[p].color.x, _particle[p].color.y, _particle[p].color.z, 0.5f);
|
||||
glm::vec3 end = _particle[p].position - _particle[p].velocity * 2.0f;
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(_particle[p].position.x, _particle[p].position.y, _particle[p].position.z);
|
||||
glVertex3f(end.x, end.y, end.z);
|
||||
|
||||
glEnd();
|
||||
if (SHOW_VELOCITY_TAILS) {
|
||||
glColor4f( _particle[p].color.x, _particle[p].color.y, _particle[p].color.z, 0.5f);
|
||||
glm::vec3 end = _particle[p].position - _particle[p].velocity * 2.0f;
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(_particle[p].position.x, _particle[p].position.y, _particle[p].position.z);
|
||||
glVertex3f(end.x, end.y, end.z);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,14 +13,16 @@
|
|||
|
||||
const int MAX_PARTICLES = 5000;
|
||||
const int MAX_EMITTERS = 20;
|
||||
const int NUM_PARTICLE_LIFE_STAGES = 3;
|
||||
const int NUM_PARTICLE_LIFE_STAGES = 4;
|
||||
const bool USE_BILLBOARD_RENDERING = false;
|
||||
const bool SHOW_VELOCITY_TAILS = false;
|
||||
|
||||
class ParticleSystem {
|
||||
public:
|
||||
|
||||
struct ParticleAttributes {
|
||||
float radius;
|
||||
glm::vec4 color;
|
||||
float bounce;
|
||||
float gravity;
|
||||
float airFriction;
|
||||
|
@ -40,8 +42,8 @@ public:
|
|||
void emitParticlesNow(int emitterIndex, int numParticles, float radius, glm::vec4 color, glm::vec3 velocity, float lifespan);
|
||||
void simulate(float deltaTime);
|
||||
void render();
|
||||
void setEmitterParticle(int emitterIndex, bool showing );
|
||||
void setEmitterParticle(int emitterIndex, bool showing, float radius, glm::vec4 color );
|
||||
void setEmitterBaseParticle(int emitterIndex, bool showing );
|
||||
void setEmitterBaseParticle(int emitterIndex, bool showing, float radius, glm::vec4 color );
|
||||
|
||||
void setOrangeBlueColorPalette(); // apply a nice preset color palette to the particles
|
||||
void setUpDirection(glm::vec3 upDirection) {_upDirection = upDirection;} // tell particle system which direction is up
|
||||
|
|
Loading…
Reference in a new issue