// 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]; printf("EXPLOSION CREATED!\n\n"); 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 == BOOM || shape == REGULAR || shape == SPARKLER || shape == WILLOW){ 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); if (shape == SPARKLER) { (&(po -> particles[i*4 + j])) -> is_sparkler = 1; } if (shape == WILLOW) { (&(po -> particles[i*4 + j])) -> is_willow = 1; } 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); if (shape == SPARKLER) { (&(po -> particles[count - 1 + i*4 + j])) -> is_sparkler = 1; } if (shape == WILLOW) { (&(po -> particles[count - 1 + i*4 + j])) -> is_willow = 1; } } } } 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 ==TRIFORCE){ make_tri(po,scale_x*2,scale_y*2,0,0); po->after_counter =100; po->radius =20; } else if(shape ==MUSHROOM){ make_shroom(po,scale_x*1.2,scale_y*1.2,0,0); po->after_counter =100; po->radius =20; } else if(shape ==ONE_UP){ make_shroom(po,scale_x*1.2,scale_y*1.2,1,0); 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; } }
// ------------------------------------------------------------------- // main function: // Compute the surface envelope // void EncQuadBezier::compute_enclosure() { //int tr[4][4][2]; // translation from xy to ccw int need_subdiv; // allocate the memory storing the results o_enc = alloc_mem_db(d1*d1*DIM); i_enc = alloc_mem_db(d1*d1*DIM); cralong = (int *) allocate (sizeof (int) * segu*segv ); // compute the bilinear envelope make_env(); // determine the support points and normals make_sup(); // average normals along the boundary between two neighboring // patch. (there is no affect for C1 surfaces) // //average_nor_PN(fp, sup_nor[fc], tr); // temp hack!!: use PN average Norm // compute and store intersection lambdas in w's need_subdiv = make_lam(); #ifdef FIX_BY_SUBDIVIDE if(need_subdiv) { int sizeu = dg*2+1; // int sizev = dg*2+1; // REAL bb[sizeu*sizev][DIM]; // space for subdivision // subdivide the patch for(i=0;i<d1;i++) { for(j=0;j<d1;j++) { Vcopy( get_bb[i][j], bb[(i*2)*sizev+(j*2)]); } } RSubDiv(bb, 2, dg, dg, sizeu-1, sizev-1); /* for(i=0;i<sizeu;i++) for(j=0;j<sizev;j++) { printf("v: %f %f %f \n", bb[i*sizev+j][0], bb[i*sizev+j][1], bb[i*sizev+j][2]); } */ // si and sj are the starting (i,j) position for subpatches for(si = 0; si<=dg; si+=dg) for(sj = 0; sj<=dg; sj+=dg) { int sub_fc; // where to place this new subdivied patch // use the first subdivided patch to overwrite // the original patch if(si==0 && sj==0) sub_fc = fc; else { sub_fc = new_patch(FNum, Face, fc); FNum++; printf("Add a new face %d, now %d faces\n", sub_fc, FNum); } for(i=0;i<d1;i++) for(j=0;j<d1;j++) Vcopy(bb[(i+si)*sizev+(j+sj)], &(Face[sub_fc].buf[(i*d1+j)*DIM])); } // increase number of patches by 3 object[index].patch_num +=3; fc --; // move back one spot to recompute the subdivided one printf("fc = %d\n", fc); // add four patches into the array // disable the current patch (quick way to delete) } #endif // this should after global lambda fix make_tri(); enc_computed = true; }