Exemplo n.º 1
0
int main()
{
  double xp[1000],yp[1000] ;
  int n,q ;
  double P[2] ;


  swidth = 700 ; sheight = 700 ;
  G_init_graphics(swidth, sheight) ;
  G_rgb(0,0,0) ;
  G_clear() ;

  G_rgb(1,0,0) ;
  n = click_and_save(xp,yp) ;
  G_rgb(0,1,0) ;
  G_fill_polygon(xp,yp,n) ;
while(1==1){
  G_wait_click(P) ;
  if(P[1] < 40){
    break;
  }
  int r = in_out(xp,yp,n,P);
  if(r==1){
    G_rgb(1,0,0);
  }else{
  G_rgb(0,0,1) ;
}
  G_fill_circle(P[0],P[1],2) ;
}

  q = G_wait_key() ;
}
Exemplo n.º 2
0
Arquivo: ifsS.c Projeto: 9Life42/cs
int main() 
{
 double j,r,q ;

 size = 600 ;
 G_init_graphics(size, size) ;
 G_rgb(0, 0, 0) ;
 G_clear() ;

 G_rgb(1.0, 0.0, 0.0) ;

 j = 0 ;
 while (j < 500000) {

   r = drand48() ;

   // diagonal_line(r) ;
     filled_triangle(r) ;

   G_point (x[0], y[0]) ;

   j=j+1 ;
 }

 q = G_wait_key() ;

}
Exemplo n.º 3
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]);
}

}
Exemplo n.º 4
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]);

}
Exemplo n.º 5
0
void draw() {
    G_rgb(.1, .1, .1);
    G_clear();
    draw_object3ds(objs, num_objs, fov, light_pos, lm);
    //printf("draw\n");
    char fovstring[128];
    sprintf(fovstring, "Fov: %.3f rad", fov);
    char camerastring[128];
    sprintf(camerastring, "Camera: x:0 y:0 z:%f", 0.0);
    G_rgb(1, 1, 1);
    G_draw_string(fovstring, 0, 580);
    G_draw_string(camerastring, 0, 560);
    G_display_image();
}
Exemplo n.º 6
0
void drawit(int i) {
    int k, j;
    double tempx[points[i]], tempy[points[i]];
    double plane_x[points[i]], plane_y[points[i]], plane_z[points[i]];
    double mod = (HEIGHT / 2) / tan(halfangle * (M_PI / 180));
    for (k = 0; k < polys[i]; k++) {
        j = 0;

        while (j < shapes[i][k]) {
            // printf("%d", shapeorder[i][k][j]);
            if (fabs(z[i][shapeorder[i][k][j]]) > 10e-7) { //Checks if z == 0
                tempx[j] = mod * (x[i][shapeorder[i][k][j]] /
                                  z[i][shapeorder[i][k][j]]) + (WIDTH / 2);
                tempy[j] = mod * (y[i][shapeorder[i][k][j]] /
                                  z[i][shapeorder[i][k][j]]) + (HEIGHT / 2);

                plane_x[j] = x[i][shapeorder[i][k][j]];
                plane_y[j] = y[i][shapeorder[i][k][j]];
                plane_z[j] = z[i][shapeorder[i][k][j]];
                j++;
            } else {
                j++;
            }
        }
        if (check_if_behind(plane_x, plane_y, plane_z, j) == 1) {
            G_rgb(1, 0, .3);
            G_polygon(tempx, tempy, j);
        }
    }
}
Exemplo n.º 7
0
int main()
{
  double swidth, sheight ;
  double i,x,y ;
  double z[2] ;

  swidth = 600 ; sheight = 600 ;
  G_init_graphics(swidth, sheight);


  i = 0;
  while(i<600){
  G_rgb(0,0,1) ;
  G_line (i, 0, i, 599) ;
  G_line(0,i,599,i) ;
  i=i+10 ;
  }

  i=0;
  while(i<10){
  G_wait_click(z) ;
  x = z[0] ; y = z[1] ;
  x=x-fmod(x,10);
  y=y-fmod(y,10);
  G_fill_rectangle(x, y ,10,10);
  i++;
}

  G_wait_key();
}
int main(){
  int x;
  G_init_graphics(600,600);
  int i;
  char prefix[100], filename[100];
  strncpy(prefix, "tetrahedron", 100);
  scanf("%s", textureName);

  //tetrahedron0000
  //14
  for(i=0; i < 73; i++){
    printf("%d\n", i);
    init_scene(i);
    sprintf(filename, "%s%04d", prefix, i);
    filename[15] = '.';
    filename[16] = 'x';
    filename[17] = 'w';
    filename[18] = 'd';
    G_save_image_to_file(filename);
    G_wait_key();
    G_rgb(1,1,1);
    G_clear();
  }
//main->init scene->draw
}
Exemplo n.º 9
0
int main (int argc, char **argv)
{
  int w,h,nrows, ncols ;
  double r[2],g[2],b[2] ;
  int i,j,k,q ;
  double dx,dy ;

  if (argc != 12) {
    printf("Usage : pgm  xwd_res_file_name  width height nrows ncols r0 g0 b0 r1 g1 b1\n") ;
    exit(0) ;
  }
  
  w = atoi(argv[2]) ;
  h = atoi(argv[3]) ;
  nrows = atoi(argv[4]) ;
  ncols = atoi(argv[5]) ;
  r[0] = atof(argv[6]) ;
  g[0] = atof(argv[7]) ;
  b[0] = atof(argv[8]) ;

  r[1] = atof(argv[9]) ;
  g[1] = atof(argv[10]) ;
  b[1] = atof(argv[11]) ;


  G_init_graphics(w,h) ;
  G_rgb(0,1,0) ;
  G_clear() ; 
  // reveals a green bottom line...error in FPT's G_fill_rectangle
  // ...now fixed

  dx = 1.0*w/ncols ;
  dy = 1.0*h/nrows ;

  for (i = 0 ; i < ncols ; i++) {
    for (j = 0 ; j < nrows ; j++) {
      k = (i + j) % 2 ;
      G_rgb(r[k],g[k],b[k]) ;
      G_fill_rectangle(i*dx,j*dy,dx,dy) ;
    }
  }

  q = G_wait_key() ;

  G_save_image_to_file(argv[1]) ;

}
void drawobject(int textureFlag, double eye[3], double halfAngle, double light[3], double view[4][4], double inherentRGB[3], double manMatrix[4][4], int (*func)(double u, double v, double p[3])){

  double p[3] , q[3], r[3], n[3], xBar, yBar, tanHalf, tempP[3];
  tanHalf = tan(halfAngle*(M_PI/180));
  double actualRGB[3], tempX, tempY;
  double i, j, e, width, height;

  int textureMap, d[2];
  if( textureFlag == 1){
    textureMap = init_xwd_map_from_file(textureName);
    if(textureMap == -1){ printf("failure\n"); }
    e = get_xwd_map_dimensions(textureMap, d);
    if(e == -1){ printf("failure2\n");}
    width = d[0]; height = d[1];
    printf("width: %lf, height: %lf\n", width, height);
  }
  for(i=0; i<2*M_PI; i+=.001){
    for(j=-1; j<1; j+=.001){
        func(i, j, p);
        D3d_mat_mult_pt(p, manMatrix, p);
        tempP[0] = p[0];
        tempP[1] = p[1];
        tempP[2] = p[2];
        D3d_mat_mult_pt(tempP, view, tempP);
        if(tempP[2] < 0) continue;
        else if(fabs(tempP[1]/tempP[2]) > tanHalf) continue;
        else if(fabs(tempP[0]/tempP[2]) > tanHalf) continue;
        light_in_eye_space[0] = light[0] ;
        light_in_eye_space[1] = light[1] ;
        light_in_eye_space[2] = light[2] ;
        //light model stuff
        func(i+.01, j, q);
        func(i, j+.01, r);
        D3d_mat_mult_pt(q, manMatrix, q);
        D3d_mat_mult_pt(r, manMatrix, r);
        q[0] = q[0]-p[0]; q[1] = q[1]-p[1]; q[2] = q[2]-p[2];
        r[0] = r[0]-p[0]; r[1] = r[1]-p[1]; r[2] = r[2]-p[2];
        crossProduct(r, q, n);

        if(textureFlag == 1){
          e = get_xwd_map_color(textureMap, (int)xBar, (int)yBar, inherentRGB);
          if(e==-1){ printf("failure3\n");}
        }

        Light_Model(inherentRGB, eye, p, n, actualRGB);
        G_rgb(actualRGB[0], actualRGB[1], actualRGB[2]);

        D3d_mat_mult_pt(p, view, p);
        xBar = ((300*p[0])/(tanHalf*p[2]))+300;
        yBar = ((300*p[1])/(tanHalf*p[2]))+300;
        //checking the z_Buffer
        if(z_Buffer[(int)xBar][(int)yBar] > p[2]){
          z_Buffer[(int)xBar][(int)yBar] = p[2];
          G_point(xBar, yBar);
        }
      }
    }
}
Exemplo n.º 11
0
int main() 
{
 double j ;
 char q ;

 G_init_graphics(601, 601) ;

 // the original design was for a 400x400
 // window and the object is centered on 200,200
 // so we recenter it and make it larger
 translate(-200, -200) ;
 scale(2.0) ;
 translate(300, 300) ;


 j = 0 ;
 while (j < 100) {

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

   G_rgb(0, 0.5, 1) ;
   G_fill_polygon(x,y,n) ;

   G_rgb(1, 1, 0) ;
   G_polygon(x,y,n) ;

   //   q = G_wait_key() ;
   G_display_image() ;
   usleep(25000) ;  // microseconds 
   
   translate(-300, -300) ;
   scale(0.95) ;
   rotate(4) ;
   translate(300, 300) ;

   j=j+1 ;
 }

 G_rgb(1,0,0) ;
 G_fill_circle(300,300, 50) ;

 q = G_wait_key() ;

}
Exemplo n.º 12
0
int main(){
  double ax[100], ay[100], bx[100], by[100];
  int anum, bnum;
  G_init_graphics(WINDOW,WINDOW);
  G_rgb(0,0,0);
  G_clear();
  G_clear(1,1,1);
  G_rgb(1,1,1);
  G_draw_string("Save", 0,585);
  G_rgb(0,1,0);
  anum = clickandsave(ax,ay);
  my_fill_polygon(ax, ay, anum);
  G_rgb(1,0,0);
  bnum = clickandsave(bx, by);
//printf("anum: %d bnum %d \n", anum, bnum);
  my_fill_polygon(bx,by,bnum);
 
G_wait_key();
   }
