Example #1
0
static void 
make_texture(rubikblocks_conf *cp) 
{
  int x, y;
  for(y = 0; y < TEX_HEIGHT; y++)
    for(x = 0; x < TEX_WIDTH; x++)
      cp->texture[y][x] = 255;
  draw_horz_line(cp, 0, TEX_WIDTH-1, 0);
  draw_horz_line(cp, 0, TEX_WIDTH-1, TEX_HEIGHT-1);
  draw_vert_line(cp, 0, 0, TEX_HEIGHT-1);
  draw_vert_line(cp, TEX_WIDTH-1, 0, TEX_HEIGHT-1);
}
Example #2
0
static void make_texture(cube21_conf *cp) 
{
  int x, y, x0, y0;
  float grayp[2] = {TEX_GRAY};
  for(y=0; y<TEX_HEIGHT; y++)
    for(x=0; x<TEX_WIDTH; x++)
      cp->texture[y][x] = 255;
  draw_horz_line(cp, 0, TEX_WIDTH-1, 0);
  draw_horz_line(cp, cp->texq*TEX_WIDTH, TEX_WIDTH-1, cp->texp*TEX_HEIGHT);
  draw_horz_line(cp, cp->texq*TEX_WIDTH, TEX_WIDTH-1, cp->texq*TEX_HEIGHT);
  draw_horz_line(cp, 0, cp->texq*TEX_WIDTH, TEX_HEIGHT/2);
  draw_horz_line(cp, 0, TEX_WIDTH-1, TEX_HEIGHT*3/4);
  draw_horz_line(cp, 0, TEX_WIDTH-1, TEX_HEIGHT-1);
  draw_vert_line(cp, 0, 0, TEX_HEIGHT-1);
  draw_vert_line(cp, cp->texq*TEX_WIDTH, 0, TEX_HEIGHT*3/4);
  draw_vert_line(cp, TEX_WIDTH-1, 0, TEX_HEIGHT-1);
  draw_slanted_horz(cp, 0, cp->texp*TEX_HEIGHT, TEX_WIDTH/2, TEX_HEIGHT/2);
  draw_slanted_vert(cp, cp->texp*TEX_WIDTH, 0, TEX_WIDTH/2, TEX_HEIGHT/2);
  draw_slanted_vert(cp, cp->texq*TEX_WIDTH, 0, TEX_WIDTH/2, TEX_HEIGHT/2);
  x0 = grayp[0]*TEX_WIDTH;
  y0 = grayp[1]*TEX_HEIGHT;
  for(y=-1; y<=1; y++)
    for(x=-1; x<=1; x++)
      cp->texture[y0+y][x0+x] = 100;   
}
Example #3
0
/*======== void draw_polygons() ==========
  Inputs:   struct matrix *polygons
  screen s
  color c  
  Returns: 
  Goes through polygons 3 points at a time, drawing 
  lines connecting each points to create bounding
  triangles

  04/16/13 13:13:27
  jdyrlandweaver
  ====================*/
