Пример #1
0
void view_rotate_circle(Polygon* poly_vrp, Point* center, int sides, double scale, double thetax, double thetay, double thetaz){
	if(NULL != poly_vrp){
		//make a unit circle of "sides" number fo sides and store the points in the poly_vrp
		int i;
		double x, z;
		polygon_init(poly_vrp);
		Point p[sides];
		Matrix LTM;
		matrix_identity(&LTM);
		matrix_scale(&LTM, scale, scale, scale);
		matrix_rotateX(&LTM, cos(thetax*M_PI/180), sin(thetax*M_PI/180));
		matrix_rotateY(&LTM, cos(thetay*M_PI/180), sin(thetay*M_PI/180));
		matrix_rotateZ(&LTM, cos(thetaz*M_PI/180), sin(thetaz*M_PI/180));
		matrix_translate(&LTM, center->val[0], center->val[1], center->val[2]);
		for(i=0; i<sides; i++){
			x = cos( i * M_PI * 2.0 / sides );
    		z = sin( i * M_PI * 2.0 / sides );

    		point_set3D(&p[i], x, 0.1, z);
		}
		polygon_set(poly_vrp, sides, &p[0]);
		matrix_xformPolygon(&LTM, poly_vrp);
	}
}
Пример #2
0
int main(int argc, char *argv[]) {
  const int rows = 1000;
  const int cols = 1000;
  View3D view;
  Matrix vtm;
  Polygon side[4];
  Polygon tpoly;
  Point  tv[3];
  Point  v[4];
  Color  color[4];
  Image *src;
  char filename[100];
  double x;
  int i;

  // set some colors
  Color_set( &color[0], 0, 0, 1 );
  Color_set( &color[1], 0, 1, 0 );
  Color_set( &color[2], 1, 0, 0 );
  Color_set( &color[3], 1, 0, 1 );


  // initialize polygons
  for(i=0;i<4;i++) {
    polygon_init( &side[i] );
  }

  // corners of a cube, centered at (0, 0, 0)
  point_set3D( &v[0], 0, 1, 0 );
  point_set3D( &v[1], 1, -1, 0);
  point_set3D( &v[2], -1, -1, 0 );
  point_set3D( &v[3], 0,  0, 1 );

  //base of the pyramid
  polygon_set(&side[3], 3, &(v[0]));

  //side1
  point_copy(&tv[0], &v[0]);
  point_copy(&tv[1], &v[2]);
  point_copy(&tv[2], &v[3]);

  polygon_set(&side[0], 3, tv);

  //side2
  point_copy(&tv[0], &v[0]);
  point_copy(&tv[1], &v[1]);
  point_copy(&tv[2], &v[3]);

  polygon_set(&side[1], 3, tv);

  //side3
  point_copy(&tv[0], &v[1]);
  point_copy(&tv[1], &v[2]);
  point_copy(&tv[2], &v[3]);

  polygon_set(&side[2], 3, tv);


  point_set3D( &(view.vrp), 1, 0, 0);
  vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] );

  vector_set( &(view.vup), 0, 0, 1 );
  view.d = 1;  // focal length
  view.du = 2;
  view.dv = view.du * (float)rows / cols;
  view.f = 0; // front clip plane
  view.b = 4; // back clip plane
  view.screenx = cols;
  view.screeny = rows;

  matrix_setView3D( &vtm, &view );

  // use a temprary polygon to transform stuff
  polygon_init( &tpoly );
  printf("Drawing pyramid\n");

x = -2;
int j;
for (j=0; j<50; j++){
// create image
  src = image_create( rows, cols );
  point_set3D(&(view.vrp), x , 2, 0.5);
  vector_set( &(view.vpn), -x, -2, -0.5);
  matrix_setView3D(&vtm, &view);  
  i=0;
  for(i=0;i<4;i++) {
    polygon_copy( &tpoly, &side[i] );
    matrix_xformPolygon( &vtm, &tpoly );

    // normalize by homogeneous coordinate before drawing
    polygon_normalize( &tpoly );


    polygon_draw( &tpoly, src, color[i] );
    //polygon_print( &tpoly, stdout );
  }
  
  printf("Writing image\n");
  sprintf(filename, "pyramid_%04d.ppm", j);
  image_write( src, filename);
  free(src);
  if(j<25){
  	x += 0.08;
  }else{
  	x -= 0.08;
  }
}