Exemplo n.º 13
0
int main()
// this tests clipping of polygon to convex window
//prefix -p == polygon; prefix -w == window
{
  int pn, wn ;
  double pt[2], u, v, q ;

  double px[100] = {  70, 460, 400} ;
  double py[100] = { 350, 25, 550} ;
  pn = 3 ;

  double wx[100] = { 100, 600, 550, 150} ;
  double wy[100] = { 150, 200, 450, 500} ;
  wn = 4 ;

  srand48(100) ;

  G_init_graphics (700, 700) ;
  G_rgb (0, 0, 0) ;
  G_clear() ;

  G_rgb (1, 0, 0) ;
  G_polygon(wx, wy, wn) ;

  G_rgb (0, 0, 1) ;
  G_polygon(px, py, pn) ;


  q = G_wait_key() ;

  pn = Clip_Polygon_Against_Convex_Window (px, py, pn, wx, wy, wn) ;

  G_rgb (1, 1, 0) ;
  for (int i = 0; i < pn; i++) {
    G_fill_circle(px[i], py[i], 2);
    printf("x:%.2lf, y:%.2lf\n", px[i], py[i]);
  }

  G_fill_polygon(px, py, pn) ;
  q = G_wait_key() ;
}
Exemplo n.º 14
0
Arquivo: stickS.c Projeto: 9Life42/cs
int main() 
{
  int q ;

  G_init_graphics(601, 601) ;

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

  G_rgb(0,0,1) ;
  G_fill_polygon(x,y,n) ;
  q = G_wait_key() ;

  translate(150, 50) ;


  G_rgb(1,0,1) ;
  G_fill_polygon(x,y,n) ;
  q = G_wait_key() ;

}
Exemplo n.º 15
0
int main ()
{
  char prefix[100], sequence_name[100] ;
  int s,e,i ;
  double f ;


  printf("enter prefix name ") ;
  scanf("%s",prefix) ;

  printf("enter starting integer ") ;
  scanf("%d",&s) ;

  printf("enter ending integer ") ;
  scanf("%d",&e) ;

  /*
  printf("\n") ;
  for (i = s ; i <= e ; i++) {
    sprintf(sequence_name, "%s%04d.xwd", prefix, i) ;
    printf("%s\n",sequence_name) ;
  }
  */


  G_init_graphics(400,400) ;

  for (i = s ; i <= e ; i++) {
    G_rgb(0,0,0) ;
    G_clear() ;
    f = 1.0*i/(e - s + 1) ;
    G_rgb(1,f,0) ;
    G_fill_circle(200,200,i) ;
    sprintf(sequence_name, "%s%04d.xwd", prefix, i) ;
    G_save_image_to_file(sequence_name) ;
  }

  G_close() ;

}
Exemplo n.º 16
0
int click_and_save (double *x, double *y)
{
  int n ;
  double P[2] ;

  G_rgb(0,1,0.5) ;
  G_fill_rectangle(0,0,swidth,20) ;

  G_rgb(1,0,0) ;
  G_wait_click(P);

  n = 0 ;
  while (P[1] > 20) {
    x[n] = P[0] ;
    y[n] = P[1] ;
    G_circle(x[n],y[n],2) ;
    if (n > 0) { G_line(x[n-1],y[n-1], x[n],y[n]) ;}
    n++ ;
    G_wait_click(P) ;
  }

  return n ;
}
Exemplo n.º 17
0
    void mypolygon(double x[], double y[], int length ){
    int i;
G_rgb(1,1,1);
    for(i = 0; i< length; i++){
      if(i+1 < length){
      G_line(x[i], y[i], x[i+1], y[i+1]);
      }
      else{
	G_line(x[i], y[i], x[0], y[0]);
      }
      
}

  }
