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