printf("Making the .gif file...\n");
system("convert -delay 10 pyramid_*.ppm ../images/ext1.gif");
system("rm -f pyramid*");




  return(0);
}
Пример #3
0
int main(int argc, char *argv[]) {
  const int rows = 180;
  const int cols = 320;
	const int nFrames = 100;
  View3D view;
  Matrix vtm;
  Polygon side[6];
  Polygon tpoly;
  Point  tv[4];
  Point  v[8];
  Color  color[6];
  Image *src;
  int i, t;
	char filename[256];

  // set some colors
  color_set( &color[0], 0, 0, 1 );
  color_set( &color[1], 0, 1, 0 );
  color_set( &color[2], 1, 0, 0 );
  color_set( &color[3], 1, 0, 1 );
  color_set( &color[4], 0, 1, 1 );
  color_set( &color[5], 1, 1, 0 );

	for(t=0;t<nFrames;t++) {

		// initialize polygons
		for(i=0;i<6;i++) {
		  polygon_init( &side[i] );
		}

		// corners of a cube, centered at (0, 0, 0)
		point_set1( &v[0], -1, -1, -1 );
		point_set1( &v[1],  1, -1, -1 );
		point_set1( &v[2],  1,  1, -1 );
		point_set1( &v[3], -1,  1, -1 );
		point_set1( &v[4], -1, -1,  1 );
		point_set1( &v[5],  1, -1,  1 );
		point_set1( &v[6],  1,  1,  1 );
		point_set1( &v[7], -1,  1,  1 );

		// front side
		polygon_set( &side[0], 4, &(v[0]) );

		// back side
		polygon_set( &side[1], 4, &(v[4]) );

		// top side
		point_copy( &tv[0], &v[2] );
		point_copy( &tv[1], &v[3] );
		point_copy( &tv[2], &v[7] );
		point_copy( &tv[3], &v[6] );

		polygon_set( &side[2], 4, tv );

		// bottom side
		point_copy( &tv[0], &v[0] );
		point_copy( &tv[1], &v[1] );
		point_copy( &tv[2], &v[5] );
		point_copy( &tv[3], &v[4] );

		polygon_set( &side[3], 4, tv );

		// left side
		point_copy( &tv[0], &v[0] );
		point_copy( &tv[1], &v[3] );
		point_copy( &tv[2], &v[7] );
		point_copy( &tv[3], &v[4] );

		polygon_set( &side[4], 4, tv );

		// right side
		point_copy( &tv[0], &v[1] );
		point_copy( &tv[1], &v[2] );
		point_copy( &tv[2], &v[6] );
		point_copy( &tv[3], &v[5] );

		polygon_set( &side[5], 4, tv );

		// grab command line argument to determine viewpoint
		// and set up the view structure
		/*if( argc > 1 ) {
		  float alpha = atof( argv[1] );
		  if( alpha < 0.0 || alpha > 1.0 )
		    alpha = 0.0;

		  point_set1( &(view.vrp), 3*alpha, 2*alpha, -2*alpha - (1.0-alpha)*3 );
		}
		else {
		  point_set1( &(view.vrp), 3, 2, -2 );
		} */
	
		float alpha = abs(t - (0.5*nFrames)) /  (0.5*nFrames);
		point_set1( &(view.vrp), 3*alpha, 2*alpha, -2*alpha - (1.0-alpha)*3 );

		vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] );

		vector_set( &(view.vup), 0, 1, 0 );
		view.d = 1;  // focal length
		view.du = 2;
		view.dv = view.du * (float)rows / cols;
		view.f = 0; // front clip plane
		view.b = 4; // back clip plane
		view.screenx = cols;
		view.screeny = rows;

		matrix_setView3D( &vtm, &view );

		// create image
		src = image_create( rows, cols );

		// use a temprary polygon to transform stuff
		polygon_init( &tpoly );

		//printf("Drawing Polygons\n");
		for(i=0;i<6;i++) {
		  polygon_copy( &tpoly, &side[i] );
		  matrix_xformPolygon( &vtm, &tpoly );

		  // normalize by homogeneous coordinate before drawing
		  polygon_normalize( &tpoly );

		  polygon_draw( &tpoly, src, color[i] );
		  //polygon_print( &tpoly, stdout );
		}

		sprintf(filename, "frame-%04d.ppm", t );
    image_write( src, filename );
		
		/*printf("Writing image\n");
		image_write( src, "cube.ppm" );*/
	}
	system("convert frame-*.ppm cube.gif");
	system("rm frame-*.ppm");

  return(0);
}
Пример #4
0
/*
 * insert a pyramid into the module
 */
