コード例 #1
0
void make_shape(Shape *vert)
{
	
    double	ray = 1; // radius
	int height = 1; // height
	double torus_radius = 1.2; // radius from origin to center of tube
	double tube_radius = 0.2; // tube radius
	GLfloat p0[3] = {0,0,0};
	GLfloat p1[3] = {0,1,0};
	theLine.type = LINE;
	
	float l1 = 1.0;
	float l2 = 0.75;
	float l3 = 0.50;
	
	switch(vert->type)
	{
		case HOUSE:
			make_house(vert);break;
		case SPHERE:
			make_sphere(vert, ray); break;
		case CYLINDER:
			make_cylinder(vert, ray, height); break;
		case CONE:
			make_cone(vert, height, ray); break;
		case TORUS:
			make_torus(vert,torus_radius, tube_radius); break;
		case CUBE:
			make_cube_smart(vert, 2); break;
		case LINE:
			make_line(vert, p0, p1);
		case SUPER:
			make_quadric(vert, l1, l2, l3);
	}	
}
コード例 #2
0
ファイル: fireworks-13.c プロジェクト: Choino/school
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);
}
コード例 #3
0
ファイル: glmain.c プロジェクト: Choino/school
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");
}
コード例 #4
0
ファイル: glmain.c プロジェクト: Choino/school
/*TODO add make_cone, make_torus, make_your_shape etc.   */
void my_setup(){
  crt_render_mode = GL_POLYGON;//GL_LINE_LOOP;
  crt_shape = HOUSE;
  crt_transform = NONE_MODE;
  crt_rs = 20;
  crt_vs = 10;
  make_cube_smart(1);
  make_cylinder(cyl_height,cyl_ray,crt_rs,crt_vs);
  make_sphere(sph_ray,crt_rs,crt_vs);
  return;

}
コード例 #5
0
ファイル: fireworks-24.c プロジェクト: Zaxcoding/fireworks
// 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);
    }
  }
}
コード例 #6
0
ファイル: fireworks-30.c プロジェクト: Choino/school
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;

}
コード例 #7
0
ファイル: fireworks-30.c プロジェクト: Choino/school
// 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;
  		
  }
  
}
コード例 #8
0
ファイル: fireworks-13.c プロジェクト: Choino/school
// 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);

}