Exemplo n.º 18
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);
  }
}
Exemplo n.º 19
0
void getClippingWindow(){
	double coords[2];
	int i = 0;
	G_rgb(255,0,0);
	G_fill_rectangle(0,0,40,40);
while(1==1){
G_wait_click(coords);
if(coords[0] < 40 && coords[1] < 40){
	break;}
else{
	cx[i] = coords[0];
	cy[i] = coords[1];
	G_rgb(255,255,255);
	G_fill_rectangle(coords[0],coords[1], 5,5);
	center[0] += cx[i];
	center[1] += cy[i];
	i++;
}
}

center[0] /=i;
center[1] /=i;
cSize = i;
}
Exemplo n.º 20
0
void redraw(){

  int i;

  G_rgb(1,1,1);

  G_clear();

  for(i=0;i<numPolygons;i++){

    buildPoly(i);

  }

}
Exemplo n.º 21
0
int main()
{
    G_init_graphics(600, 600);

    for (int j = 0; j < 200; ++j)
    {
        {
            usleep(20000);
            G_rgb(drand48(),drand48(),drand48());
            G_clear();

            G_rgb(drand48(),drand48(),drand48());
            G_fill_polygon(x,y,n) ;
            G_display_image(); // clearing, choosing random colors
        }

        translate(-300, -300) ;
        scale(0.98, 0.98) ;
        rotate(3.0) ;
        translate(300, 300) ;
    }

    int close = G_wait_key() ;
}
Exemplo n.º 22
0
void redraw(){
  
  
  int k = buildArray();
  
  int i, j;
  
  G_rgb(0,0,.3);
  
  G_clear();
  
  for(i =0; i < k; i++){
    buildPoly(i);
  }
  
  G_rgb(1,0,0);
  G_point((300/H)*lightPos[0]/lightPos[2] + 300, (300/H)*lightPos[1]/lightPos[2] + 300);
  /*
    
  //printf("%d\n", numPolygons[thisObj]);
  
  for(thisObj=0;thisObj<numObjects; thisObj++){
  
  for(i=0;i<numPolygons[thisObj];i++){
  
  buildPoly(i);
  
  
  }
  
  
  }
  */
  
  //  exit(1) ;
}
Exemplo n.º 23
0
Arquivo: t03.c Projeto: javins/fpt
void Draw(double degrees)
{
   double xcen,ycen,radius ;

   int i,n ;
   double delta,u,v ;
   double x0,y0, x1,y1,x2,y2 ;
   double color ;
   double r,g,b ;

   G_clear() ;

   n = 24 ;
   xcen = 0.5*swidth ; ycen = 0.5*sheight ; 

   if (swidth < sheight) { radius = 0.4*swidth ;}
   else { radius = 0.4*sheight ; }

   delta = 360.0/n ;
   for (i = 0 ; i < n ; i+=1) {
     u =  degrees + i*delta ;
     v =  u + delta ;
     u *= (M_PI/180) ;
     v *= (M_PI/180) ;

     x0 = xcen ;
     y0 = ycen ;

     x1 = xcen + radius*cos(u) ;
     y1 = ycen + radius*sin(u) ;

     x2 = xcen + radius*cos(v) ;
     y2 = ycen + radius*sin(v) ;

     if (i == 0) {
       r = 1 ; g = 1 ; b = 0 ;
     } else if (i % 2 == 0) {
       r = 1 ; g = 0 ; b = 0 ;
     } else {
       r = 0 ; g = 0 ; b = 1 ;
     }
     

     G_rgb (r,g,b) ;
     G_fill_triangle(x0,y0, x1,y1, x2,y2) ;

   }
}
Exemplo n.º 24
0
void redraw(){

 

  int i;

  G_rgb(1,1,1);

  G_clear();

  //printf("%d\n", numPolygons[thisObj]);

  for(i=0;i<numPolygons[thisObj];i++){

    buildPoly(i);

  }

}
Exemplo n.º 25
0
void buildPoly(int i){

  double R, G, B;

  G_rgb(r[i],g[i],b[i]);

  double xpoly[20], ypoly[20];

  int j,k,n;

  n = shapes[i][0];

  for(j=1;j<=n;j++){
    xpoly[j-1] = xp[shapes[i][j]];
    ypoly[j-1] = yp[shapes[i][j]];

  }

  G_fill_polygon(xpoly,ypoly,n);

} 
Exemplo n.º 26
0
void buildPoly(int i){

  double R, G, B;

  G_rgb(r[thisObj][i],g[thisObj][i],b[thisObj][i]);

  double xpoly[20], ypoly[20];

  int j,k,n;

  n = shapes[thisObj][i][0];

  for(j=1;j<=n;j++){
    xpoly[j-1] = xp[thisObj][shapes[thisObj][i][j]];
    ypoly[j-1] = yp[thisObj][shapes[thisObj][i][j]];

  }
  
  clipHitheryon

  G_fill_polygon(xpoly,ypoly,n);


} 
Exemplo n.º 27
0
void setUp(){
  G_init_graphics(WINDOW_WIDTH,WINDOW_WIDTH + 30);
  G_rgb(0,0,0);
  G_clear();
  G_clear(1,1,1);
}
Exemplo n.º 28
0
int main (int argc, char **argv)
{
    char q, action;
    double mat[4][4], minv[4][4], scaleFactor;
    double radians = 3 * (M_PI / 180);
    FILE *g;
    int cc, sign, currentObj, k, h;
    int increment = 15;
    int xcounter, ycounter, zcounter = 0;

    for (cc = 1; cc < argc; cc++) {
        g = fopen(argv[cc], "r"); //opens a file; r = read only
        if (g == NULL) { //if the file is empty, it will let me know
            printf("can't open (1)\n");
            exit(1);
        } else {
            readobject(g, cc);

            D3d_make_identity(mat);
            D3d_make_identity(minv);
            scaleFactor = scale_n_fit(cc);
            D3d_translate(mat, minv, -centerx, -centery, -centerz);
            D3d_scale(mat, minv, scaleFactor, scaleFactor, scaleFactor);
            D3d_mat_mult_points(x[cc], y[cc], z[cc], mat,
                                x[cc], y[cc], z[cc], points[cc]);
            // printarray(z[cc], points[cc]);
        }
    }

    welcome(argc - 1);
    scanf("%c", &q);
    currentObj = q - '0';
    sign = 1 ;
    action = 't' ;

    if (currentObj < argc && currentObj > 0) {
        G_init_graphics(WIDTH, HEIGHT);
        while (1) {
            G_rgb(0, 0, 0);
            G_clear();
            drawit(currentObj);

            D3d_make_identity (mat) ;
            D3d_make_identity (minv) ;

            q = G_wait_key() ;

            if (q == 'q') {
                exit(0) ;
            } else if (q == 'c') {
                sign = -sign ;
            } else if (q == 't') {
                action = q ;
            } else if (q == 's') {
                reverse = -reverse;
            } else if (q == 'r') {
                action = q ;
            } else if (('0' <= q) && (q <= '9')) {
                k = q - '0' ;
                if (h != currentObj) {
                    currentObj = k;
                }
            } else if ((q == 'x') && (action == 't')) {
                D3d_translate (mat, minv, sign * increment, 0, 0);
                xcounter = xcounter + (sign * increment);

            } else if ((q == 'y') && (action == 't')) {
                D3d_translate (mat, minv, 0, sign * increment, 0);
                ycounter = ycounter + (sign * increment);

            } else if ((q == 'z') && (action == 't')) {
                D3d_translate(mat, minv, 0, 0, sign * increment);
                zcounter = zcounter + (sign * increment);

            } else if ((q == 'x') && (action == 'r')) {
                D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter);
                D3d_rotate_x(mat, minv, sign * radians);
                D3d_translate(mat, minv, xcounter, ycounter, zcounter);

            } else if ((q == 'y') && (action == 'r')) {
                D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter);
                D3d_rotate_y(mat, minv, sign * radians);
                D3d_translate(mat, minv, xcounter, ycounter, zcounter);

            } else if ((q == 'z') && (action == 'r')) {
                D3d_translate(mat, minv, -xcounter, -ycounter, -zcounter);
                D3d_rotate_z(mat, minv, sign * radians);
                D3d_translate(mat, minv, xcounter, ycounter, zcounter);

            } else {
                printf("no action\n") ;
            }


            D3d_mat_mult_points (x[currentObj], y[currentObj], z[currentObj],
                                 mat,  x[currentObj], y[currentObj],
                                 z[currentObj], points[currentObj] + 1) ;
            //the numpoints[currentObj]+1 is because we have stored
            //the center of the object at the arrays' end

            G_rgb(0, 0, 0);
            G_clear();
            drawit(currentObj);
        }
    }
}
Exemplo n.º 29
0
int main()
{
  double pwidth, pheight, bwidth ;
  double angle,hx,hy,mx,my,sx,sy ;
  double hours,minutes,seconds ;
  double x,y,nx,ny,digit ;
  int theta ;   //INTERESTING that this MUST be int to avoid flicker-WHY?
  double oldhourtheta,oldminutetheta,oldsecondtheta ;
  char text[3] ;
  double hms[3] ; // hours,minutes,seconds


  G_init_graphics(600,600) ;
  G_rgb (1,1,1) ;
  G_fill_rectangle (0,0, 600,600) ;

  // outer circle of the clock face 
  G_rgb (1,0,0) ; // red
  theta = 0 ; // degrees 
  x = 225*cos(theta*M_PI/180) + 300 ;
  y = 225*sin(theta*M_PI/180) + 300 ;
  while (theta <= 360) {
        theta = theta + 1 ;
        nx = 225*cos(theta*M_PI/180) + 300 ;
        ny = 225*sin(theta*M_PI/180) + 300 ;
        G_line(x,y,nx,ny) ;
        x = nx ;
        y = ny ;
  }
  G_display_image() ;


  // digits on the clock face 
  G_rgb (0,0,0) ; // black
  theta = 90 ; // degrees 
  digit = 0 ;
  while (theta > -270) {
        theta = theta - 30 ;
        digit = digit + 1 ;
        nx = 200*cos(theta*M_PI/180) + 300 ;
        ny = 200*sin(theta*M_PI/180) + 300 ;
        if (digit >= 10) { 
                   text[0] = '1' ;
                   text[1] = '0' + digit - 10 ;
                   text[2] = '\0' ;
		 }
        else {
                   text[0] = '0' + digit ;
                   text[1] = '\0' ;
		 }
        G_draw_string(text,nx-5,ny-5) ;
  }
  G_display_image() ;


  oldsecondtheta = oldminutetheta = oldhourtheta = -10000000 ;
  sx = sy = mx = my = hx = hy = 300 ;
  while (0 < 1) {

  /* watch out for SLIGHT FLAW : if one of the hands overlays another,
     then if it is erased, you'll erase the other as well...this should
     fix that...we erase them all and redraw them all */

    get_timeD (hms) ;
    hours   = hms[0] ;
    minutes = hms[1] ;
    seconds = hms[2] ;

    // set the second hand 
    theta = 90 - 6*seconds  ;
    if (theta != oldsecondtheta) {
       G_rgb (1,1,1) ; // white
       G_line(300,300,sx,sy) ;
       G_line(300,300,mx,my) ;
       G_line(300,300,hx,hy) ;
       angle = theta*M_PI/180 ;
       sx = 175*cos(angle) + 300 ;
       sy = 175*sin(angle) + 300 ;
       G_rgb (1,0,0) ; // red
       G_line(300,300,sx,sy) ;
       G_line(300,300,mx,my) ;
       G_line(300,300,hx,hy) ;

       G_display_image() ;
       oldsecondtheta = theta ;
     }


    // set the minute hand 
    theta = 90 - 6*(minutes + seconds/60.0)  ;
    if (theta != oldminutetheta) {
       G_rgb (1,1,1) ; // white
       G_line(300,300,sx,sy) ;
       G_line(300,300,mx,my) ;
       G_line(300,300,hx,hy) ;
       angle = theta*M_PI/180 ;
       mx = 140*cos(angle) + 300 ;
       my = 140*sin(angle) + 300 ;
       G_rgb (1,0,0) ; // red
       G_line(300,300,sx,sy) ;
       G_line(300,300,mx,my) ;
       G_line(300,300,hx,hy) ;

       G_display_image() ;
       oldminutetheta = theta ;
     }

    // set the hour hand 
    theta = 90 - 30*(hours + minutes/60.0 + seconds/3600.0)  ;
    if (theta != oldhourtheta) {
       G_rgb (1,1,1) ; // white
       G_line(300,300,sx,sy) ;
       G_line(300,300,mx,my) ;
       G_line(300,300,hx,hy) ;
       angle = theta*M_PI/180 ;
       hx = 75*cos(angle) + 300 ;
       hy = 75*sin(angle) + 300 ;
       G_rgb (1,0,0) ; // red
       G_line(300,300,sx,sy) ;
       G_line(300,300,mx,my) ;
       G_line(300,300,hx,hy) ;

       G_display_image() ;
       oldhourtheta = theta ;
     }

   } // end while (0 < 1) 

}
Exemplo n.º 30
0
void calcColor(double *xx, double *yy, double *zz, double initR, double initG, double initB){
  
  double ambient = .2;
  double diffuse;
  double D = .5;
  double specularPower = 50;
  double specular;
  
  double vec1[3];
  double vec2[3];
  double normalV[3];
  double lightV[3];
  double r[3];
  
  double eyeV[3];
  
  int i;
  lightV[0] = lightPos[0] - xx[0];
  lightV[1] = lightPos[1] - yy[0];
  lightV[2] = lightPos[2] - zz[0];
  
  specular = (1 - ambient - D);
  
  vec1[0] = xx[1] - xx[0] ;
  vec1[1] = yy[1] - yy[0] ;
  vec1[2] = zz[1] - zz[0] ;
  
  vec2[0] = xx[2] - xx[0] ;
  vec2[1] = yy[2] - yy[0] ;
  vec2[2] = zz[2] - zz[0] ;
  
  eyeV[0] = 0 - xx[0] ;
  eyeV[1] = 0 - yy[0] ;
  eyeV[2] = 0 - zz[0] ;
  
  makeUnit(vec1);
  makeUnit(vec2);
  makeUnit(lightV);
  makeUnit(eyeV);
  
  crossProduct(normalV, vec1, vec2);
  
  makeUnit(normalV);
 		if(objectIsReversed[thisObj]){
  		for(i = 0; i < 3; i++){
  			normalV[i] = -normalV[i];
  		}
  		
  	}
  
  
  //printf("vec1: %lf %lf %lf\n", vec1[0], vec1[1], vec1[2]);
  
  double alpha = dotProduct(normalV, lightV);
  double intensity;
    if(alpha >= 0){
      diffuse = alpha;
    }else{
      diffuse = 0;
    }	
    
    for(i = 0; i < 3; i++){
      r[i] = 2*(alpha*normalV[i]) - lightV[i];
    }
    
    double beta = dotProduct(eyeV, r);
    if(beta >= 0){
      specular = beta;
    }else{
      specular = 0;
    }
    
    //printf("diffuse: %lf\n", diffuse);
    //printf("diffuse: %lf\n", diffuse);
    
    intensity = ambient + diffuse * D + pow(specular, specularPower) ;
  //}
  
  double rd, gn, bl;
  
  rd = initR * intensity;
  gn = initG * intensity;
  bl = initB * intensity;
  
  G_rgb(rd, gn, bl);
  
}