void module_pyramid(Module *md, int solid, float size, float x, float y, float z){

	if(!md){
		printf("Null md passed to module_pyramid\n");
		return;
	}
	Polygon side;
	Point tv[3];
    Point v[5];
    Line l;
    Element *e;
    int i;

    polygon_init(&side);

    // corners of the pyramid
    point_set3D(&v[0], -1, -1, -1 );
    point_set3D(&v[1],  1, -1, -1 );
    point_set3D(&v[2],  1,  -1, 1 );
    point_set3D(&v[3], -1,  -1, 1 );
    point_set3D(&v[4], 0, 0, 0);
    //printf("points created\n");

    // set pyramid parameters
    module_scale(md, (int)size, (int)size, (int)size);
	module_translate(md, (float)x, (float)y, (float)z);
	//printf("parameters set\n");

    if (solid == 0){
    	// add only lines
    	// foundation
		for(i=0;i<3;i++){
			line_set( &l, v[i], v[i+1] );
			e = element_init(ObjLine, &l);
			module_insert(md, e);
		}
		line_set( &l, v[3], v[0] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		
		// connecting lines
		line_set( &l, v[4], v[0] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[1], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[2], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[3], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);

		//printf("successfully passed to module\n");
    } else{

    	// front side
	    point_copy(&tv[0], &v[0]);
	    point_copy(&tv[1], &v[1]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv);
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // back side
	    point_copy(&tv[0], &v[3]);
	    point_copy(&tv[1], &v[2]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv);
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // bottom side
	    polygon_set(&side, 4, &(v[0]));
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // left side
	    point_copy(&tv[0], &v[0]);
	    point_copy(&tv[1], &v[3]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv);
	    e = element_init(ObjPolygon, &side);
		module_insert(md, e);

	    // right side
	    point_copy(&tv[0], &v[1]);
	    point_copy(&tv[1], &v[2]);
	    point_copy(&tv[2], &v[4]);
	    polygon_set(&side, 3, tv); 
		e = element_init(ObjPolygon, &side);
		module_insert(md, e);

		//printf("successfully passed to module\n");
    }

    polygon_clear(&side);
}
Пример #5
0
/*
* Sourced from coursework file test6b.c (Bruce Maxwell)
*/
void module_cone( Module *mod, int sides, int fill, int size, float x, float y, float z) {
	Polygon p;
	Point xtop, xbot;
	Element *e;
	Line l;
	double x1, x2, z1, z2;
	int i;

	if(!mod){
		printf("Null md passed to module_cylinder\n");
		return;
	}

	// set cone parameters
    module_scale(mod, (int)size, (int)size, (int)size);
	module_translate(mod, (float)x, (float)y, (float)z);
	printf("parameters set\n");

	polygon_init( &p );
	point_set3D( &xtop, 0, 1.0, 0.0 );
	point_set3D( &xbot, 0, 0.0, 0.0 );

	if (fill == 1){
		// make a fan for the top and bottom sides
		// and quadrilaterals for the sides
		for(i=0;i<sides;i++) {
			Point pt[6];

			x1 = cos( i * M_PI * 2.0 / sides );
			z1 = sin( i * M_PI * 2.0 / sides );
			x2 = cos( ( (i+1)%sides ) * M_PI * 2.0 / sides );
			z2 = sin( ( (i+1)%sides ) * M_PI * 2.0 / sides );

			point_copy( &pt[0], &xbot );
			point_set3D( &pt[1], x1, 0.0, z1 );
			point_set3D( &pt[2], x2, 0.0, z2 );

			polygon_set( &p, 3, pt );
			e = element_init(ObjPolygon, &p);
			module_insert(mod, e);

			point_set3D( &pt[3], x1, 0.0, z1 );
			point_set3D( &pt[4], x2, 0.0, z2 );
			point_copy( &pt[5], &xtop);

			polygon_set( &p, 3, &pt[3] );
			e = element_init(ObjPolygon, &p);
			module_insert(mod, e);
		}
	} else{
		// make a fan for the top and bottom sides
		// and quadrilaterals for the sides
		for(i=0;i<sides;i++) {
			Point pt[8];

			x1 = cos( i * M_PI * 2.0 / sides );
			z1 = sin( i * M_PI * 2.0 / sides );
			x2 = cos( ( (i+1)%sides ) * M_PI * 2.0 / sides );
			z2 = sin( ( (i+1)%sides ) * M_PI * 2.0 / sides );

			point_copy( &pt[0], &xbot );
			point_set3D( &pt[1], x1, 0.0, z1 );
			point_set3D( &pt[2], x2, 0.0, z2 );

			line_set( &l, pt[0], pt[1] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[1], pt[2] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[2], pt[0]);
			e = element_init(ObjLine, &l);
			module_insert(mod, e);

			point_set3D( &pt[3], x1, 0.0, z1 );
			point_set3D( &pt[4], x2, 0.0, z2 );
			point_set3D( &pt[5], x2, 1.0, z2 );
			point_set3D( &pt[6], x1, 1.0, z1 );
			point_copy( &pt[7], &xtop);

			line_set( &l, pt[0], pt[7] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[1], pt[7] );
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[2], pt[7]);
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
			line_set( &l, pt[3], pt[7]);
			e = element_init(ObjLine, &l);
			module_insert(mod, e);
		}
	}
	polygon_clear( &p );
}
Пример #6
0
/*
 * Adds a unit cube, axis-aligned and centered on zero to the Module. 
 * If solid is zero, add only lines. If solid is non-zero, use polygons. 
 * Make sure each polygon has surface normals defined for it.
 */
