Skip to content

Commit 3e40ce5

Browse files
committed
reworked reset and particle initialization to assure particle will always be centered
1 parent e192a10 commit 3e40ce5

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/particlemanager.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,22 @@ ParticleManager::~ParticleManager()
5050

5151
void ParticleManager::initParticles()
5252
{
53-
for(int i=0; i<(int)sqrt(d_MAXPARTICLES); i++) {
54-
for(int j=0; j<(int)sqrt(d_MAXPARTICLES); j++) {
53+
int max_particles = (int)sqrt(d_MAXPARTICLES);
54+
for(int i=0; i<max_particles; i++) {
55+
for(int j=0; j<max_particles; j++) {
56+
//create single particle and place it in allignment with other particles to form
57+
//a square
5558
Particle particle;
56-
glm::vec2 d2Pos = glm::vec2(j*0.06, i*0.06) + glm::vec2(-17.0f,-17.0f);
59+
auto factor_x = (i - (float)max_particles / 2.0f) / (float)max_particles;
60+
auto factor_y = (j - (float)max_particles / 2.0f) / (float)max_particles;
61+
62+
//multiply by arbitrary constant
63+
glm::vec2 particle_locale_delta = glm::vec2(30 * factor_x, 30 * factor_y);
64+
glm::vec2 d2Pos = glm::vec2(0, 0);
65+
d2Pos += particle_locale_delta;
5766
particle.pos = glm::vec3(d2Pos.x,d2Pos.y,-70);
5867

68+
//set particle constants
5969
particle.life = 1000.0f;
6070
particle.cameradistance = -1.0f;
6171

@@ -366,11 +376,20 @@ void ParticleManager::setColorRand(const int& val)
366376
void ParticleManager::resetParticles()
367377
{
368378
d_particles_container.clear();
369-
for(int i=0; i<(int)sqrt(d_MAXPARTICLES); i++) {
370-
for(int j=0; j<(int)sqrt(d_MAXPARTICLES); j++) {
371-
Particle particle;
372-
glm::vec2 d2Pos = glm::vec2(j*0.06, i*0.06) + glm::vec2(-20.0f,-20.0f);
373-
particle.pos = glm::vec3(d2Pos.x,d2Pos.y,-70);
379+
int max_particles = (int)sqrt(d_MAXPARTICLES);
380+
for(int i=0; i<max_particles; i++) {
381+
for(int j=0; j<max_particles; j++) {
382+
//create single particle and place it in allignment with other particles to form
383+
//a square
384+
Particle particle;
385+
auto factor_x = (i - (float)max_particles / 2.0f) / (float)max_particles;
386+
auto factor_y = (j - (float)max_particles / 2.0f) / (float)max_particles;
387+
388+
//multiply by arbitrary constant
389+
glm::vec2 particle_locale_delta = glm::vec2(30 * factor_x, 30 * factor_y);
390+
glm::vec2 d2Pos = glm::vec2(0, 0);
391+
d2Pos += particle_locale_delta;
392+
particle.pos = glm::vec3(d2Pos.x, d2Pos.y, -70);
374393

375394
particle.life = 1000.0f;
376395
particle.cameradistance = -1.0f;

0 commit comments

Comments
 (0)