1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#include "ParticleModel.h"
#include "lookupTable.h"
ParticleModel::ParticleModel(float xPos, float yPos)
{
pos.x = xPos;
pos.y = yPos;
}
ParticleModel::~ParticleModel(void)
{
}
/*----------------------------------------------------------------------------\
* |
* STATE ACCESS (get / set) FUNCTIONS |
* |
*----------------------------------------------------------------------------*/
/*
* Sets position of particle.
*
* Parameter list
* xPos x-coordinate of position.
* yPos y-coordinate of position.
*/
void ParticleModel::setPosition(float xPos, float yPos)
{
// position of particle
pos.x = xPos; pos.y = yPos;
}
/* TODO: Add functions to set other particle model parameters, e.g. velocity, acceleration, ... */
/*
* Gets position of particle.
*
* Parameter list
* none.
*/
Point2D ParticleModel::getPosition()
{
return pos;
}
//New pieces of information from 13.10
void ParticleModel::reset_Particles(void)
{
//This initialises and resets the particles within the model
//Loop through all current particles and set their state to dead
for (int index = 0; index < max_Particles; index++)
{
particles[index].state = PARTICLE_STATE_DEAD;
particles[index].type = PARTICLE_TYPE_FADE;
particles[index].x = 0;
particles[index].y = 0;
particles[index].xv = 0;
particles[index].yv = 0;
particles[index].counter = 0;
particles[index].max_count = 0;
}
} //End reset_Particles
void ParticleModel::start_Particle(int type, int count, int x, int y, int xv, int yv)
{
//This initialises a single particle.
int pindex = -1; //Local declaration of pindex for use in this method only
//Check to see if any particles are alive
//If so, set to dead
for (int index = 0; index < max_Particles; index++)
if (particles[index].state == PARTICLE_STATE_DEAD)
{
//Setting the local index
pindex = index;
break;
}
if (pindex ==-1)
return;
//Setting the general information relating to a particle
particles[index].state = PARTICLE_STATE_ALIVE;
particles[index].type = type;
particles[index].x = x;
particles[index].y = y;
particles[index].xv = xv;
particles[index].yv = yv;
particles[index].counter = 0;
particles[index].max_count = count;
}//End start_Particle
void ParticleModel::start_Particles_Explosion(int type, int count, int x, int y, int xv, int yv, int num_particles)
{
//This function will start a particle explosion at a given position and velocity
while(--num_particles >= 0)
{
//Calculating a random position in a 360 radius to fire the particle
int ang = rand()%360;
//Calculating a random velocity for each particle
float vel = 2+rand()%4;
start_Particle(type, count, x+RAND_RANGE(-4,4),y+RAND_RANGE(-4,4),xv+cos_look[ang]*vel, yv+sin_look[ang]*vel);
}
}//End start_Particle_Explosion
void start_Particle_Ring(int type, int count, int x, int y, int xv, int yv, int num_particles)
{
//This function starts a particle explision at a given position and velocity
//Uses the new lookup tables
//Calculate random trajectory angle
float vel = 2+rand()%4;
while(--num_particles >=0)
{
int ang = rand()%360;
start_Particle(type, count, x, y, xv+cos_look[ang]*vel, yv+sin_look[ang]*vel);
}
}//end start_Particle_Ring
void ParticleModel::draw_Particles(void)
{
for (int index = 0; index < max_Particles; index++)
{
//Test to see if particle is alive
if (particles[index].state = PARTICLE_STATE_ALIVE)
int x = particles[index].x;
int y = particles[index].y;
//Collision detection removed as it is elsewhere in the software.
}
}
|