static void draw_line(void) { double *x, *y; int max; // int num; // unreferenced int i, j, k, l; int p; max = (patt.v_num > patt.h_num)? patt.v_num: patt.h_num; x = (double *)malloc( sizeof(double)*max ); y = (double *)malloc( sizeof(double)*max ); if( x == NULL || y == NULL ) exit(0); i = check_num; for( j = 0; j < patt.v_num; j++ ) { for( k = 0; k < patt.h_num; k++ ) { x[k] = patt.point[i][j*patt.h_num+k].x_coord; y[k] = patt.point[i][j*patt.h_num+k].y_coord; } draw_line2( x, y, patt.h_num ); } for( j = 0; j < patt.h_num; j++ ) { for( k = 0; k < patt.v_num; k++ ) { x[k] = patt.point[i][k*patt.h_num+j].x_coord; y[k] = patt.point[i][k*patt.h_num+j].y_coord; } draw_line2( x, y, patt.v_num ); } for( j = 3 - patt.v_num; j < patt.h_num - 2; j++ ) { p = 0; for( k = 0; k < patt.v_num; k++ ) { l = j+k; if( l < 0 || l >= patt.h_num ) continue; x[p] = patt.point[i][k*patt.h_num+l].x_coord; y[p] = patt.point[i][k*patt.h_num+l].y_coord; p++; } draw_line2( x, y, p ); } for( j = 2; j < patt.h_num + patt.v_num - 3; j++ ) { p = 0; for( k = 0; k < patt.v_num; k++ ) { l = j-k; if( l < 0 || l >= patt.h_num ) continue; x[p] = patt.point[i][k*patt.h_num+l].x_coord; y[p] = patt.point[i][k*patt.h_num+l].y_coord; p++; } draw_line2( x, y, p ); } free( x ); free( y ); }
void draw_world() { world_z = world.height+25; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glTranslatef(0.0f, 0.0f, -world_z); int i,j,k; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int c = 0; draw_box(world.width,world.height); glColor3f(color[c].r,color[c].g,color[c].b); for(i=0; i<num_projectors; i++) { if(select_type == PROJECTOR && select_number == i) draw_selected_line(projector[i].l); else draw_line(projector[i].l); draw_point(projector[i].d); glColor3f(color[c].r,color[c].g,color[c].b); } c++; glColor3f(color[c].r,color[c].g,color[c].b); for(i=0; i<num_mirrors; i++) { if(select_type == MIRROR && select_number == i) draw_selected_line(mirror[i].l); else draw_line(mirror[i].l); glColor3f(color[c].r,color[c].g,color[c].b); } c++; glColor3f(color[c].r,color[c].g,color[c].b); for(i=0; i<num_blocks; i++) { if(select_type == BLOCK && select_number == i) draw_selected_line(block[i].l); else draw_line(block[i].l); glColor3f(color[c].r,color[c].g,color[c].b); } /*for(i=0; i<num_projectors; i++) { for(j=0; j<projector[i].num_pixels; j++) draw_line(projector[i].pixels[j]); draw_point(projector[i].d); }*/ for(i=0; i<num_projectors; i++) { for(j=0; j<projector[i].num_pixels; j++) { glColor3f(color[c].r,color[c].g,color[c++].b); point p,fp; float dist = INF; int type = 1,num; for(k=0; k<num_mirrors; k++) { p = find_intersection(mirror[k].l,projector[i].pixels[j]); if( (abs(p.x) <= world.width/2) && (abs(p.y) <= world.height/2) && check_point_on_line_segment(mirror[k].l,p) ) if(find_side(projector[i].l.p1,projector[i].l.p2,p) == -1) { float d = distance_between_points(p,projector[i].pixels[j].p1); if( d < dist ) { fp = p; dist = d; type = 1; num = k; if(find_side(mirror[k].l.p1,mirror[k].l.p2,projector[i].pixels[j].p1) == -1) type = 2; } } } for(k=0; k<num_blocks; k++) { p = find_intersection(block[k].l,projector[i].pixels[j]); if(abs(p.x) <= world.width/2 && abs(p.y) <= world.height/2 && check_point_on_line_segment(block[k].l,p)) if(find_side(projector[i].l.p1,projector[i].l.p2,p) == -1) { float d = distance_between_points(p,projector[i].pixels[j].p1); if( d < dist ) { fp = p; dist = d; type = 2; } } } for(k=0; k<num_world; k++) { p = find_intersection(world.l[k],projector[i].pixels[j]); if(abs(p.x) <= world.width/2 && abs(p.y) <= world.height/2 && check_point_on_line_segment(world.l[k],p)) if(find_side(projector[i].l.p1,projector[i].l.p2,p) == -1) { float d = distance_between_points(p,projector[i].pixels[j].p1); if( d < dist ) { fp = p; dist = d; type = 2; } } } for(k=0; k<num_projectors; k++) { if(k!=i) { p = find_intersection(projector[k].l,projector[i].pixels[j]); if(abs(p.x) <= world.width/2 && abs(p.y) <= world.height/2 && check_point_on_line_segment(projector[k].l,p)) if(find_side(projector[i].l.p1,projector[i].l.p2,p) == -1) { float d = distance_between_points(p,projector[i].pixels[j].p1); if( d < dist ) { fp = p; dist = d; type = 2; } } } } draw_line2(fp,projector[i].pixels[j].p2); if(type==1) { //float angle = find_angle(projector[i].pixels[j],mirror[num].l); //float angle = find_angle2(projector[i].pixels[j].p1,fp,mirror[num].l.p1,mirror[num].l.p2); line n; n.p1 = fp; n.m = tan(PI + 2*atan(mirror[num].l.m) - atan(projector[i].pixels[j].m)); n.c = n.p1.y - n.p1.x*n.m; draw_reflections(n,num,1); } } } //glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); //glPushMatrix(); //glTranslatef(0.0f, 0.0f, -5.0f); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //glRotatef(rot,1,2,0); //glRasterPos2f(-0.5,0); //glColor4f(0.0f, 1.0f, 1.0f,1.0f); //glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, "Rishi Raj Singh Jhelumi"); //glBegin(GL_POINTS); //glVertex3f(0,0,-world_z); //glEnd(); //glPopMatrix(); glFlush(); //glutSwapBuffers(); }
void draw_reflections(line l,int m,int side) { int i,j,k; point p,fp; float dist = INF; int type = 1,num; for(k=0; k<num_mirrors; k++) { if(k!=m) { p = find_intersection(mirror[k].l,l); if( (abs(p.x) <= world.width/2) && (abs(p.y) <= world.height/2) && check_point_on_line_segment(mirror[k].l,p) ) if(find_side(mirror[m].l.p1,mirror[m].l.p2,p) == side) { float d = distance_between_points(p,l.p1); if( d < dist ) { fp = p; dist = d; type = 1; num = k; if(find_side(mirror[k].l.p1,mirror[k].l.p2,l.p1) == -1) type = 2; } } } } for(k=0; k<num_blocks; k++) { p = find_intersection(block[k].l,l); if(abs(p.x) <= world.width/2 && abs(p.y) <= world.height/2 && check_point_on_line_segment(block[k].l,p)) if(find_side(mirror[m].l.p1,mirror[m].l.p2,p) == side) { float d = distance_between_points(p,l.p1); if( d < dist ) { fp = p; dist = d; type = 2; } } } for(k=0; k<num_world; k++) { p = find_intersection(world.l[k],l); if(abs(p.x) <= world.width/2 && abs(p.y) <= world.height/2 && check_point_on_line_segment(world.l[k],p)) if(find_side(mirror[m].l.p1,mirror[m].l.p2,p) == side) { float d = distance_between_points(p,l.p1); if( d < dist ) { fp = p; dist = d; type = 2; } } } for(k=0; k<num_projectors; k++) { p = find_intersection(projector[k].l,l); if(abs(p.x) <= world.width/2 && abs(p.y) <= world.height/2 && check_point_on_line_segment(projector[k].l,p)) if(find_side(mirror[m].l.p1,mirror[m].l.p2,p) == side) { float d = distance_between_points(p,l.p1); if( d < dist ) { fp = p; dist = d; type = 2; } } } draw_line2(fp,l.p1); if(type==1) { //float angle = find_angle(l,mirror[m].l); line n; n.p1 = fp; n.m = tan(PI + 2*atan(mirror[num].l.m) - atan(l.m)); n.c = n.p1.y - n.p1.x*n.m; draw_reflections(n,num,1); } }