void draw_polygons( struct matrix *polygons, screen s, color c, struct constants K, struct light * lights, int num_lights ) {

  int i;

  for( i=0; i < polygons->lastcol-2; i+=3 ) {
    c.red = 0; c.green = 0; c.blue = 0;

    double xB=0,yB=0,zB=0,xT=0,yT=0,zT=0,xM=0,yM=0,zM=0; 
    double Mxy1=0, Mzy1=0, Mxy2=0, Mzy2=0, Mxy3=0, Mzy3=0; // slopes of x and z w.r.t y
    /* M1 is between B and T, M2 is between B and M, M3 is between M and T */
    double x0=0,y0=0,z0=0,x1=0,z1=0;

    if ( calculate_dot( polygons, i ) < 0 ) {
      if(polygons->m[1][i] <= polygons->m[1][i+1]){
	if(polygons->m[1][i+2] >= polygons->m[1][i+1]){
	  xB = polygons->m[0][i]; yB = polygons->m[1][i]; zB = polygons->m[2][i];
	  xM = polygons->m[0][i+1]; yM = polygons->m[1][i+1]; zM = polygons->m[2][i+1];
	  xT = polygons->m[0][i+2]; yT = polygons->m[1][i+2]; zT = polygons->m[2][i+2];
	}else if(polygons->m[1][i+2] >= polygons->m[1][i]){
	  xB = polygons->m[0][i]; yB = polygons->m[1][i]; zB = polygons->m[2][i];
	  xT = polygons->m[0][i+1]; yT = polygons->m[1][i+1]; zT = polygons->m[2][i+1];
	  xM = polygons->m[0][i+2]; yM = polygons->m[1][i+2]; zM = polygons->m[2][i+2];	  
	}else{	  
	  xM = polygons->m[0][i]; yM = polygons->m[1][i]; zM = polygons->m[2][i];
	  xT = polygons->m[0][i+1]; yT = polygons->m[1][i+1]; zT = polygons->m[2][i+1];
	  xB = polygons->m[0][i+2]; yB = polygons->m[1][i+2]; zB = polygons->m[2][i+2];	  
	}
      }else{
	if(polygons->m[1][i+2] >= polygons->m[1][i]){
	  xM = polygons->m[0][i]; yM = polygons->m[1][i]; zM = polygons->m[2][i];
	  xB = polygons->m[0][i+1]; yB = polygons->m[1][i+1]; zB = polygons->m[2][i+1];
	  xT = polygons->m[0][i+2]; yT = polygons->m[1][i+2]; zT = polygons->m[2][i+2];
	}else if(polygons->m[1][i+2] >= polygons->m[1][i+1]){
	  xT = polygons->m[0][i]; yT = polygons->m[1][i]; zT = polygons->m[2][i];
	  xB = polygons->m[0][i+1]; yB = polygons->m[1][i+1]; zB = polygons->m[2][i+1];
	  xM = polygons->m[0][i+2]; yM = polygons->m[1][i+2]; zM = polygons->m[2][i+2];	  
	}else{	  
	  xT = polygons->m[0][i]; yT = polygons->m[1][i]; zT = polygons->m[2][i];
	  xM = polygons->m[0][i+1]; yM = polygons->m[1][i+1]; zM = polygons->m[2][i+1];
	  xB = polygons->m[0][i+2]; yB = polygons->m[1][i+2]; zB = polygons->m[2][i+2];	  
	}
      }

      //printf("%f, %f, %f, %f, %f, %f, %f, %f, %f\n",xB,yB,zB,xM,yM,zM,xT,yT,zT);
      
      if (yB != yT){
	Mxy1 = (xB - xT) / (yB - yT);
	Mzy1 = (zB - zT) / (yB - yT);
      }
      if (yB != yM){
	Mxy2 = (xB - xM) / (yB - yM);
	Mzy2 = (zB - zM) / (yB - yM);
      }
      if (yM != yT){
	Mxy3 = (xM - xT) / (yM - yT);
	Mzy3 = (zM - zT) / (yM - yT);
      }

      c.red += lights[0].c[RED]*K.r[amb];
      c.green += lights[0].c[GREEN]*K.g[amb];
      c.blue += lights[0].c[BLUE]*K.b[amb];


      // we run x0 along B->T
      x0 = xB; y0 = yB; z0 = zB;
      x1 = xB; z1 = zB;
      while(y0 <= yT){
	if (y0 >= yM){
	  x1 = xM + Mxy3 * (y0 - yM);
	  z1 = zM + Mzy3 * (y0 - yM);
	}
	draw_horz_line(ceil(x0),floor(x1),y0,z0,z1,s,c);
	x0 += Mxy1; y0 += 1; z0 += Mzy1;
	if(y0 < yM){
	  x1 += Mxy2; z1 += Mzy2;
	}else{
	  x1 += Mxy3; z1 += Mzy3;
	}
      }     
    }
  }
}