コード例 #1
0
ファイル: lcube.c プロジェクト: Milkyway-at-home/nemo
main()
{
        char    *p;
	float	tdir = TRANS;
	float	scal = 1.0 + SCAL;
	int	but, nplanes;
	int	x, y, i, n;
	short	val;
	int	bf = 1;
	int	fill = 1;

	prefsize(500L, 500L);

	vinit("mswin");
	winopen("lcube");

	unqdevice(INPUTCHANGE);
	qdevice(SKEY);
	qdevice(XKEY);
	qdevice(YKEY);
	qdevice(ZKEY);
	qdevice(EQUALKEY);
	qdevice(MINUSKEY);
	qdevice(ESCKEY);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;
	

	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);

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

	makecubes(1);

	backface(1);
		
	doublebuffer();
	gconfig();

	/*
	 * Doublebuffer does a backbuffer(TRUE)....
	 */

	while(1) {
		x = 500 - (int)getvaluator(MOUSEX);
		y = 500 - (int)getvaluator(MOUSEY);
		x *= 3;
		y *= 3;
		pushmatrix();
			rotate(x, 'y');
			rotate(y, 'x');
			color(BLACK);
			clear();
			callobj((Object)3);
			if (nplanes == 1)
				callobj((Object)2);
		popmatrix();
		swapbuffers();

		if (qtest()) {
			but = qread(&val);
			but = qread(&val);	/* swallow up event */

			switch (but) {

			case SKEY:
				scale(scal, scal, scal);
				break;
			case XKEY:
				translate(tdir, 0.0, 0.0);
				break;
			case YKEY:
				translate(0.0, tdir, 0.0);
				break;
			case ZKEY:
				translate(0.0, 0.0, tdir);
				break;
			case MINUSKEY:
				tdir = -tdir;

				if (scal < 1.0)
					scal = 1.0 + SCAL;
				else
					scal = 1.0 - SCAL;

				break;
			case EQUALKEY:
				tdir = TRANS;
				break;
			case BKEY:
				bf = !bf;
				backface(bf);
				break;
			case FKEY:
				fill = !fill;
				if (fill)
					polymode(PYM_FILL);
				else
					polymode(PYM_LINE);
				break;
			case ESCKEY:
			case QKEY:
				gexit();
				exit(0);
			default:
				;
			}
		}
	}
}
コード例 #2
0
ファイル: lcube.c プロジェクト: mooseman/Vogle
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();
}
コード例 #3
0
ファイル: balls.c プロジェクト: Milkyway-at-home/nemo
/*
 * a demonstration of objects
 */
draw_balls()
{
	if (!inited) {
		inited = 1;
		/*
		 * set up our viewing transformation
		 */
		perspective(900, 1.0, 0.001, 500.0);
		lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);

		/*
		 * Call a routine to make the sphere object
		 */
		makesphere();
		hfont("times.rb");
	}

	/*
	 * Now draw the sphere object scaled down. We use the pushmatrix
	 * and the popmatrix to preserve the transformation matrix so
	 * that only this sphere is drawn scaled.
	 */
	color(CYAN);

	pushmatrix();
		scale(0.5, 0.5, 0.5);
		callobj(SPHERE);
	popmatrix();

	/*
	 * now we draw the same sphere translated, with a different
	 * scale and color.
	 */

	color(WHITE);

	pushmatrix();
		translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
		scale(0.3, 0.3, 0.3);
		callobj(SPHERE);
	popmatrix();

	/*
	 * and maybe a few more times....
	 */


	color(RED);

	pushmatrix();
		translate(0.0, RADIUS, 0.7 * RADIUS);
		scale(0.2, 0.2, 0.2);
		callobj(SPHERE);
	popmatrix();

	color(GREEN);

	pushmatrix();
		translate(0.0, 1.5 * RADIUS, -RADIUS);
		scale(0.15, 0.15, 0.15);
		callobj(SPHERE);
	popmatrix();

	color(YELLOW);

	pushmatrix();
		translate(0.0, -RADIUS, -RADIUS);
		scale(0.12, 0.12, 0.12);
		callobj(SPHERE);
	popmatrix();

	color(BLUE);

	pushmatrix();
		translate(0.0, -2.0*RADIUS, -RADIUS);
		scale(0.3, 0.3, 0.3);
		callobj(SPHERE);
	popmatrix();

	ortho2(0.0, 1.0, 0.0, 1.0);
	hcentertext(1);
	htextsize(0.08, 0.15);
	move2(0.8, 0.5);
	htextang(-90.0);
	hcharstr("I'm very ordinary!");
	perspective(900, 1.0, 0.001, 500.0);
	lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);
}