void createParticles() {
  Particle p1 = Particle();
  unsigned int i;
  srand(time(NULL)); // for rand function
  if (objFile) {
    maxX = vertexes[0].getX();
    maxY = vertexes[0].getY();
    maxZ = vertexes[0].getZ();
    for(i = 0; i < vertexes.size(); i++) {
      //p1 = Particle(0.02, 0.0, 3.0, 998.29, 0, 3.5, vertexes[i], Vector(0, 0, 0));
      p1 = Water(vertexes[i]);
      if (maxX < vertexes[i].getX()) {
        maxX = vertexes[i].getX();
      }
      if (maxY < vertexes[i].getY()) {
        maxY = vertexes[i].getY();
      }
      if (maxZ < vertexes[i].getZ()) {
        maxZ = vertexes[i].getZ();
      }
      pSystem.addParticle(p1);
    }
    pSystem.setBoundaries(-maxX, -1, -maxZ, maxX + 1, maxY + 1, maxZ + 1);
  } else {
    for(i = 0; i < numParticles/2; i++) {
      p1 = Water();
      pSystem.addParticle(p1);
    }
    for(; i < numParticles; i++) {
      p1 = Mucus();
      pSystem.addParticle(p1);
    }
  }  
}
void Demo::update() {
  Vec2f gravity = Vec2f(0, 0.01);
  particleSystem->applyForce(gravity);

  float dx = lmap((float)getMousePos().x, 0.0f, (float)getWindowWidth(), -0.2f, 0.2f);
  Vec2f wind = Vec2f(dx, 0);
  particleSystem->applyForce(wind);

  particleSystem->addParticle();
  particleSystem->update();
}
void NOC_4_08_ParticleSystemSmokeApp::draw()
{
	gl::clear( Color::black() );
	
	// Calculate a "wind" force based on mouse horizontal position
	float dx = lmap( mousePos.x, 0.0f, float( getWindowWidth() ), -0.2f, 0.2f );
	Vec2f wind = Vec2f( dx, 0 );
	ps.applyForce(wind);

	for( int i = 0; i < 2; i++ ){
		ps.addParticle();
	}
	ps.run();
	
	// Draw an arrow representing the wind force
	drawVector( wind, Vec2f( getWindowWidth() / 2, 50 ), 500 );
}
Example #4
0
void AddParticleStartingAt(Vec4<float> WorldPoint) {
	ParticleSystem* ps = ModelerApplication::Instance()->GetParticleSystem();
	for (int i = 0; i < VAL(PARTICLE_COUNT) * 5 ; i++) {

		float mag = rand() % 10 / 10.0 + 0.2;
		float theta = rand() % 360 / 57.3;
		float yVelocity = rand() % 10 / 10.0 + 2;
		float xVelocity = cos(theta) * mag;
		float zVelocity = sin(theta) * mag * 3;
		//printf("add: %f, %f, %f\n", WorldPoint[0], WorldPoint[1], WorldPoint[2]);
		Vec3f position(WorldPoint[0], WorldPoint[1], WorldPoint[2]);
		Vec3f velocity(xVelocity, 5, zVelocity);
		Particle* p = new PointObj(1.0f, position, velocity);
		//printf("added: %f, %f, %f\n", p->getPosition()[0], p->getPosition()[1], p->getPosition()[2]);

		ps->addParticle(p);
	}
}
void keyboard(unsigned char key, int x, int y) {
  Particle p1;
  switch(key) {
    case ' ': // allow spacebar to end the program
      exit(0);
      break;
    case 'b':
      maxX = 1;
      maxY = 0;
      maxZ = 1;
      bBoxScene = false;
      bxScene = false;
      bzScene = false;
      bNoBound = true;
      pSystem.setBoundaries(-maxX, -1, -maxZ, maxX, maxY, maxZ);
      break;
    case 'p':
      p1 = Water();
      p1.setPosition(Point3D(0,.1,0));
      pSystem.addParticle(p1);
      break;
	case 'o':
		for(float i = 0.; i < 5; i++){
			for(float j = 0.; j < 5; j++){
				for(float k = 0.; k < 5; k++){
					p1 = Mucus();
					p1.setPosition(Point3D(i/50,j/50-.2,k/50));
					pSystem.addParticle(p1);
				}
			}
		}
      break;
	  	case 'w':
		for(float i = 0.; i < 5; i++){
			for(float j = 0.; j < 5; j++){
				for(float k = 0.; k < 5; k++){
					p1 = Water();
					p1.setPosition(Point3D(i/50,j/50-.2,k/50));
					pSystem.addParticle(p1);
				}
			}
		}
      break;
    case 'x': // opens up x portion of boundary
      bBoxScene = false;
      bxScene = true;
      bzScene = false;
      bNoBound = false;
      pSystem.setBoundaries(-1, -1, -.1, .1, 0, .1);
      break;
    case 'z': // open up z portion of the boundary
      bBoxScene = false;
      bxScene = false;
      bzScene = true;
      bNoBound = false;
      pSystem.setBoundaries(-.1, -1, -.2, .1, 0, .1);
      break;
	case 'c': // change camera
		camera++;
		if (camera > numcameras)
			camera = 1;
		break;
    default:
      break;
  }
  glutPostRedisplay();
}
Example #6
0
void ParticleFactory::perform(const double elapsedSeconds, const Vec2f origin, const Listener& list, ParticleSystem & ps)
{
	double offsetSeconds = elapsedSeconds + d_adjustSeconds - d_offsetTime;
	if (offsetSeconds < 0)
		ci::app::console() << "waiting for song to start..." << std::endl;

	if (offsetSeconds >= 30 && offsetSeconds < 45)
	{
		while (ps.mParticles.size() < 3)
		{
			Particle* particle = new ParticleG(origin, list);
			ps.addParticle(particle);
		}
	}
	if (offsetSeconds >= 45 && offsetSeconds < 75)
	{
		Particle* particle = new ParticleC(origin, list);
		ps.addParticle(particle);
	}
	if (offsetSeconds >= 75 && offsetSeconds < 105)
	{
		Particle* particle = new ParticleB(origin, list);
		ps.addParticle(particle);
	}
	if (offsetSeconds >= 105 && offsetSeconds < 135)
	{
		Particle* particle = new ParticleL(origin, list);
		ps.addParticle(particle);
	}
	if (offsetSeconds >= 135 && offsetSeconds < 150)
	{
		Particle* particle = new ParticleI(origin, list);
		ps.addParticle(particle);
	}
	if (offsetSeconds >= 135 && offsetSeconds < 165)
	{
		for (int i = 0; i < (int)(list.getVolume()*10.f); ++i)
		{
			Particle* particle = new ParticleD(origin, list);
			ps.addParticle(particle);
		}
		for (int i = 0; i < 3; ++i)
		{
			Particle* particle = new ParticleA(origin, list);
			particle->mOrientation = ps.mOrientation;
			ps.addParticle(particle);
		}
	}
	if (offsetSeconds >= 165 && offsetSeconds < 195)
	{
		for (int i = 0; i < 4; ++i)
		{
			Particle* particle = new ParticleH(origin, list);
			ps.addParticle(particle);
		}
	}
	if (offsetSeconds >= 195 && offsetSeconds < 210)
	{
		for (int i = 0; i < 4; ++i)
		{
			Particle* particle = new ParticleF(origin, list);
			particle->mOrientation = ps.mOrientation;
			ps.addParticle(particle);
		}
		Particle* particle = new ParticleE(origin, list);
		particle->mOrientation = ps.mOrientation;
		ps.addParticle(particle);
	}
	if (offsetSeconds >= 210 && offsetSeconds < 225)
	{
		Particle* particle = new ParticleJ(origin, list);
		ps.addParticle(particle);
	}
	if (offsetSeconds >= 225 && offsetSeconds < 255)
	{
		Particle* particle = new ParticleN(origin, list);
		ps.addParticle(particle);
	}
	if (offsetSeconds >= 255 )
	{
		Particle* particle = new ParticleK(origin, list);
		ps.addParticle(particle);
	}

}
Example #7
0
void ParticleFactory::create(const double elapsedSeconds, const Vec2f origin, const Listener& list, ParticleSystem & ps)
{
	ps.mUnderlays = 3;
	switch (d_particleToCreate)
	{
	
	case PARTICLE_A:{
		for (int i = 0; i < 3; ++i)
		{
			Particle* particle = new ParticleA(origin, list);
			particle->mOrientation = ps.mOrientation;
			ps.addParticle(particle);
		}
	}break;
	case PARTICLE_B:{
		Particle* particle = new ParticleB(origin, list);
			ps.addParticle(particle);
	}break;
	case PARTICLE_C:{
		Particle* particle = new ParticleC(origin, list);
			ps.addParticle(particle);
	}break;
	case PARTICLE_D:{
		for (int i = 0; i < (int)(list.getVolume()*20.f); ++i)
		{
			Particle* particle = new ParticleD(origin, list);
			ps.addParticle(particle);
		}
	}break;
	case PARTICLE_E:{
			Particle* particle = new ParticleE(origin, list);
			particle->mOrientation = ps.mOrientation;
			ps.addParticle(particle);
	}break;
	case PARTICLE_F:{
		for (int i = 0; i < 4; ++i)
		{
			Particle* particle = new ParticleF(origin, list);
			particle->mOrientation = ps.mOrientation;
			ps.addParticle(particle);
		}
	}break;
	case PARTICLE_G:{
			while (ps.mParticles.size() < 3)
			{
				Particle* particle = new ParticleG(origin, list);
				ps.addParticle(particle);
			}
	}break;
	case PARTICLE_H:{
		for (int i = 0; i < 4; ++i)
		{
			Particle* particle = new ParticleH(origin, list);
			ps.addParticle(particle);
		}
	}break;
	case PARTICLE_I:{
			Particle* particle = new ParticleI(origin, list);
			ps.addParticle(particle);
	}break;
	case PARTICLE_J:{
		Particle* particle = new ParticleJ(origin, list);
		ps.addParticle(particle);
	}break;
	case PARTICLE_K:{
		Particle* particle = new ParticleK(origin, list);
		ps.addParticle(particle);
	}break;
	case PARTICLE_L:{
		Particle* particle = new ParticleL(origin, list);
		ps.addParticle(particle);
	}break;
	case PARTICLE_M:{
		Particle* particle = new ParticleM(origin, list);
		particle->mOrientation = ps.mOrientation;
		ps.addParticle(particle);
		ps.mUnderlays = 1;
	}break;
	case PARTICLE_N:{
		Particle* particle = new ParticleN(origin, list);
		ps.addParticle(particle);
	}break;
	default:
		ci::app::console() << "UNKNOWN PARTICLE: " << d_particleToCreate;
		break;
	}
}
void Demo::update() {
  particleSystem->addParticle();
  particleSystem->update();
}