mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 23:13:09 +02:00
added sphere resolution to emitter attributes
This commit is contained in:
parent
ad0ca748bb
commit
13e6f2e6fa
3 changed files with 59 additions and 49 deletions
|
@ -11,10 +11,11 @@
|
|||
#include "ParticleSystem.h"
|
||||
#include "Application.h"
|
||||
|
||||
const float DEFAULT_PARTICLE_RADIUS = 0.01f;
|
||||
const float DEFAULT_PARTICLE_BOUNCE = 1.0f;
|
||||
const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f;
|
||||
const float DEFAULT_PARTICLE_LIFESPAN = 1.0f;
|
||||
const float DEFAULT_PARTICLE_RADIUS = 0.01f;
|
||||
const float DEFAULT_PARTICLE_BOUNCE = 1.0f;
|
||||
const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f;
|
||||
const float DEFAULT_PARTICLE_LIFESPAN = 1.0f;
|
||||
const int DEFAULT_PARTICLE_SPHERE_RESOLUTION = 6;
|
||||
|
||||
ParticleSystem::ParticleSystem() {
|
||||
|
||||
|
@ -27,6 +28,7 @@ ParticleSystem::ParticleSystem() {
|
|||
_emitter[emitterIndex].position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_emitter[emitterIndex].direction = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
_emitter[emitterIndex].visible = false;
|
||||
_emitter[emitterIndex].particleResolution = DEFAULT_PARTICLE_SPHERE_RESOLUTION;
|
||||
_emitter[emitterIndex].particleLifespan = DEFAULT_PARTICLE_LIFESPAN;
|
||||
_emitter[emitterIndex].baseParticle.alive = false;
|
||||
_emitter[emitterIndex].baseParticle.age = 0.0f;
|
||||
|
@ -279,7 +281,7 @@ void ParticleSystem::render() {
|
|||
glColor4f(_emitter[e].baseParticle.color.r, _emitter[e].baseParticle.color.g, _emitter[e].baseParticle.color.b, _emitter[e].baseParticle.color.a );
|
||||
glPushMatrix();
|
||||
glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z);
|
||||
glutSolidSphere(_emitter[e].baseParticle.radius, 6, 6);
|
||||
glutSolidSphere(_emitter[e].baseParticle.radius, _emitter[e].particleResolution, _emitter[e].particleResolution);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
@ -330,7 +332,7 @@ void ParticleSystem::renderParticle(int p) {
|
|||
} else {
|
||||
glPushMatrix();
|
||||
glTranslatef(_particle[p].position.x, _particle[p].position.y, _particle[p].position.z);
|
||||
glutSolidSphere(_particle[p].radius, 6, 6);
|
||||
glutSolidSphere(_particle[p].radius, _emitter[_particle[p].emitterIndex].particleResolution, _emitter[_particle[p].emitterIndex].particleResolution);
|
||||
glPopMatrix();
|
||||
|
||||
if (SHOW_VELOCITY_TAILS) {
|
||||
|
|
|
@ -10,31 +10,32 @@
|
|||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
const int MAX_PARTICLES = 5000;
|
||||
const int MAX_EMITTERS = 20;
|
||||
const int MAX_PARTICLES = 5000;
|
||||
const int MAX_EMITTERS = 20;
|
||||
const int NUM_PARTICLE_LIFE_STAGES = 4;
|
||||
const bool USE_BILLBOARD_RENDERING = false;
|
||||
const bool SHOW_VELOCITY_TAILS = false;
|
||||
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;
|
||||
float jitter;
|
||||
float emitterAttraction;
|
||||
float tornadoForce;
|
||||
float neighborAttraction;
|
||||
float neighborRepulsion;
|
||||
bool usingCollisionSphere;
|
||||
glm::vec3 collisionSpherePosition;
|
||||
float collisionSphereRadius;
|
||||
float radius; // radius of the particle
|
||||
glm::vec4 color; // color (rgba) of the particle
|
||||
float bounce; // how much reflection when the particle collides with floor/ground
|
||||
float gravity; // force opposite of up direction
|
||||
float airFriction; // continual dampening of velocity
|
||||
float jitter; // random forces on velocity
|
||||
float emitterAttraction; // an attraction to the emitter position
|
||||
float tornadoForce; // force perpendicular to direction axis
|
||||
float neighborAttraction; // causes particle to be pulled towards next particle in list
|
||||
float neighborRepulsion; // causes particle to be repelled by previous particle in list
|
||||
bool usingCollisionSphere; // set to true to allow collision with a sphere
|
||||
glm::vec3 collisionSpherePosition; // position of the collision sphere
|
||||
float collisionSphereRadius; // radius of the collision sphere
|
||||
};
|
||||
|
||||
// public methods...
|
||||
ParticleSystem();
|
||||
|
||||
int addEmitter(); // add (create new) emitter and get its unique id
|
||||
|
@ -47,14 +48,15 @@ public:
|
|||
void setShowingEmitterBaseParticle(int emitterIndex, bool showing );
|
||||
void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles
|
||||
void setParticleAttributes (int emitterIndex, int lifeStage, ParticleAttributes attributes); // set attributes for this life stage of particles
|
||||
void setEmitterBaseParticleColor (int emitterIndex, glm::vec4 color ) {_emitter[emitterIndex].baseParticle.color = color; }
|
||||
void setEmitterBaseParticleRadius (int emitterIndex, float radius ) {_emitter[emitterIndex].baseParticle.radius = radius; }
|
||||
void setEmitterPosition (int emitterIndex, glm::vec3 position ) {_emitter[emitterIndex].position = position; }
|
||||
void setEmitterDirection (int emitterIndex, glm::vec3 direction) {_emitter[emitterIndex].direction = direction; }
|
||||
void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; }
|
||||
void setEmitterParticleLifespan (int emitterIndex, float lifespan ) {_emitter[emitterIndex].particleLifespan = lifespan; }
|
||||
void setEmitterThrust (int emitterIndex, float thrust ) {_emitter[emitterIndex].thrust = thrust; }
|
||||
void setEmitterRate (int emitterIndex, float rate ) {_emitter[emitterIndex].rate = rate; }
|
||||
void setEmitterBaseParticleColor (int emitterIndex, glm::vec4 color ) {_emitter[emitterIndex].baseParticle.color = color; }
|
||||
void setEmitterBaseParticleRadius (int emitterIndex, float radius ) {_emitter[emitterIndex].baseParticle.radius = radius; }
|
||||
void setEmitterPosition (int emitterIndex, glm::vec3 position ) {_emitter[emitterIndex].position = position; }
|
||||
void setEmitterParticleResolution (int emitterIndex, int resolution) {_emitter[emitterIndex].particleResolution = resolution; }
|
||||
void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; }
|
||||
void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; }
|
||||
void setEmitterParticleLifespan (int emitterIndex, float lifespan ) {_emitter[emitterIndex].particleLifespan = lifespan; }
|
||||
void setEmitterThrust (int emitterIndex, float thrust ) {_emitter[emitterIndex].thrust = thrust; }
|
||||
void setEmitterRate (int emitterIndex, float rate ) {_emitter[emitterIndex].rate = rate; }
|
||||
|
||||
private:
|
||||
|
||||
|
@ -69,13 +71,14 @@ private:
|
|||
};
|
||||
|
||||
struct Emitter {
|
||||
glm::vec3 position;
|
||||
glm::vec3 direction;
|
||||
bool visible;
|
||||
float particleLifespan;
|
||||
float thrust;
|
||||
float rate;
|
||||
Particle baseParticle; // a non-physical particle at the emitter position
|
||||
glm::vec3 position; // teh position of the emitter in world coordinates
|
||||
glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects
|
||||
bool visible; // whether or not a line is shown indicating the emitter (indicating its direction)
|
||||
float particleLifespan; // how long the particle shall live, in seconds
|
||||
int particleResolution; // for sphere-based particles
|
||||
float thrust; // the initial velocity upon emitting along the emitter direction
|
||||
float rate; // currently, how many particles emitted during a simulation time step
|
||||
Particle baseParticle; // a non-physical particle at the emitter position
|
||||
ParticleAttributes particleAttributes[NUM_PARTICLE_LIFE_STAGES]; // the attributes of particles emitted from this emitter
|
||||
};
|
||||
|
||||
|
|
|
@ -331,9 +331,10 @@ void Hand::setRaveGloveMode(int mode) {
|
|||
//-----------------------------------------
|
||||
if (mode == 0) {
|
||||
|
||||
_particleSystem.setEmitterParticleLifespan(_fingerParticleEmitter[f], 1.0f);
|
||||
_particleSystem.setEmitterThrust(_fingerParticleEmitter[f], 0.002f);
|
||||
_particleSystem.setEmitterRate(_fingerParticleEmitter[f], 1.0);
|
||||
_particleSystem.setEmitterParticleLifespan (_fingerParticleEmitter[f], 1.0f );
|
||||
_particleSystem.setEmitterThrust (_fingerParticleEmitter[f], 0.002f );
|
||||
_particleSystem.setEmitterRate (_fingerParticleEmitter[f], 1.0 );
|
||||
_particleSystem.setEmitterParticleResolution(_fingerParticleEmitter[f], 6 );
|
||||
|
||||
attributes.radius = 0.0f;
|
||||
attributes.color = glm::vec4( 1.0f, 1.0f, 0.5f, 0.5f);
|
||||
|
@ -370,9 +371,10 @@ void Hand::setRaveGloveMode(int mode) {
|
|||
//-----------------------------------------
|
||||
} else if (mode == 1) {
|
||||
|
||||
_particleSystem.setEmitterParticleLifespan(_fingerParticleEmitter[f], 1.0f);
|
||||
_particleSystem.setEmitterThrust(_fingerParticleEmitter[f], 0.002f);
|
||||
_particleSystem.setEmitterRate(_fingerParticleEmitter[f], 10.0);
|
||||
_particleSystem.setEmitterParticleLifespan (_fingerParticleEmitter[f], 1.0f );
|
||||
_particleSystem.setEmitterThrust (_fingerParticleEmitter[f], 0.002f );
|
||||
_particleSystem.setEmitterRate (_fingerParticleEmitter[f], 10.0 );
|
||||
_particleSystem.setEmitterParticleResolution(_fingerParticleEmitter[f], 5 );
|
||||
|
||||
attributes.radius = 0.001f;
|
||||
attributes.color = glm::vec4( 0.8f, 0.9f, 1.0f, 0.5f);
|
||||
|
@ -403,9 +405,10 @@ void Hand::setRaveGloveMode(int mode) {
|
|||
//-----------------------------------------
|
||||
} else if (mode == 2) {
|
||||
|
||||
_particleSystem.setEmitterParticleLifespan(_fingerParticleEmitter[f], 0.05f);
|
||||
_particleSystem.setEmitterThrust(_fingerParticleEmitter[f], 0.002f);
|
||||
_particleSystem.setEmitterRate(_fingerParticleEmitter[f], 1.0);
|
||||
_particleSystem.setEmitterParticleLifespan (_fingerParticleEmitter[f], 0.05f );
|
||||
_particleSystem.setEmitterThrust (_fingerParticleEmitter[f], 0.002f );
|
||||
_particleSystem.setEmitterRate (_fingerParticleEmitter[f], 1.0 );
|
||||
_particleSystem.setEmitterParticleResolution(_fingerParticleEmitter[f], 12 );
|
||||
|
||||
attributes.radius = 0.0f;
|
||||
attributes.color = glm::vec4( 1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
@ -437,8 +440,10 @@ void Hand::setRaveGloveMode(int mode) {
|
|||
//-----------------------------------------
|
||||
} else if (mode == 3) {
|
||||
|
||||
_particleSystem.setEmitterParticleLifespan(_fingerParticleEmitter[f], 0.05f);
|
||||
_particleSystem.setEmitterThrust(_fingerParticleEmitter[f], 0.002f);
|
||||
_particleSystem.setEmitterParticleLifespan (_fingerParticleEmitter[f], 0.05f );
|
||||
_particleSystem.setEmitterThrust (_fingerParticleEmitter[f], 0.002f );
|
||||
_particleSystem.setEmitterRate (_fingerParticleEmitter[f], 1.0f );
|
||||
_particleSystem.setEmitterParticleResolution(_fingerParticleEmitter[f], 20 );
|
||||
|
||||
attributes.radius = 0.02f;
|
||||
attributes.color = glm::vec4( 1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
|
Loading…
Reference in a new issue