示例#1
0
void display(int pnum){
	int i, j, k;
	G_rgb(0,0,0);
  G_clear();
  G_clear(1,1,1);
// printf("enter disp\n");
for(i=0;i<numpolys[pnum];i++){
	double xtemp[poly_sizes[pnum][i]], ytemp[poly_sizes[pnum][i]];
	// printf("New display\n");
	for(j=0; j<poly_sizes[pnum][i];j++){
 		xtemp[j] = x[pnum][polygons[pnum][i][j]];
 		ytemp[j] = y[pnum][polygons[pnum][i][j]];
 		// printf("X = %lf Y = %lf \n",xtemp[j],ytemp[j] );
	}
	
 	G_rgb(colors[pnum][i][0],colors[pnum][i][1],colors[pnum][i][2]);
 	G_fill_polygon(xtemp, ytemp ,poly_sizes[pnum][i]);
 	}
 	double a[3][3], b[3][3];
 	D2d_make_identity(a);
 	D2d_make_identity(b);
 	D2d_translate(a, b, -WINDOW_WIDTH/2, -WINDOW_WIDTH/2);
 	D2d_rotate(a,b, ROTATE_SPEED);
 	D2d_translate(a, b, WINDOW_WIDTH/2, WINDOW_WIDTH/2);
 	D2d_mat_mult_points(x[pnum], y[pnum], a, x[pnum], y[pnum],numpoints[pnum]);

}
示例#2
0
void display(int pnum){
	int i, j, k;
	G_rgb(0,0,0);
  G_clear();
  G_clear(1,1,1);
// printf("enter disp\n");
for(i=0;i<numpolys[pnum];i++){
	double xtemp[1000], ytemp[1000];
	// printf("New display\n");
	for(j=0; j<poly_sizes[pnum][i];j++){
 		xtemp[j] = x[pnum][polygons[pnum][i][j]];
 		ytemp[j] = y[pnum][polygons[pnum][i][j]];
 		// printf("X = %lf Y = %lf \n",xtemp[j],ytemp[j] );
	}
	int tsize = clip(xtemp,ytemp,poly_sizes[pnum][i]);
 	G_rgb(colors[pnum][i][0],colors[pnum][i][1],colors[pnum][i][2]);
 	G_fill_polygon(xtemp, ytemp ,tsize);
 	}
 	double a[3][3], b[3][3];
 	D2d_make_identity(a);
 	D2d_make_identity(b);
 	D2d_translate(a, b, -WINDOW_WIDTH/2, -WINDOW_WIDTH/2);
 	D2d_rotate(a,b, ROTATE_SPEED);
 	D2d_translate(a, b, WINDOW_WIDTH/2, WINDOW_WIDTH/2);
 	
 	D2d_mat_mult_points(x[pnum], y[pnum], a, x[pnum], y[pnum],numpoints[pnum]);

for(i=0; i<cSize;i++){//show clipping box
	G_rgb(255,255,255);
	G_line(cx[i], cy[i], cx[(i+1)%cSize], cy[(i+1)%cSize]);
}

}
示例#3
0
int main()
{

  G_init_graphics(600,600) ;

  G_rgb(0,0,0) ;
  G_clear() ;

  G_rgb(0,0,1) ;
  G_fill_polygon(jx,jy,5) ;
  G_wait_key();
  double rot45[3][3];
  double useless[3][3];
  D2d_make_identity(rot45);
  D2d_rotate(rot45, useless, M_PI/4.0);
  D2d_mat_mult_points(jx, jy, rot45, jx, jy, 5);
  G_fill_polygon(jx, jy, 5);
  double upandover[3][3];
  D2d_make_identity(upandover);
  D2d_translate(upandover, useless, 1, 1);
  int count = 0;
  while (G_wait_key()) {
    count = (count+1)%200;

    D2d_mat_mult_points(jx, jy, upandover, jx, jy, 5);
    G_rgb(0, 0, 0);
    G_clear();
    G_rgb(0, 0, 1);
    if (count < 100) {
        G_fill_polygon(jx, jy, 5);
    } else {
        G_fill_polygon(jy, jx, 5);
    }
    G_rgb(1, 0, 0);
    G_line(0, 0, 600, 600);
  }
}
示例#4
0
void scaleNfit(int argc){
int i,j;
double scale[3][3] ,iscale[3][3];
for(i=0; i<argc-1;i++){
	double xmax, xmin, ymax, ymin, xrad, yrad, xcenter, ycenter;
			xmin = x[i][0];
			xmax = x[i][0];
			ymin = y[i][0];
			ymax = y[i][0];
	for(j = 0; j<numpoints[i];j++){
		if(x[i][j] < xmin){
			xmin = x[i][j];
		}
		if(x[i][j] > xmax){
			xmax = x[i][j];
		}
		if(y[i][j] < ymin){
			ymin = y[i][j];
		}
		if(y[i][j] > ymax){
			ymax = y[i][j];
		}
	}
	xrad = (xmax - xmin)/2;
	 // printf("xmax = %lf xmin = %lf \n",xmax, xmin );
	yrad = (ymax - ymin)/2;
	 // printf("ymax = %lf ymin = %lf \n",ymax, ymin );
	xcenter = xmax - xrad;
	ycenter = ymax - yrad;
	// printf("Xcenter = %lf Ycenter = %lf \n", xcenter, ycenter);
	double s;
	if(xrad > yrad){
		s = xrad;
	}else{
		s=yrad;
	}
	s = (WINDOW_WIDTH/2)/s;
	D2d_make_identity(scale);
	D2d_make_identity(iscale);
	D2d_translate(scale, iscale, -xcenter, -ycenter);
	D2d_scale(scale, iscale,s,s);
	D2d_translate(scale, iscale, WINDOW_WIDTH/2, WINDOW_WIDTH/2);
	D2d_mat_mult_points(x[i],y[i],scale,x[i],y[i], numpoints[i]);
}
}
示例#5
0
int main(int argc, char **argv){
  char t;
  int i;
  int j, k;
  double minx[10], miny[10], maxx[10], maxy[10];
  
  
  FILE *f;
  
  int numObjects = argc-1;
  
  for(thisObj=0; thisObj < numObjects; thisObj++){
    
    f=fopen(argv[thisObj+1], "r");
    if(f==NULL){
      printf("Can't open file"); exit(1);
    }
    
 
    fscanf(f, "%d", &numPoints[thisObj]);
    
    
    
    for(i=0;i<numPoints[thisObj];i++){
      
      fscanf(f, "%lf %lf", &xp[thisObj][i], &yp[thisObj][i]);
      
    }
    
    
    
    fscanf(f, "%d", &numPolygons[thisObj]);
    
    
    
    
    for(i=0;i<numPolygons[thisObj];i++){
      
      fscanf(f, "%d", &shapes[thisObj][i][0]);
      
      for(j=1;j<=shapes[thisObj][i][0];j++){
	fscanf(f, "%d", &shapes[thisObj][i][j]);
	
      }
      
    }
    
    for(i=0;i<numPolygons[thisObj]; i++){
      
      fscanf(f, "%lf %lf %lf", &r[thisObj][i], &g[thisObj][i], &b[thisObj][i]);
      
    }
 

    //printf("heelo01\n") ;
   
    minx[thisObj] = xp[thisObj][0], miny[thisObj] = yp[thisObj][0],maxx[thisObj] = xp[thisObj][0], maxy[thisObj] = yp[thisObj][0];
    //find min x
    for(i=0;i<numPoints[thisObj]; i++){
      
      if(xp[thisObj][i]<minx[thisObj]){minx[thisObj] = xp[thisObj][i];}
      if(xp[thisObj][i]>maxx[thisObj]){maxx[thisObj] = xp[thisObj][i];}
      if(yp[thisObj][i]<miny[thisObj]){miny[thisObj] = yp[thisObj][i];}
      if(yp[thisObj][i]>maxy[thisObj]){maxy[thisObj] = yp[thisObj][i];}
    }
    
    
    
    vertc[thisObj] = (maxy[thisObj] + miny[thisObj])/2;
    horzc[thisObj] = (maxx[thisObj] + minx[thisObj])/2;
    

    double sf ; 
    if(maxy[thisObj]-miny[thisObj]>maxx[thisObj]-minx[thisObj]){
       sf = 550/(maxy[thisObj]-miny[thisObj]) ;
    }else {
       sf = 550/(maxx[thisObj]-minx[thisObj]) ;
    }


    D2d_make_identity(m);
    D2d_make_identity(minv);
    D2d_translate(m,minv, -horzc[thisObj],-vertc[thisObj]); 
    D2d_scale(m,minv, sf,sf) ;
    D2d_translate(m,minv, 300,300) ;
    D2d_mat_mult_points( xp[thisObj],yp[thisObj], 
                         m, 
                         xp[thisObj],yp[thisObj],numPoints[thisObj]) ;

    horzc[thisObj]=300; vertc[thisObj] = 300;

  } // end for thisObj



  thisObj = 0;
 

  G_init_graphics(600,600);
 
  redraw();
  
  buildClipWindow();
  
  redraw();

  D2d_make_identity(m);
  D2d_make_identity(minv);
  D2d_translate(m,minv, -300,-300) ;  
  D2d_rotate(m,minv, 3*M_PI/180) ;
  D2d_translate(m,minv,  300, 300) ;  

  while(1){

    t = G_wait_key();

    if(t>='0' && t<='9'){
      thisObj = t-'0';
    }


    D2d_mat_mult_points(xp[thisObj], yp[thisObj],
                        m, 
                        xp[thisObj], yp[thisObj], numPoints[thisObj]);

    redraw();

  }

}