Esempio n. 1
0
/*
 * Matrix operand to add a rotation about the Y-axis to the Module.
 */
void module_rotateY(Module *md, double cth, double sth){
	if(!md){
		printf("Null md passed to module_rotateY\n");
		return;
	}
	Element *e;
	Matrix m;
	matrix_identity(&m);
	matrix_rotateY(&m, cth, sth);
	e = element_init(ObjMatrix, &m);
	module_insert(md, e);
}
Esempio n. 2
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);
	}
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
	int frame;
	Color blue, green, purple, red, white;
	Point p[16];
	BezierSurface bc;
	DrawState ds;
	Module *curve;
	View3D view;
	Matrix VTM, GTM;
	int divisions = 4;
	int rows = 300, cols = 400;
	Image *src = image_create(rows, cols);

	// grab the command line argument, if one exists
	if(argc > 1) {
		int tmp = atoi(argv[1]);
		if( tmp >= 0 && tmp < 10 )
			divisions = tmp;
	}
	printf("Creating Bezier surface with %d subdivisions\n", divisions);

	color_set(&white, 1.0, 1.0, 1.0 );
	color_set(&blue, .1, .2, .8);
	color_set(&green, .2, 0.7, 0.3 );
	color_set(&purple, 0.6, 0.1, 0.7 );
	color_set(&red, 0.75, 0.3, 0.3 );

	curve = module_create();

	// create a flat plane
	point_set3D(&p[0], 0.0, -0.2, 0.0); // first row, constant x, even spacing in z
	point_set3D(&p[1], 0.0, -0.2, 0.33);
	point_set3D(&p[2], 0.0, -0.2, 0.66);
	point_set3D(&p[3], 0.0, -0.2, 1.0);
	point_set3D(&p[4], 0.33, -0.2, 0.0); // second row
	point_set3D(&p[5], 0.33, -0.2, 0.33);
	point_set3D(&p[6], 0.33, -0.2, 0.66);
	point_set3D(&p[7], 0.33, -0.2, 1.0);
	point_set3D(&p[8], 0.66, -0.2, 0.0); // third row
	point_set3D(&p[9], 0.66, -0.2, 0.33);
	point_set3D(&p[10], 0.66, -0.2, 0.66);
	point_set3D(&p[11], 0.66, -0.2, 1.0);
	point_set3D(&p[12], 1.0, -0.2, 0.0); // fourth row
	point_set3D(&p[13], 1.0, -0.2, 0.33);
	point_set3D(&p[14], 1.0, -0.2, 0.66);
	point_set3D(&p[15], 1.0, -0.2, 1.0);
	bezierSurface_set(&bc, p);

	// put the curve into a module
	module_color(curve, &red);
	module_bezierSurface(curve, &bc, divisions, 0);

	// create a curved surface sitting above the plane
	point_set3D(&p[0], 0.0, 0.0, 0.0); // first row, constant x, even spacing in z
	point_set3D(&p[1], 0.0, 0.2, 0.33);
	point_set3D(&p[2], 0.0, 0.5, 0.66);
	point_set3D(&p[3], 0.0, 0.1, 1.0);
	point_set3D(&p[4], 0.33, 0.8, 0.0); // second row
	point_set3D(&p[5], 0.33, -0.1, 0.33);
	point_set3D(&p[6], 0.33, 0.0, 0.66);
	point_set3D(&p[7], 0.33, 0.3, 1.0);
	point_set3D(&p[8], 0.66, 0.3, 0.0); // third row
	point_set3D(&p[9], 0.66, 0.8, 0.33);
	point_set3D(&p[10], 0.66, 0.9, 0.66);
	point_set3D(&p[11], 0.66, 0.5, 1.0);
	point_set3D(&p[12], 1.0, 0.4, 0.0); // fourth row
	point_set3D(&p[13], 1.0, 0.2, 0.33);
	point_set3D(&p[14], 1.0, 0.5, 0.66);
	point_set3D(&p[15], 1.0, 1.0, 1.0);
	bezierSurface_set(&bc, p);

	// put the curve into a module
	module_color(curve, &green);
	module_bezierSurface(curve, &bc, divisions, 1);

	// set up the drawstate
	drawstate_setColor(&ds, white);
	ds.shade = ShadeFrame;
	
	// set up the view
	point_set3D(&(view.vrp), 0.0, 1.2, -3.0 );
	vector_set( &(view.vpn), 0.0, -0.8, 2.5 );
	vector_set( &(view.vup), 0.0, 1.0, 0.0 );
	view.d = 1.5;
	view.du = 1.0;
	view.dv = 1.0*rows/cols;
	view.screeny = rows;
	view.screenx = cols;
	view.f = 0.0;
	view.b = 3.0;

	matrix_setView3D( &VTM, &view );
	matrix_identity( &GTM );

	// Create the animation by adjusting the GTM
	for(frame=0;frame<60;frame++) {
		char buffer[256];
		
		matrix_rotateY(&GTM, cos(M_PI/30.0), sin(M_PI/30.0) );
		module_draw( curve, &VTM, &GTM, &ds, NULL, src );

		sprintf(buffer, "bezSurf-frame%03d.ppm", frame);
		image_write(src, buffer);
		image_reset(src);
	}
	
	printf("converting to gif...\n");
	system("convert -delay 1.5 -loop 0 bezSurf-frame*.ppm bezSurf.gif");
	system("rm bezSurf-frame*.ppm");

	// clean up
	image_free( src );

	module_delete( curve );

	return(0);
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
	int i, frame;
	Color blue, green, purple, red, white;
	Point p[4];
	BezierCurve bc;
	DrawState ds;
	Module *curveA;
	Module *curveB;
	Module *curves;
	View3D view;
	Matrix VTM, GTM;
	int divisions = 4;
	int rows = 300, cols = 400;
	Image *src = image_create(rows, cols);

	// grab the command line argument, if one exists
	if(argc > 1) {
		int tmp = atoi(argv[1]);
		if( tmp >= 0 && tmp < 10 )
			divisions = tmp;
	}
	printf("Creating Bezier curves with %d subdivisions\n", divisions);

	color_set(&white, 1.0, 1.0, 1.0 );
	color_set(&blue, .1, .2, .8);
	color_set(&green, .2, 0.7, 0.3 );
	color_set(&purple, 0.6, 0.1, 0.7 );
	color_set(&red, 0.75, 0.3, 0.3 );

	// set one curve
	point_set3D(&p[0], 0.0, 0.0, 0.0);
	point_set3D(&p[1], 1.0, 0.2, 0.0);
	point_set3D(&p[2], 0.7, 0.5, 0.2);
	point_set3D(&p[3], 1.0, 1.0, 1.0);
	bezierCurve_set(&bc, p);

	// put the curve into a module
	curveA = module_create();
	module_color(curveA, &blue);
	module_bezierCurve(curveA, &bc, divisions);

	// set the second curve
	point_set3D(&p[0], 0.0, 0.0, 0.0);
	point_set3D(&p[1], 0.0, 0.2, 1.0);
	point_set3D(&p[2], 0.2, 0.5, 0.7);
	point_set3D(&p[3], 1.0, 1.0, 1.0);
	bezierCurve_set(&bc, p);

	// put the curve into a module
	curveB = module_create();
	module_color(curveB, &green);
	module_bezierCurve(curveB, &bc, divisions);

	// create a module with six curves
	curves = module_create();
	for(i=0;i<3;i++) {
		module_module( curves, curveA );
		module_module( curves, curveB );
		module_rotateY( curves, cos(2.0*M_PI/3.0), sin(2.0*M_PI/3.0) );
	}

	// set up the drawstate
	drawstate_setColor(&ds, white);

	// set up the view
	point_set3D(&(view.vrp), 0.0, 0.5, -3.0 );
	vector_set( &(view.vpn), 0.0, 0.0, 1.0 );
	vector_set( &(view.vup), 0.0, 1.0, 0.0 );
	view.d = 1.0;
	view.du = 1.0;
	view.dv = 1.0*rows/cols;
	view.screeny = rows;
	view.screenx = cols;
	view.f = 0.0;
	view.b = 3.0;

	matrix_setView3D( &VTM, &view );
	matrix_identity( &GTM );

	// Create the animation by adjusting the GTM
	for(frame=0;frame<60;frame++) {
		char buffer[256];
		
		matrix_rotateY(&GTM, cos(M_PI/30.0), sin(M_PI/30.0) );
		module_draw( curves, &VTM, &GTM, &ds, NULL, src );

		sprintf(buffer, "bez3d-frame%03d.ppm", frame);
		image_write(src, buffer);
		image_reset(src);
	}
	
	printf("converting to gif...\n");
	system("convert -delay 1.5 -loop 0 bez3d-frame*.ppm bez3d.gif");
	system("rm bez3d-frame*.ppm");

	// clean up
	image_free( src );

	module_delete( curveA );
	module_delete( curveB );
	module_delete( curves );

	return(0);
}