void module_cube(Module *md, int solid){
	if(!md){
		printf("Null md passed to module_cube\n");
		return;
	}
	Element *e;
 	Polygon p;
	Point v[8];
	Point tv[4];
	Line l;
	int i;
	
	// initialize polygon
	polygon_init( &p );
  
	// corners of a cube, centered at (0, 0, 0)
	point_set3D( &v[0], -0.5, -0.5, -0.5 );
	point_set3D( &v[1],  0.5, -0.5, -0.5 );
	point_set3D( &v[2],  0.5,  0.5, -0.5 );
	point_set3D( &v[3], -0.5,  0.5, -0.5 );
	point_set3D( &v[4], -0.5, -0.5,  0.5 );
	point_set3D( &v[5],  0.5, -0.5,  0.5 );
	point_set3D( &v[6],  0.5,  0.5,  0.5 );
	point_set3D( &v[7], -0.5,  0.5,  0.5 );
		
	if(solid == 0){
		// add only lines ( 12 of them )
		
		// front face lines
		for(i=0;i<3;i++){
			line_set( &l, v[i], v[i+1] );
			e = element_init(ObjLine, &l);
			module_insert(md, e);
		}
		line_set( &l, v[3], v[0] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		
		// back face lines
		for(i=4;i<7;i++){
			line_set( &l, v[i], v[i+1] );
			e = element_init(ObjLine, &l);
			module_insert(md, e);
		}
		line_set( &l, v[7], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		
		// connecting lines
		line_set( &l, v[2], v[6] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[3], v[7] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[0], v[4] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
		line_set( &l, v[1], v[5] );
		e = element_init(ObjLine, &l);
		module_insert(md, e);
	}
	else{
	 	// use polygons ( 6 of them )
		// front side
		polygon_set( &p, 4, &(v[0]) );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// back side
		polygon_set( &p, 4, &(v[4]) );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// top side
		point_copy( &tv[0], &v[2] );
		point_copy( &tv[1], &v[3] );
		point_copy( &tv[2], &v[7] );
		point_copy( &tv[3], &v[6] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// bottom side
		point_copy( &tv[0], &v[0] );
		point_copy( &tv[1], &v[1] );
		point_copy( &tv[2], &v[5] );
		point_copy( &tv[3], &v[4] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// left side
		point_copy( &tv[0], &v[0] );
		point_copy( &tv[1], &v[3] );
		point_copy( &tv[2], &v[7] );
		point_copy( &tv[3], &v[4] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);

		// right side
		point_copy( &tv[0], &v[1] );
		point_copy( &tv[1], &v[2] );
		point_copy( &tv[2], &v[6] );
		point_copy( &tv[3], &v[5] );

		polygon_set( &p, 4, tv );
		e = element_init(ObjPolygon, &p);
		module_insert(md, e);
	}
	
	// clean up
	polygon_clear(&p);
}
Пример #7
0
/*
 * use the de Casteljau algorithm to subdivide the Bezier surface divisions times,
 * then draw either the lines connecting the control points, if solid is 0, 
 * or draw triangles connecting the surface.
 */
void module_bezierSurface(Module *m, BezierSurface *b, int divisions, int solid){
	int i, j, k, l;
	Line tempLine;
	Point grid[7][7];
	Point controls[7];
	Point deCast[7];
	Point surfacePoints[16];
	BezierSurface tempBezSurf;
	Polygon *temptri = polygon_create();
	if(!m || !b){
		printf("Null passed to module_bezierSurface\n");
		return;
	}
	
	// base case
	if(divisions == 0){
		// lines
		if(solid == 0){
			for(i=0;i<4;i++){
				for(j=0;j<3;j++){
					line_set(&tempLine, b->c[i][j], b->c[i][j+1]);
					module_line(m, &tempLine);
					line_set(&tempLine, b->c[j][i], b->c[j+1][i]);
					module_line(m, &tempLine);
				}
			}
		} 
		// triangles
		else {
			controls[0] = b->c[0][0];
			controls[1] = b->c[0][3];
			controls[2] = b->c[3][3];
			controls[3] = b->c[3][0];
			controls[4] = b->c[0][0];
			polygon_set(temptri, 3, &(controls[0]));
			module_polygon(m, temptri);
			polygon_set(temptri, 3, &(controls[2]));
			module_polygon(m, temptri);
		}
	}
	
	// divide and recurse
	else {

		// compute all avg points for 3 orders, down to just one point 3rd order
		// do for each of the four bezier curves
		for(i=0;i<4;i++){
			deCasteljau(&(deCast[0]), &(b->c[i][0]));
			for(j=0;j<7;j++){
				grid[2*i][j] = deCast[j];
			}
		}

		// now traverse the other direction, populating grid
		for(i=0;i<7;i++){
			for(j=0;j<4;j++){
				controls[j] = grid[2*j][i];
			}
			deCasteljau(&(deCast[0]), &(controls[0]));
			for(j=0;j<7;j++){
				grid[j][i] = deCast[j];
			}
		}

		// now make the four new bezier surfaces by subdividing across
		for(i=0;i<2;i++){
			for(j=0;j<2;j++){
				for(k=0;k<4;k++){
					for(l=0;l<4;l++){
						surfacePoints[4*k+l] = grid[k+3*i][l+3*j];
					}
				}
				bezierSurface_set(&tempBezSurf, &(surfacePoints[0]));
				// recursive call
				module_bezierSurface(m, &tempBezSurf, divisions-1, solid);
			}
		}
	}
	
	// clean up
	polygon_free(temptri);
}
Пример #8
0
// makes 3 X-wing fighters in a loose formation
int main(int argc, char *argv[]) {
  int i, j; //loop variables

  Image *src;
  Module* wall;
  Module* ray;
  Module* ray2;
  Module *scene1;
  Module* scene2;
  Polygon p;
  Line l;
  Point point[4];
  Point point2[2];
  View3D view;
  Matrix vtm, gtm;
  DrawState *ds;
  char filename[100];
  Color Flame = { { 1.0, 0.7, 0.2 } };
  Color Red =  { { 1.0, 0.2, 0.1 } };
  Color Grey =  { { 0.745, 0.745, 0.745} };
  Color Blue = {{0.117647, 0.564706, 1}};
  // Color Grey = {{1, 1, 1}};


  // set up the view
  point_set3D( &(view.vrp), 4, 4, 4 );
  vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] );
  vector_set( &(view.vup), 0, 1, 0 );

  view.d = 1;
  view.du = 1.6;
  view.dv = 0.9;
  view.f = 1;
  view.b = 50;
  view.screenx = 640;
  view.screeny = 360;

  matrix_setView3D( &vtm, &view );
  matrix_identity( &gtm );

  // //wall
  wall = module_create();
  module_color(wall, &Red);
  polygon_init(&p);
  point_set3D(&point[0], 1,1,2);
  point_set3D(&point[1], 1,0,2);
  point_set3D(&point[2], 0,0,2);
  point_set3D(&point[3], 0,1,2);
  polygon_set(&p, 4, &point[0]);
  module_polygon(wall, &p);

//ray
  ray = module_create();
  module_color(ray, &Blue);
  for(i=0; i< 5; i++){
  point_set3D(&point2[0], -1+0.01*i, -1, 1);
  point_set3D(&point2[1], 1+0.01*i, 1, 1);
  line_set(&l, point2[0], point2[1]);
  module_line(ray, &l);
 }

 //ray2

  ray2 = module_create();
  module_color(ray2, &Red);
  for(i=0; i< 5; i++){
  point_set3D(&point2[0], -1+0.01*i, 1, -1);
  point_set3D(&point2[1], 1+0.01*i, -1, -1);
  line_set(&l, point2[0], point2[1]);
  // line_zBuffer(&l, 0);
  module_line(ray2, &l);
 }



//scene
    // scene = module_create();
    // module_module(scene, wall);
    // module_module(scene, ray);
    // module_module(scene, ray2);
    // module_module(scene, wall);
    



    

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

	//scene
    scene1 = module_create();
    scene2 = module_create();
    module_rotateZ(scene1, cos(i*10 * M_PI/180), sin(i*10 * M_PI/180));
    module_scale( scene1, 3, 1, 2 );
    module_color( scene1, &Blue );
    module_cube( scene1, 1);


    module_scale(scene2, 0.5, 0.5, 0.5);
    module_cylinder(scene2, 30);
	// create the image and drawstate
	src = image_create( 360, 640 );
	ds = drawstate_create();
  drawstate_setAlpha(ds, 1);
	ds->shade = ShadeDepth;

	// draw into the scene
  // module_draw( scene1, &vtm, &gtm, ds, src );
  drawstate_setAlpha(ds, 1 );
	module_draw( scene1, &vtm, &gtm, ds, src );

	// write out the scene
	sprintf(filename, "frame_%.2d.ppm", i);
	image_write( src, filename );
	module_delete( scene1);

}
	 


	//free the polygon data
	// polygon_clear( &p );

	// free the modules
	// module_delete( scene);
	// module_delete( wall );


	// free the drawstate
	free(ds);

	// free the image
	image_free( src );

	return(0);
}
Пример #9
0
/*
  Program to test polygon functionality using barycentric coordinates
*/
int main(int argc, char *argv[]) {
  Image *src;
  const int rows = 100;
  const int cols = 100;
  Polygon *p;
  Color Red;
  Color White;
  Color Blue;
  Point pt[100];

  color_set(&Red, 0.9, 0.2, 0.1 );
  color_set(&White, 1.0, 1.0, 1.0 );
  color_set(&Blue, 0.2, 0.1, 0.95 );
  
  src = image_create(rows, cols);

  // make a simple square to test proper areas and locations
  // the square ought to be 20x20, include pixel (30,30) and exclude pixel (50, 50)
  point_set2D(&(pt[0]), 30, 30);
  point_set2D(&(pt[1]), 50, 30);
  point_set2D(&(pt[2]), 50, 50);
  point_set2D(&(pt[3]), 30, 50);
  point_set2D(&(pt[4]), 30, 30);

  p = polygon_createp(3, pt);

  printf("drawing polygon 1\n");
  polygon_drawFillB(p, src, Blue);

  polygon_set(p, 3, &(pt[2]) );

  printf("drawing polygon 2\n");
  polygon_drawFillB(p, src, Red);

  point_set2D(&(pt[5]), 60, 20);
  point_set2D(&(pt[6]), 80, 85);
  point_set2D(&(pt[7]), 50, 70);
  polygon_set(p, 3, &(pt[5]));

  printf("drawing polygon 3\n");
  polygon_drawFillB(p, src, White);

  point_set2D(&(pt[8]), 5, 5);
  point_set2D(&(pt[9]), 25, 5);
  point_set2D(&(pt[10]), 25, 25);
  point_set2D(&(pt[11]), 5, 25);
  point_set2D(&(pt[12]), 5, 5);

  polygon_set(p, 3, &(pt[10]) );

  printf("drawing polygon 4\n");
  polygon_drawFillB(p, src, Red);

  polygon_set(p, 3, &(pt[8]));

  printf("drawing polygon 5\n");
  polygon_drawFillB(p, src, Blue);


  printf("writing output\n");
  image_write(src, "test4b.ppm");

  image_free(src);

  return(0);
}
Пример #10
0
/*
  Program to test polygon functionality
*/
int main(int argc, char *argv[]) {
  Image *src;
  const int rows = 300;
  const int cols = 400;
  Polygon *p;
  Color Red;
  Color Orange;
  Color White;
  Color Blue;
  Point pt[100];
  int i;
  
  srand(42);

  color_set(&Red, 0.9, 0.2, 0.1 );
  color_set(&Orange, 0.95, 0.7, 0.3 );
  color_set(&White, 1.0, 1.0, 1.0 );
  color_set(&Blue, 0.2, 0.1, 0.95 );

  src = image_create(rows, cols);

  // make a simple square to test proper areas and locations
  // the square ought to be 20x20, include pixel (30,30) and exclude pixel (50, 50)
  point_set2D(&(pt[0]), 30, 30);
  point_set2D(&(pt[1]), 50, 30);
  point_set2D(&(pt[2]), 50, 50);
  point_set2D(&(pt[3]), 30, 50);

  p = polygon_createp(4, pt);

  printf("drawing a square\n");
  polygon_drawFill(p, src, Blue);

  // something more interesting
  for(i=0;i<50;i++) {
    float dr = rand() % 20;
    point_set2D(&(pt[i]), 
    200 + cos((float)i * M_PI * 2.0 / 50.0)*(70 + dr),
    150 + sin((float)i * M_PI * 2.0 / 50.0)*(70 + dr));
  }
  polygon_set(p, 50, pt);

  printf("drawing first big polygon\n");
  polygon_drawFill(p, src, Red);

  for(i=0;i<50;i++) {
    float dr = rand() % 15;
    point_set2D(&(pt[i]), 
    200 + cos((float)i * M_PI * 2.0 / 50.0)*(50 + dr),
    150 + sin((float)i * M_PI * 2.0 / 50.0)*(50 + dr));
  }
  polygon_set(p, 50, pt);

  printf("drawing second big polygon\n");
  polygon_drawFill(p, src, Orange);

  for(i=0;i<50;i++) {
    float dr = rand() % 10;
    point_set2D(&(pt[i]), 
    200 + cos((float)i * M_PI * 2.0 / 50.0)*(30 + dr),
    150 + sin((float)i * M_PI * 2.0 / 50.0)*(30 + dr));
  }
  polygon_set(p, 50, pt);

  printf("drawing third big polygon\n");
  polygon_drawFill(p, src, White);

  printf("writing output\n");
  image_write(src, "test4a.ppm");

  image_free(src);

  return(0);
}