Exemple #1
0
/*
 * makesphere
 *
 *	make a sphere object
 */
makesphere()
{
	float	r, z;
	int	i, a;

	makeobj(SPHERE);

		/*
		 * create the latitudinal rings
		 */
		for (i = 0; i < 1800; i += 200) {
			pushmatrix();
				rotate(i, 'y');
				circ(0.0, 0.0, RADIUS);
			popmatrix();
		}
		
		/*
		 * create the longitudinal rings
		 */
		pushmatrix();
			rotate(900, 'x');
			for (a = -900; a < 900; a += 200) {
				r = RADIUS * cos((double)a * PI / 180.0);
				z = RADIUS * sin((double)a * PI / 180.0);
				pushmatrix();
					translate(0.0, 0.0, -z);
					circ(0.0, 0.0, r);
				popmatrix();	
			}
		popmatrix();
	closeobj();

}
Exemple #2
0
main()
{
        char    device[10], *p;
	float	x, y, tdir = TRANS;
	int	but, nplanes;
	int	i, n;
	char	buf[10][128];

	fprintf(stderr,"Enter output device: ");
	gets(device);

	prefposition(50, 50);

	vinit(device);

	window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
	lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0.0);


	makeobj(1);
		makepoly();
			rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
		closepoly();
	closeobj();

	if ((nplanes = getdepth()) == 1)
		makecubes(0);

	makecubes(1);

	backface(1);
		
	if (backbuffer() < 0) {
		vexit();
		fprintf(stderr, "lcube: device doesn't support double buffering.\n"); 
		exit(0); 
	}        

	while((but = slocator(&x, &y)) != 44) {
		pushmatrix();
			rotate(100.0 * x, 'y');
			rotate(100.0 * y, 'x');
			color(BLACK);
			clear();
			callobj(3);
			if (nplanes == 1)
				callobj(2);
		popmatrix();
		swapbuffers();

		switch (but = checkkey()) {
		case 'x':
			translate(tdir, 0.0, 0.0);
			break;
		case 'y':
			translate(0.0, tdir, 0.0);
			break;
		case 'z':
			translate(0.0, 0.0, tdir);
			break;
		case '-':
			tdir = -tdir;
			break;
		case '+':
			tdir = TRANS;
			break;
		case 27: /* ESC */
		case 'q':
			vexit();
			exit(0);
		default:
			;
		}
	}

	vexit();
}
Exemple #3
0
void FSM_simulate(char *str)
{
	FILE *fp;
	fp=fopen(str,"r");
	if(fp == NULL)
		exit(0);
	int input_type;
	int prev_val=0,val,index,offset,size;
	int curr_state = N;	
	char ch = getc(fp),flag;
	while( !feof(fp) )
	{
		int ascii_val = (int)ch;
		if(ascii_val>=48 && ascii_val<=57)
		{
			val = ascii_val - 48;			
			input_type = NUM;
		}
		else if(ch == 'Y' || ch== 'N')
			input_type = CH;
		else if(ascii_val==44)
			input_type = COM;
		else if(ascii_val==10)
			input_type = CR;
		else
			input_type = ERR;
		switch(input_type)
		{
			case NUM :
			{
				if(curr_state == N)
				{
					curr_state = N;
					prev_val = prev_val*10 + val;
				}
				else if(curr_state == I)
				{
					curr_state = I;
					prev_val = prev_val*10 + val;
				}
				else if(curr_state == II)
				{
					curr_state = II;
					prev_val = prev_val*10 + val;
				}
				break;
			}
			case COM :
			{
				if(curr_state == N)
				{
					curr_state = I;
					index = prev_val;
					prev_val =0;
				}
				else if(curr_state == I)
				{
					curr_state = II;
					offset = prev_val;
					prev_val =0;
				}
				else if(curr_state == II)
				{
					curr_state = III;
					size = prev_val;
					prev_val =0;
				}
				else
					error();
				break;
			}
			case CH:
			{
				if(curr_state == III )
				{
					curr_state = IV;
					flag = ch;
				}
				else
					error();
				break;
			}
			case CR :
			{
				if(curr_state == IV)
				{
					makeobj(index,offset,size,flag);
					curr_state = N;
					break;
				}
				else 
					error();
				break;
			}
			case ERR:
				error();				
		}
		ch=getc(fp);
	}	
	fclose(fp);
}