Пример #1
0
void my_time_out(int id) { 
  int i, j,k;
  
  PARTICLE *cur;
  EXPLOSION *cur_explosion;
  float fall_time;
  for (j = 0; j < NUM_NOZZLES; j++) {
    
    cur_explosion = &explosions[j];
    for (i = 0; i < (&explosions[j])->quantity; i++) {
    
      cur = &(cur_explosion->particles[i]);
    
      if (cur_explosion->counter < cur_explosion->radius) {
        real_translation(&(cur->shape), cur->translation[0], cur->translation[1], cur->translation[2]);
      }
    
      else {
    
        if (cur_explosion->counter > cur_explosion->radius && cur_explosion->counter < cur_explosion->radius + cur_explosion->after_counter && cur_explosion -> radius > 0) {
          fall_time =(float)((rand() % (10)))/100000.;
          real_translation(&(cur->shape), 0, -fall_time*5, 0);
          cur->init_color[0]=cur->init_color[0]-250*fall_time;
          cur->init_color[1]=cur->init_color[1]-250*fall_time;
          cur->init_color[2]=cur->init_color[2]-250*fall_time;
          if(!cur_explosion->fizz){
         // 	BASS_ChannelPlay(sounds[7], TRUE);
          	cur_explosion->fizz=1;
          	
          }
          // TODO THIS IS WHERE WE WANT TO START FADING AS WELL
        }

        if (cur_explosion->counter > cur_explosion->after_counter && cur_explosion -> radius > 0) {
          printf("Resetting explosion for key %d\n", j+1);
          cur_explosion->fizz=0;
          free(&(cur_explosion->particles[0]));
          cur_explosion -> radius = 0;
          cur_explosion -> density = 0;
          cur_explosion -> quantity = 0;
          cur_explosion -> cube_size = 0;
          cur_explosion -> shape = 0;
          cur_explosion -> counter = 0;
          cur_explosion -> start_x = 0;
          cur_explosion -> start_y = 0;
          cur_explosion -> after_counter = 0;
        }
      }  
    }
    if (cur_explosion->radius > 0) {
      cur_explosion->counter += 1;
    }
  }
  glutPostRedisplay();                       // re-draw the scene
  glutTimerFunc(timer_speed, my_time_out, 0); // keeps the timer moving, at timer_speed ms

}
Пример #2
0
void intersect()
{
	GLfloat p[4] = {player->pos[0], player->pos[1], player->pos[2], 1};		//never change p
	GLfloat d[4] = {player->u[0], player->u[1], player->u[2], 0};			//never change d
	GLfloat result[3];

	for(int i = 0; i < shapeList.size(); i++) 
	{
		shapeList[i]->intersect(p, d, result);
		//result[] = {# of intersections, t1, t1}

		if (result[0] > 0)		//If there was a hit - (either 1 or 2 intersections)
		{
			if (result[1] >= 0)			//Dont draw intersects behind you
			{
				//x = p + dt
				GLfloat intersect1[3] = {d[0] * result[1], d[1] * result[1], d[2] *result[1]};	//Mult d by t1
				intersect1[0] += p[0];															//add p
				intersect1[1] += p[1];
				intersect1[2] += p[2];
				hitMarkers.push_back(new Shape(SPHERE, 1, 1, 2, 2));
				real_scaling(hitMarkers[hitMarkers.size() - 1], 0.1, 0.1, 0.1);					//Shrink sphere
				real_translation(hitMarkers[hitMarkers.size() - 1], intersect1[0], intersect1[1], intersect1[2]);	//Move it to the intersect point
			}
			
			//If there is 2 intersections, figure out the second
			//If there was 1, dont figure out this one. t1 and t2 are the same if there is 1 intersection so using t1 above if fine
			if (result[0] == 2)
			{
				if (result[2] >= 0)		//Dont draw ones behind you
				{
					GLfloat intersect2[3] = {d[0] * result[2], d[1] * result[2], d[2] *result[2]};
					intersect2[0] += p[0];
					intersect2[1] += p[1];
					intersect2[2] += p[2];
					hitMarkers.push_back(new Shape(SPHERE, 1, 1, 10, 10));
					real_scaling(hitMarkers[hitMarkers.size() - 1], 0.1, 0.1, 0.1);
					real_translation(hitMarkers[hitMarkers.size() - 1], intersect2[0], intersect2[1], intersect2[2]);
				}
			}
		}		
	}

	glutPostRedisplay();		
}
Пример #3
0
void my_setup()
{
  int i;
  for (i = 0; i < 7; i++) {
    make_nozzle(&nozzles[i], .008, .25);
    real_scaling(&(nozzles[i].Shape), 1, .3, 1);
    real_translation(&(nozzles[i].Shape), -.78+.26*i, -.95, 0);
  }
}
Пример #4
0
void spawn_particle(int i)
{
  SHAPE cur;
  NOZZLE *cur_nozzle;

  cur_nozzle = &nozzles[i];
  make_cube_smart(&cur, .1);
  make_particle(&particles[i], colors[RED], colors[BLACK], 1, colors[RED], colors[BLACK], 0, 0, cur, 0, .05, 0);
  real_translation(&(particles[i].shape), cur_nozzle->x, cur_nozzle->y + .1, 0);
}
Пример #5
0
void parse_obj(char *buffer){
  OBJECT *po;
  char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate;



  my_assert ((num_objects < NUM_OBJECTS), "too many objects");
  po = &my_objects[num_objects++];

  pshape  = strtok(buffer, " ");
  //printf("pshape is %s\n",pshape);

  ptranslate    = strtok(NULL, "()");  strtok(NULL, "()");
  pscale        = strtok(NULL, "()");  strtok(NULL, "()"); 
  protate       = strtok(NULL, "()");  strtok(NULL, "()");  

  pshine  = strtok(NULL, "()");strtok(NULL, "()");
  //printf("pshine is %s\n",pshine);
 
  pemi    = strtok(NULL, "()");  strtok(NULL, "()"); 
  pamb    = strtok(NULL, "()");  strtok(NULL, "()"); 
  pdiff   = strtok(NULL, "()");  strtok(NULL, "()"); 
  pspec   = strtok(NULL, "()");  strtok(NULL, "()"); 


  po->sid  = atoi(pshape);
  po->shine = atof(pshine);

  parse_floats(ptranslate, po->translate);
  parse_floats(pscale, po->scale);
  parse_floats(protate, po->rotate);

  parse_floats(pemi, po->emi);
  parse_floats(pamb, po->amb);
  parse_floats(pdiff, po->diff);
  parse_floats(pspec, po->spec);

  // use switch to create your objects, cube given as example
  switch (po->sid){
  case 1: //cube
    make_cube_smart(po, 1);
    break;
  }
  
  // scale, rotate, translate using your real tranformations from assignment 3 depending on input from spec file
  
  real_scaling(po, po->scale[0], po->scale[1], po->scale[2]);  
  real_rotation(po, po->rotate[0], 1, 0, 0);
  real_rotation(po, po->rotate[1], 0, 1, 0);
  real_rotation(po, po->rotate[2], 0, 0, 1);
  real_translation(po, po->translate[0], po->translate[1], po->translate[2]);
  
  printf("read object\n");
}
Пример #6
0
void my_time_out(int id) { 
  int i, j;
  PARTICLE *cur;
  EXPLOSION *cur_explosion;
  for (i = 0; i < NUM_NOZZLES; i++) {
    cur = &particles[i];
    real_translation(&(particles[i].shape), cur->translation[0], cur->translation[1], cur->translation[2]);
  }
  for (j = 0; j < NUM_NOZZLES; j++) {
    for (i = 0; i < (&explosions[j])->quantity; i++) {
      cur_explosion = &explosions[j];
      cur = &(cur_explosion->particles[i]);
      if (cur_explosion->counter < cur_explosion->radius) {
        real_translation(&(cur->shape), cur->translation[0], cur->translation[1], cur->translation[2]);
      }
      cur_explosion->counter += 1;
    }
  }
  glutTimerFunc(timer_speed, my_time_out, 0); // keeps the timer moving, at timer_speed ms
  glutPostRedisplay();                       // re-draw the scene

}
Пример #7
0
void setup_nozzles()
{
  int i;
  GLfloat trans_x;
  GLfloat trans_y;

  for (i = 0; i < NUM_NOZZLES; i++) {
    trans_x = -1 + (float)2/(float)NUM_NOZZLES + (2 - (float)2/(float)NUM_NOZZLES)*(float)i/(float)NUM_NOZZLES;
    trans_y = -.95;
    make_nozzle(&nozzles[i], .008, .25, i + 1);
    real_scaling(&(nozzles[i].shape), 1, .3, 1);
    real_translation(&(nozzles[i].shape), trans_x, trans_y, 0);
    
    nozzles[i].x = trans_x;
    nozzles[i].y = trans_y;
  }
}
Пример #8
0
void my_setup(int argc, char **argv){

	firstPersonView = 1;
	num_objects = num_lights = 0;

	// initialize global shape defaults and mode for drawing
	crt_render_mode = GL_POLYGON;

	real_translation(player, -5, 0, 0);	
	player->isPlayer = true;

	//If you want to allow the user to type in the spec file
	//then modify the following code.
	//Otherwise, the program will attempt to load the file as specified
	//on the command line:
	//EX: ./glmain spec3
	my_assert(argc >1, "need to supply a spec file");
	read_spec(argv[1]);

	return;
}
Пример #9
0
// quantity needs to be a square number
void make_explosion(EXPLOSION *po, GLfloat radius, GLfloat density, 
                          int quantity, GLfloat cube_size, int after_counter,
                          short shape, SOUND sound, GLfloat start_x, GLfloat start_y) {
  int i, j, k;
  int count = 0;
  short solid = rand()%5;
  GLfloat color[3];
  GLfloat other_color[3];
  
  if(shape ==0){
  		solid =2;
  }
  if(solid){
  		for(i=0;i<3;++i){
  			color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  		}
  		
  		if(solid<3){
  			other_color[0] =color[0];
  			other_color[1] = color[1];
  			other_color[2] = color[2];
  		}
  		else{
  			for(i=0;i<3;++i){
  				other_color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  			}
  		}
  }
  
  else{
  	 	for(i=0;i<3;++i){
  			color[i] =0;
  		}
  
  }
  	
  SHAPE cur;
  GLfloat trans_x, trans_y, trans_z;
  GLfloat ray = cube_size;
  
  start_y +=(float)((rand() % (7)) - 3)/10.;
  start_x +=(float)((rand() % (11)) - 5)/100.;

  po -> radius = radius;
  po -> density = density;
  po -> quantity = quantity;
  po -> cube_size = cube_size;
  po -> shape = shape;
  po -> sound = sound;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;
  po -> after_counter = after_counter + radius;
  po -> fizz=0;
  po -> particles = malloc(quantity*sizeof(PARTICLE));

  k = sqrt(quantity)/2;

  // draw the top half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      


      trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/80.;
      trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/80.;
      trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/80.;
    
      make_particle(&(po->particles[i*4 + j]), color, solid, 1000, cur, trans_x, trans_y, trans_z);
      count++;
    }
  }
  // draw the bottom half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i - 180); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      
      trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/100.;;
      trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/100.;;
      trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/100.;;
    
      make_particle(&(po->particles[count - 1 + i*4 + j]), other_color, solid,1000, cur, trans_x, trans_y, trans_z);
    }
  }
}
Пример #10
0
void parse_obj(char *buffer){
	OBJECT *po;
	char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate;
	Shape *s = NULL;


	my_assert ((num_objects < NUM_OBJECTS), "too many objects");
	po = &my_objects[num_objects++];

	pshape  = strtok(buffer, " ");
	//printf("pshape is %s\n",pshape);

	ptranslate    = strtok(NULL, "()");  strtok(NULL, "()");
	pscale        = strtok(NULL, "()");  strtok(NULL, "()"); 
	protate       = strtok(NULL, "()");  strtok(NULL, "()");  

	pshine  = strtok(NULL, "()");strtok(NULL, "()");
	//printf("pshine is %s\n",pshine);

	pemi    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pamb    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pdiff   = strtok(NULL, "()");  strtok(NULL, "()"); 
	pspec   = strtok(NULL, "()");  strtok(NULL, "()"); 


	po->sid  = atoi(pshape);
	po->shine = atof(pshine);

	parse_floats(ptranslate, po->translate);
	parse_floats(pscale, po->scale);
	parse_floats(protate, po->rotate);

	parse_floats(pemi, po->emi);
	parse_floats(pamb, po->amb);
	parse_floats(pdiff, po->diff);
	parse_floats(pspec, po->spec);

	//Create the shape
	switch (po->sid)
	{
		case 1: //cube
		{
			s = new Shape(CUBE, 1, 1, 1, 1);
			break;
		}
		case 2:	//house
		{
			s = new Shape(HOUSE, 1, 1, 1, 1);
			break;
		}
		case 3:
		{
			s = new Shape(SPHERE, 1, 1, 25, 25);
			break;
		}
		case 4:
		{
			s = new Shape(CYLINDER, 1, 1, 10, 10);
			break;
		}
		case 5:
		{
			s = new Shape(CONE, 1, 1, 10, 10);
			break;
		}
		case 6:	//Torus
		{
			s = new Shape(1.2, .2, 15, 40);
			break;
		}

	}
	if (s != NULL)
		s->switchRenderMode();

	// scale, rotate, translate the shape using the struct values
	real_scaling(s, po->scale[0], po->scale[1], po->scale[2]);  
	real_rotation(s, po->rotate[0], 1, 0, 0);
	real_rotation(s, po->rotate[1], 0, 1, 0);
	real_rotation(s, po->rotate[2], 0, 0, 1);
	real_translation(s, po->translate[0], po->translate[1], po->translate[2]);
	
	//Add to list
	shapeList.push_back(s);

	printf("read object\n");
}
Пример #11
0
void my_TimeOut(int id) 
{	
	/* Camera controls
		Controls go in here so there is no delay when pressing keys to move
		It also allows us to move forward and backwards while turning
		WASD for forward/back + strafing left/right
		R/F for up/down
	*/
	if (wDown)
	{
		cam->translate(-CAM_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (aDown)
	{
		cam->translate(-CAM_MOVE_SPEED, 1, 0, 0);
		glutPostRedisplay();
	}
	if (sDown)
	{
		cam->translate(CAM_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (dDown)
	{
		cam->translate(CAM_MOVE_SPEED, 1, 0, 0);
		glutPostRedisplay();
	}
	if (rDown)	//go up
	{
		cam->pos[1] += CAM_MOVE_SPEED;
		glutPostRedisplay();
	}
	if (fDown)	//go down
	{
		cam->pos[1] -= CAM_MOVE_SPEED;
		glutPostRedisplay();		
	}

	/* Player(cone) controls
		I/K = forward/back
		J/L = turn left/right
		U/H = up/down

		For rotation, rotate the cones uvw axes with player->rotate()
		Then translate to origin, rotate by y, translate back
	*/
	if (iDown)
	{
		player->translate(PLAYER_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (jDown)	//Rotate left
	{
		GLfloat cx = player->pos[0];
		GLfloat cy = player->pos[1];
		GLfloat cz = player->pos[2];

		player->rotate(PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, -cx, -cy, -cz);
		real_rotation(player, PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, cx, cy, cz);
		glutPostRedisplay();
	}
	if (kDown)
	{
		player->translate(-PLAYER_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (lDown)	//Rotate right
	{
		GLfloat cx = player->pos[0];
		GLfloat cy = player->pos[1];
		GLfloat cz = player->pos[2];

		player->rotate(-PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, -cx, -cy, -cz);
		real_rotation(player, -PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, cx, cy, cz);
		glutPostRedisplay();
	}
	if (uDown)	//up
	{
		player->translate(PLAYER_MOVE_SPEED, 0, 1, 0);
		glutPostRedisplay();
	}
	if (hDown)	//down
	{
		player->translate(-PLAYER_MOVE_SPEED, 0, 1, 0);
		glutPostRedisplay();
	}


	/* Camera truning */
	if (turnRight)
	{
		cam->rotate(turnRightLen * .07, 0, 1, 0);	//Scale by .07, we can't rotate by num of pixels moved degrees
		turnRightLen = 0;
		glutPostRedisplay();
		turnRight = false;
		glutWarpPointer(wWidth / 2, wHeight / 2);	//Move pointer back to middle
	}
	else if (turnLeft)
	{
		cam->rotate(-turnLeftLen * .07, 0, 1, 0);
		turnLeftLen = 0;
		glutPostRedisplay();
		turnLeft = false;
		glutWarpPointer(wWidth / 2, wHeight / 2);
	}

	glutTimerFunc(20, my_TimeOut, 0);
}
Пример #12
0
/*TODO: expand to add hmwk 3 keyboard events */
void my_keyboard( unsigned char key, int x, int y ) {
  switch( key ) {
  case 'O':
  case 'o': {
    reset();
    glutPostRedisplay(); 
  }; break;


  case 'y': {
	switch( crt_transform) {
	case ROTATION_MODE: real_rotation(-2,0,1,0); break;
	case TRANSLATION_MODE: real_translation(0,-1,0); break;
	//... etc: handle real-translation, rotation, scaling
	}
    glutPostRedisplay(); 
  }; break;
  case 'Y': {
	switch( crt_transform) {
	case ROTATION_MODE: real_rotation(2,0,1,0); break;
	case TRANSLATION_MODE: real_translation(0,1,0); break;
	//... etc: handle real-translation, rotation, scaling
	}
    glutPostRedisplay(); 
  }; break;

  //etc...

  case '1': {
    crt_shape = CUBE;
    glutPostRedisplay();
  }; break;
  case '0': {
    crt_shape = HOUSE;
    glutPostRedisplay();
  }; break;
  case '3':{
    crt_shape = CYLINDER;
    glutPostRedisplay();
  }; break;
  case '4': {
    crt_shape = SPHERE;
    glutPostRedisplay();
  }; break;
  case '6': {
    crt_shape = MESH;
    glutPostRedisplay();
  }; break; 

  //etc ... EC shapes from hmwk2

  case 'S':
  case 's': {
    crt_transform = REAL_SCALING_MODE;
  }; break;

  case 'T':
  case 't': {
    crt_transform = REAL_TRANSLATION_MODE;
  }; break;

  case 'R':
  case 'r': {
    crt_transform = REAL_ROTATION_MODE;
  }; break;


 

  //add camera controls...
  //...

  //add your tessellation code from hmwk2
  case '+': {
  }; break;

  case '-': {
  }; break;

  case '>': {
  }; break;

  case '<': {
  }; break;

  case 'q': 
  case 'Q':

    exit(0) ;

    break ;	

  default: break;

  }

  

  return ;

}
Пример #13
0
void make_fuse(FUSE *po, int hangtime, GLfloat *init_color, GLfloat trans_x,
                      GLfloat trans_y, GLfloat trans_z,
                      GLfloat ray, GLfloat start_x, GLfloat start_y)
{

  int i;
  double divisor;
  PARTICLE *cur_po;
  SHAPE cur;
  GLfloat a;
  GLfloat color_changed[3];
  GLfloat color_used[3];

  for(i=0;i<3;i++){
  	 	a =(float)((rand() % (10)))/500.;
  	 	color_used[i] =a;
  
  }
  
  if(start_y==-1){
  		po->trail_size=rand() % 20 + 45;
  		divisor = 100;
  		trans_y=0;
  }
  else{
  		po->trail_size=25;
  		divisor = 500;
  		
  }
  
  for(i=0;i<3;i++){
  	 	a =(float)((rand() % (10)))/divisor;
  	 	color_used[i] =a;
  
  }
  po->trail = malloc(po->trail_size*sizeof(PARTICLE));

  for (i = 0; i < po->trail_size; i++) {
    cur_po = &(po->trail[i]);
    make_cube_smart(&cur, ray);
    real_translation(&cur, start_x, start_y + i*ray, 0);
	
    color_changed[0] = color_used[0]*i;
    color_changed[1] = color_used[1]*i;
    color_changed[2] = color_used[2]*i;
    

    make_particle(cur_po, color_changed, 1, cur, trans_x, trans_y, trans_z);

  }

  hangtime = (rand() % 20) + 15;
  
  ////FOR INTRO TEXT
  if(intro_flag_1){
  		hangtime=26;
  }
  else if(intro_flag_2){
  		hangtime=26;
  }
  else if(intro_flag_3){
  		hangtime =17;
  }
  else if(intro_flag_4){
  		hangtime =14;
  
  }

  po -> hangtime = hangtime;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;

}
Пример #14
0
void my_time_out(int id) { 
  int i, j,k;
  
  PARTICLE *cur;
  EXPLOSION *cur_explosion;
  FUSE *curr_fuse;
  GLfloat nozzle_change=0;
  float fall_time;
  fall_time =(float)((rand() % (10)))/100000.;
  
  for (j = 0; j < MAX_FIREWORKS; j++) {
    curr_fuse = &fuses[j];

    if (curr_fuse -> hangtime > 0) {


      for (i = 0; i < curr_fuse->trail_size; i++) {
        cur = &(curr_fuse -> trail[i]);
        if(curr_fuse->start_y==-1){
        	nozzle_change = (float)((rand() % (41)-20))/5000.;
          	cur->init_color[0]=cur->init_color[0]-2250*fall_time;
          	cur->init_color[1]=cur->init_color[1]-2250*fall_time;
          	cur->init_color[2]=cur->init_color[2]-2250*fall_time;
        }
        else{
        	nozzle_change=0;
        }
        real_translation(&(cur->shape), cur->translation[0]+nozzle_change, cur->translation[1], cur->translation[2]);
      }

      if (curr_fuse -> counter < curr_fuse -> hangtime) {
      	curr_fuse -> counter += 1;
      }
      else {

      	int num = rand() % (NUM_SOUNDS - 2);


      	GLfloat used_radius;
      	GLfloat used_density;
      	int used_quantity;
      	GLfloat used_cube_size;
      	int used_after_counter;
       
      	int cur_shape = rand() % (NUM_SHAPES);      //right now 2 0-regular 1-burst 2-heart**(needs 2 twice in a row 
      
      	if(cur_shape ==2){
      		cur_shape = rand() % (NUM_SHAPES); 
      	}
      

      	if(cur_shape==1){
          used_radius = reg_radius;
          used_density = reg_density;
          used_quantity = reg_quantity;
          used_after_counter = reg_after_counter;

      	}
      	else{
          used_radius = bur_radius;
          used_density = bur_density;
          used_quantity = bur_quantity;
          used_after_counter = bur_after_counter;
          BASS_ChannelSetAttribute(sounds[num], BASS_ATTRIB_VOL, 90);
        

      	}
        ////FOR INTRO TEXT
      	if(intro_flag_1){
      	  cur_shape =-1;
      
      	}
      	else if(intro_flag_2){
      	  cur_shape =-2;
      	}
      	else if(intro_flag_3){
      	  cur_shape =-3;
      	}
      	else if(intro_flag_4){
      	  cur_shape =-4;
      	}

      	GLfloat test_this_shit_out = (&(cur -> shape)) -> shape_verts[1][1][1];

      	GLfloat new_radius = (float)((rand()%41 -20)/100.)*used_radius +used_radius;
      	int new_quantity = (int)((float)(rand()%41 -20)/100.)*used_quantity +used_quantity;
      	GLfloat new_after_counter= (float)((rand()%41 -20)/100.)*used_after_counter +used_after_counter;
      	//GLfloat cur_cube_size = .007;

	  	if (curr_fuse->start_y==-1){
	  		if((cur->init_color[0])<0.1 && (cur->init_color[1]) <0.1 && (cur->init_color[2])<0.1){
	  			for(i=0;i<curr_fuse->trail_size;i++){
	  				free(&(curr_fuse -> trail[i]));
	  				
	  				curr_fuse -> hangtime= 0;
          			curr_fuse -> counter = 0;
          			curr_fuse -> trail_size = 0;
          			curr_fuse -> start_x = 0;
          			curr_fuse -> start_y = 0;
	  			}
	  			
	  		}
	  	}
	  	else{
      		if (cur_shape == 3) {
       			make_fuse(&fuses[cur_fuse = (cur_fuse + 1 ) % MAX_FIREWORKS], 5, colors[RED], .005, .005, 0, .004, curr_fuse -> start_x, test_this_shit_out);
        		make_fuse(&fuses[cur_fuse = (cur_fuse + 1 ) % MAX_FIREWORKS], 5, colors[RED], -.005, .005, 0, .004, curr_fuse -> start_x, test_this_shit_out);
        		make_fuse(&fuses[cur_fuse = (cur_fuse + 1 ) % MAX_FIREWORKS], 5, colors[RED], -.005, -.005, 0, .004, curr_fuse -> start_x, test_this_shit_out);
        		make_fuse(&fuses[cur_fuse = (cur_fuse + 1 ) % MAX_FIREWORKS], 5, colors[RED], .005, -.005, 0, .004, curr_fuse -> start_x, test_this_shit_out);
      		}
      		else {
       			make_explosion(&explosions[cur_firework = (cur_firework + 1 )% MAX_FIREWORKS], new_radius, 1, new_quantity, .007, new_after_counter, cur_shape, test_sound, curr_fuse -> start_x, test_this_shit_out, 1, 0);
        		if(cur_shape<0){
        			cur_shape=(rand()%2)+1;
        		}
        		BASS_ChannelPlay(sounds[cur_shape], TRUE);
      		}
      			curr_fuse -> hangtime = -1;
      
      	}
      }
    }




    cur_explosion = &explosions[j];
    for (i = 0; i < (&explosions[j])->quantity; i++) {
    
      cur = &(cur_explosion->particles[i]);
    
      if (cur_explosion->counter < cur_explosion->radius) {
        if (cur -> is_sparkler != 0) {
          cur -> translation[0] = (float)((rand() % (10)) - 5)/180.;
          cur -> translation[1] = (float)((rand() % (10)) - 5)/180.;
          cur -> translation[2] = (float)((rand() % (10)) - 5)/180.;
        }

        real_translation(&(cur->shape), cur->translation[0], cur->translation[1], cur->translation[2]);
      }
    
      else {
    
        if (cur_explosion->counter > cur_explosion->radius && cur_explosion->counter < cur_explosion->radius + cur_explosion->after_counter && cur_explosion -> radius > 0) {
          fall_time =(float)((rand() % (10)))/100000.;
          real_translation(&(cur->shape), 0, -fall_time*5, 0);
          cur->init_color[0]=cur->init_color[0]-250*fall_time;
          cur->init_color[1]=cur->init_color[1]-250*fall_time;
          cur->init_color[2]=cur->init_color[2]-250*fall_time;
          if(!cur_explosion->fizz){
         // 	BASS_ChannelPlay(sounds[7], TRUE);
          	cur_explosion->fizz=1;
          	
          }
          // TODO THIS IS WHERE WE WANT TO START FADING AS WELL
        }

        if (cur_explosion->counter > cur_explosion->after_counter && cur_explosion -> radius > 0) {
          cur_explosion->fizz=0;
          free(&(cur_explosion->particles[0]));


          cur_explosion -> radius = 0;
          cur_explosion -> density = 0;
          cur_explosion -> quantity = 0;
          cur_explosion -> cube_size = 0;
          cur_explosion -> shape = 0;
          cur_explosion -> counter = 0;
          cur_explosion -> start_x = 0;
          cur_explosion -> start_y = 0;
          cur_explosion -> after_counter = 0;
        }
      }  
    }
    if (cur_explosion->radius > 0) {
      cur_explosion->counter += 1;
    }
  }


  glutPostRedisplay();                       // re-draw the scene
  glutTimerFunc(timer_speed, my_time_out, 0); // keeps the timer moving, at timer_speed ms

}
Пример #15
0
// quantity needs to be a square number
void make_explosion(EXPLOSION *po, GLfloat radius, GLfloat density, 
                          int quantity, GLfloat cube_size, int after_counter,
                          short shape, SOUND sound, GLfloat start_x, GLfloat start_y,
                          short is_sparkler, short is_screamer) {
  int i, j, k;
  int count = 0;
  short solid = rand()%5;
  GLfloat color[3];
  GLfloat other_color[3];
  
  if(shape ==0){
  		solid =2;
  }
  if(solid){
  		for(i=0;i<3;++i){
  			color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  		}
  		
  		if(solid<3){
  			other_color[0] =color[0];
  			other_color[1] = color[1];
  			other_color[2] = color[2];
  		}
  		else{
  			for(i=0;i<3;++i){
  				other_color[i] =(float)((rand() % (100)))/100.;			//randomize color
  			
  			}
  		}
  }
  
  else{
  	 	for(i=0;i<3;++i){
  			color[i] =0;
  		}
  
  }
  	
  SHAPE cur;
  GLfloat trans_x, trans_y, trans_z;
  GLfloat ray = cube_size;
  
  start_x +=(float)((rand() % (11)) - 5)/100.;

  po -> radius = radius;
  po -> density = density;
  po -> quantity = quantity;
  po -> cube_size = cube_size;
  po -> shape = shape;
  po -> sound = sound;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;
  po -> after_counter = after_counter + radius;
  po -> fizz=0;
  po -> particles = malloc(quantity*sizeof(PARTICLE));


  double scale_x=.025;
  double scale_y=.025;
  if(shape==0||shape ==1){
  	  k = sqrt(quantity)/2;

	  // draw the top half
	  for (i = 0; i <= k; i++) {
		for (j = 0; j <= k; j++) {
	
		  make_cube_smart(&cur, ray);
		  real_translation(&cur, start_x, start_y, 0);
	
		  int t = (360.0/(float)(k) * j);    // theta
		  int p = (180.0/(float)(k) * i); // phi
	
		  GLfloat theta = (t * M_PI/180.); // theta angle
		  GLfloat phi = (p * M_PI/180.);  // phi angle
		  
	
	
		  trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/80.;
		  trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/80.;
		  trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/80.;
		
		  make_particle(&(po->particles[i*4 + j]), color, solid, cur, trans_x, trans_y, trans_z);
		  (&(po -> particles[i*4 + j])) -> is_sparkler = is_sparkler; 
      count++;
		}
	  }
	  // draw the bottom half
	  for (i = 0; i <= k; i++) {
		for (j = 0; j <= k; j++) {
	
		  make_cube_smart(&cur, ray);
		  real_translation(&cur, start_x, start_y, 0);
	
		  int t = (360.0/(float)(k) * j);    // theta
		  int p = (180.0/(float)(k) * i - 180); // phi
	
		  GLfloat theta = (t * M_PI/180.); // theta angle
		  GLfloat phi = (p * M_PI/180.);  // phi angle
		  
		  trans_x = ray * cos(phi) * cos(theta) + (float)((rand() % (3)) - 1)/100.;;
		  trans_y = ray * sin(phi) + (float)((rand() % (3)) - 1)/100.;;
		  trans_z = -ray * cos(phi) * sin(theta) + (float)((rand() % (3)) - 1)/100.;;
		
		  make_particle(&(po->particles[count - 1 + i*4 + j]), other_color, solid, cur, trans_x, trans_y, trans_z);
      (&(po -> particles[i*4 + j])) -> is_sparkler = is_sparkler; 

    }
	  }
  
  }
  else if(shape ==2){
  		
  		make_heart(po,scale_x,scale_y,0,0);
  		make_heart(po,scale_x*1.7,scale_y*1.7,1,28);
  		po->after_counter =100;
  		po->radius =20;
  }
  
  else if(shape ==-1){		  ////FOR INTRO TEXT
  		make_b(po,scale_x*4,scale_y*4,1,0);
  		make_y(po,scale_x*4,scale_y*4,1,19);
  		intro_flag_1=0;
  		po->after_counter =100;
  		po->radius =18;
  }
  else if(shape ==-2){			  ////FOR INTRO TEXT
  		make_z(po,scale_x*3,scale_y*3,1,0);
  		make_a(po,scale_x*3,scale_y*2,1,40);
  		make_c(po,scale_x*2.4,scale_y*2.4,1,58);
  		make_h(po,scale_x*3,scale_y*3,1,71);
  		intro_flag_2=0;
  		po->after_counter =100;
  		po->radius =20;
  }
  else if(shape ==-3){			  ////FOR INTRO TEXT
  
  		make_a(po,scale_x*2,scale_y*2,2,0);
  		make_n(po,scale_x*1.2,scale_y*1.2,1,18);
  		make_d(po,scale_x*2,scale_y*2,1,43);
  		intro_flag_3=0;
  		po->after_counter =100;
  		po->radius =30;
  }
  else if(shape ==-4){			  ////FOR INTRO TEXT
  		make_a(po,scale_x*2,scale_y*2,3,0);
  		make_n(po,scale_x*1.2,scale_y*1.2,0,18);
  		make_d(po,scale_x*2,scale_y*2,0,43);
  		make_y(po,scale_x*2.1,scale_y*2.1,0,65);
  		intro_flag_4=0;
  		po->after_counter =100;
  		po->radius =30;
  		
  }
  
}
Пример #16
0
// quantity needs to be a square number
void make_explosion(EXPLOSION *po, GLfloat radius, GLfloat density, 
                          int quantity, GLfloat cube_size,
                          short shape, SOUND sound, GLfloat start_x, GLfloat start_y) {
  int i, j, k;
  int count = 0;
  int count1 = 0;
  SHAPE cur;
  GLfloat trans_x, trans_y, trans_z;
  GLfloat ray = cube_size;

  po -> radius = radius;
  po -> density = density;
  po -> quantity = quantity;
  po -> cube_size = cube_size;
  po -> shape = shape;
  po -> sound = sound;
  po -> counter = 0;
  po -> start_x = start_x;
  po -> start_y = start_y;

  po -> particles = malloc(quantity*sizeof(PARTICLE));

  k = sqrt(quantity)/2;

  // draw the top half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      printf("theta is %f, phi is %f\ncos(theta) is %f, cos(phi) is %f\n\n", theta, phi, cos(theta), cos(phi));
      
      trans_x = ray * cos(phi) * cos(theta);
      trans_y = ray * sin(phi);
      trans_z = -ray * cos(phi) * sin(theta);
    
      make_particle(&(po->particles[i*4 + j]), colors[RED], colors[BLACK], 1, colors[RED],
                   colors[BLACK], 1, 1000, cur, trans_x, trans_y, trans_z);
      count++;
    }
  }
  // draw the bottom half
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {

      make_cube_smart(&cur, ray);
      real_translation(&cur, start_x, start_y, 0);

      int t = (360.0/(float)(k) * j);    // theta
      int p = (180.0/(float)(k) * i - 180); // phi

      GLfloat theta = (t * M_PI/180.); // theta angle
      GLfloat phi = (p * M_PI/180.);  // phi angle
      printf("theta is %f, phi is %f\ncos(theta) is %f, cos(phi) is %f\n\n", theta, phi, cos(theta), cos(phi));
      
      trans_x = ray * cos(phi) * cos(theta);
      trans_y = ray * sin(phi);
      trans_z = -ray * cos(phi) * sin(theta);
    
      make_particle(&(po->particles[count - 1 + i*4 + j]), colors[RED], colors[BLACK], 1, colors[RED],
                   colors[BLACK], 1, 1000, cur, trans_x, trans_y, trans_z);
      count1++;
    }
  }

  printf("Count is %d\n", count + count1 - 1);

}