コード例 #1
0
void make_shape(Shape *vert)
{
	
    double	ray = 1; // radius
	int height = 1; // height
	double torus_radius = 1.2; // radius from origin to center of tube
	double tube_radius = 0.2; // tube radius
	GLfloat p0[3] = {0,0,0};
	GLfloat p1[3] = {0,1,0};
	theLine.type = LINE;
	
	float l1 = 1.0;
	float l2 = 0.75;
	float l3 = 0.50;
	
	switch(vert->type)
	{
		case HOUSE:
			make_house(vert);break;
		case SPHERE:
			make_sphere(vert, ray); break;
		case CYLINDER:
			make_cylinder(vert, ray, height); break;
		case CONE:
			make_cone(vert, height, ray); break;
		case TORUS:
			make_torus(vert,torus_radius, tube_radius); break;
		case CUBE:
			make_cube_smart(vert, 2); break;
		case LINE:
			make_line(vert, p0, p1);
		case SUPER:
			make_quadric(vert, l1, l2, l3);
	}	
}
コード例 #2
0
ファイル: glmain.c プロジェクト: Choino/school
void parse_obj(char *buffer){
	OBJECT *po;
	char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate;
	
	my_assert ((num_objects < NUM_OBJECTS), "too many objects");
	po = &my_objects[num_objects++];
	
	pshape  = strtok(buffer, " ");
	//printf("pshape is %s\n",pshape);
	
	ptranslate    = strtok(NULL, "()");  strtok(NULL, "()");
	pscale        = strtok(NULL, "()");  strtok(NULL, "()"); 
	protate       = strtok(NULL, "()");  strtok(NULL, "()");  
	
	pshine  = strtok(NULL, "()");strtok(NULL, "()");
	//printf("pshine is %s\n",pshine);
	
	pemi    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pamb    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pdiff   = strtok(NULL, "()");  strtok(NULL, "()"); 
	pspec   = strtok(NULL, "()");  strtok(NULL, "()"); 
	
	po->sid  = atoi(pshape);
	printf("%d",po->sid);
	po->shine = atof(pshine);
	
	parse_floats(ptranslate, po->translate);
	parse_floats(pscale, po->scale);
	parse_floats(protate, po->rotate);
	
	parse_floats(pemi, po->emi);
	parse_floats(pamb, po->amb);
	parse_floats(pdiff, po->diff);
	parse_floats(pspec, po->spec);
	
	// use switch to create your objects, cube given as example
	switch (po->sid){
		case 0: // makes house
			make_house(po);
			break;
		case 1: //cube
			make_cube_smart(po, 1);
			break;
		case 2:
			make_sphere(po, 1);
			break;
		case 3:
			make_cone(po, 1, 1);
			break;
		case 4:
			make_torus(po, 1.2, .1);
			break;
	}
	
	// scale, rotate, translate using your real tranformations from assignment 3 depending on input from spec file
	
	real_scaling(po, po->scale[0], po->scale[1], po->scale[2]);  
	real_rotation(po, po->rotate[0], 1, 0, 0);
	real_rotation(po, po->rotate[1], 0, 1, 0);
	real_rotation(po, po->rotate[2], 0, 0, 1);
	real_translation(po, po->translate[0], po->translate[1], po->translate[2]);
	
	printf("read object\n");
}