/*************************************** Auteur : Pierre Aubert Mail : aubertp7@gmail.com Licence : CeCILL-C ****************************************/ #include "asterics_random.h" #include "table_particle.h" ///Allocate the tables of position, velocity and acceleration /** @param[out] tp : table of particles * @param nbParticle */ void allocTableParticle(TableParticle & tp, size_t nbParticle){ tp.nbParticle = nbParticle; tp.tabPosX = new float[nbParticle]; tp.tabPosY = new float[nbParticle]; tp.tabPosZ = new float[nbParticle]; tp.tabVitX = new float[nbParticle]; tp.tabVitY = new float[nbParticle]; tp.tabVitZ = new float[nbParticle]; tp.tabAccX = new float[nbParticle]; tp.tabAccY = new float[nbParticle]; tp.tabAccZ = new float[nbParticle]; } ///Init the tables of position, velocity and acceleration /** @param[out] tp : table of particles */ void initTableParticle(TableParticle & tp){ unsigned int seed = initRandom(); std::cout << "initTableParticle : seed = " << seed << std::endl; size_t nbParticle(tp.nbParticle); for(size_t i(0lu); i < nbParticle; ++i){ tp.tabPosX[i] = randfloat(-1.0f, 1.0f); tp.tabPosY[i] = randfloat(-1.0f, 1.0f); tp.tabPosZ[i] = randfloat(-1.0f, 1.0f); tp.tabVitX[i] = randfloat(-0.005f, 0.005f); tp.tabVitY[i] = randfloat(-0.005f, 0.005f); tp.tabVitZ[i] = randfloat(-0.005f, 0.005f); tp.tabAccX[i] = 0.0f; tp.tabAccY[i] = 0.0f; tp.tabAccZ[i] = -9.81f; } } ///Free the table of particles /** @param[out] tp : table of particles */ void freeTableParticle(TableParticle & tp){ delete [] tp.tabPosX; delete [] tp.tabPosY; delete [] tp.tabPosZ; delete [] tp.tabVitX; delete [] tp.tabVitY; delete [] tp.tabVitZ; delete [] tp.tabAccX; delete [] tp.tabAccY; delete [] tp.tabAccZ; tp.tabPosX = NULL; tp.tabPosY = NULL; tp.tabPosZ = NULL; tp.tabVitX = NULL; tp.tabVitY = NULL; tp.tabVitZ = NULL; tp.tabAccX = NULL; tp.tabAccY = NULL; tp.tabAccZ = NULL; } ///Move the particles on one axis /** @param[out] tabPos : table of particle position to the updated * @param[out] tabVit : table of particle velocity to the updated * @param[out] tabAcc : table of particle acceleration to the updated * @param nbParticle : number of particles * @param dt : ellapsed time */ void moveParticleOnAxis(float * tabPos, float * tabVit, const float * tabAcc, size_t nbParticle, float dt){ for(size_t i(0lu); i < nbParticle; ++i){ tabVit[i] += tabAcc[i]*dt; tabPos[i] += tabVit[i]*dt; } } ///Move the particles /** @param[out] tp : table of particle to the updated * @param dt : ellapsed time */ void moveParticle(TableParticle & tp, float dt){ size_t nbParticle(tp.nbParticle); moveParticleOnAxis(tp.tabPosX, tp.tabVitX, tp.tabAccX, nbParticle, dt); moveParticleOnAxis(tp.tabPosY, tp.tabVitY, tp.tabAccY, nbParticle, dt); moveParticleOnAxis(tp.tabPosZ, tp.tabVitZ, tp.tabAccZ, nbParticle, dt); }