Skip to content

Commit

Permalink
reworked reset and particle initialization to assure particle will al…
Browse files Browse the repository at this point in the history
…ways be centered
  • Loading branch information
Syntaf committed Oct 8, 2014
1 parent e192a10 commit 3e40ce5
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/particlemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,22 @@ ParticleManager::~ParticleManager()

void ParticleManager::initParticles()
{
for(int i=0; i<(int)sqrt(d_MAXPARTICLES); i++) {
for(int j=0; j<(int)sqrt(d_MAXPARTICLES); j++) {
int max_particles = (int)sqrt(d_MAXPARTICLES);
for(int i=0; i<max_particles; i++) {
for(int j=0; j<max_particles; j++) {
//create single particle and place it in allignment with other particles to form
//a square
Particle particle;
glm::vec2 d2Pos = glm::vec2(j*0.06, i*0.06) + glm::vec2(-17.0f,-17.0f);
auto factor_x = (i - (float)max_particles / 2.0f) / (float)max_particles;
auto factor_y = (j - (float)max_particles / 2.0f) / (float)max_particles;

//multiply by arbitrary constant
glm::vec2 particle_locale_delta = glm::vec2(30 * factor_x, 30 * factor_y);
glm::vec2 d2Pos = glm::vec2(0, 0);
d2Pos += particle_locale_delta;
particle.pos = glm::vec3(d2Pos.x,d2Pos.y,-70);

//set particle constants
particle.life = 1000.0f;
particle.cameradistance = -1.0f;

Expand Down Expand Up @@ -366,11 +376,20 @@ void ParticleManager::setColorRand(const int& val)
void ParticleManager::resetParticles()
{
d_particles_container.clear();
for(int i=0; i<(int)sqrt(d_MAXPARTICLES); i++) {
for(int j=0; j<(int)sqrt(d_MAXPARTICLES); j++) {
Particle particle;
glm::vec2 d2Pos = glm::vec2(j*0.06, i*0.06) + glm::vec2(-20.0f,-20.0f);
particle.pos = glm::vec3(d2Pos.x,d2Pos.y,-70);
int max_particles = (int)sqrt(d_MAXPARTICLES);
for(int i=0; i<max_particles; i++) {
for(int j=0; j<max_particles; j++) {
//create single particle and place it in allignment with other particles to form
//a square
Particle particle;
auto factor_x = (i - (float)max_particles / 2.0f) / (float)max_particles;
auto factor_y = (j - (float)max_particles / 2.0f) / (float)max_particles;

//multiply by arbitrary constant
glm::vec2 particle_locale_delta = glm::vec2(30 * factor_x, 30 * factor_y);
glm::vec2 d2Pos = glm::vec2(0, 0);
d2Pos += particle_locale_delta;
particle.pos = glm::vec3(d2Pos.x, d2Pos.y, -70);

particle.life = 1000.0f;
particle.cameradistance = -1.0f;
Expand Down

0 comments on commit 3e40ce5

Please sign in to comment.