Example #1
0
void showsettings()
{
	char str[256];
	int xpos;

	ortho2(-0.5,xsize-0.5,-0.5,ysize-0.5);
	color(51);
	rectfi(0,0,xsize,2*SLIDERHIGH);
	color(0);
	sprintf(str,"Mass %g",curmass); 
	cmov2i(20,3+1*SLIDERHIGH);
	charstr(str);
	sprintf(str,"Drag %g",curdrag); 
	cmov2i(20,3+0*SLIDERHIGH);
	charstr(str);
	move2i(SLIDERLEFT,0);
	draw2i(SLIDERLEFT,2*SLIDERHIGH);
	move2i(0,1*SLIDERHIGH);
	draw2i(xsize,1*SLIDERHIGH);
	move2i(0,2*SLIDERHIGH);
	draw2i(xsize,2*SLIDERHIGH);
	color(1);
	xpos = SLIDERLEFT+curmass*(xsize-SLIDERLEFT);
	rectfi(xpos,1*SLIDERHIGH,xpos+4,2*SLIDERHIGH);
	xpos = SLIDERLEFT+curdrag*(xsize-SLIDERLEFT);
	rectfi(xpos,0*SLIDERHIGH,xpos+4,1*SLIDERHIGH);
	ortho2(0.0,1.25,0.0,1.0);
}
Example #2
0
void clearscreen()
{
	int x, y;

	ortho2(0.0,1.25,0.0,1.0);
	color(51);
	setpattern(0);
	clear();
	npolys = 0;
	showsettings();
	color(0);
}
static void
_dxf_SET_WORLD_SCREEN (void *ctx, int w, int h)
{
  /*
   *  set up a one-to-one mapping of world to screen
   */

  ENTRY(("_dxf_SET_WORLD_SCREEN(0x%x, %d, %d)",ctx, w, h));

  viewport (0, w-1, 0, h-1) ;
  ortho2 (-0.5, (float)w-0.5, -0.5, (float)h-0.5) ;
  loadmatrix(identity) ;

  EXIT((""));
}
Example #4
0
/*
 * display all the hershey fonts and demonstrate textang
 */
main()
{
	char	buf[50];
	char	*str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
	char	*str2 = "abcdefghijklmnopqrstuvwxyz" ;
	char	*str3 = "1234567890+-=!@#$%^&*(){}[]" ;
	char	*str4 = "<>,./?~`\\|_BONK,blark" ;
	int	i;
	short	val;

	vinit("mswin");
	winopen("circtxt");

	hleftjustify(1);

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);
	clear();

	ortho2(-14.0, 14.0, -14.0, 14.0);	/* define the world space */

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

		/*
		 * textang is used to specify the orientation of text. As
		 * we want the title to come out straight we make sure it is
		 * zero each time we go through this loop.
		 */
		htextang(0.0);

		/*
		 * do the title
		 */
		color(YELLOW);
		hfont("futura.m");
		sprintf(buf, "This is hershey font %s", fonts[i]);
		hboxtext(-11.0, 12.0, 20.0, 1.0, buf);

		/*
		 * draw a box around the title
		 */
		rect(-11.0, 12.0, 9.0, 13.0);

		color(GREEN);

		hfont(fonts[i]);		/* grab a font from the table */

		htextsize(1.5, 1.5);		/* show the outer ring */
		ShowCircularText(11.0, str1);

		htextsize(1.3, 1.3);		/* show the second ring */
		ShowCircularText(8.5, str2);

		htextsize(1.1, 1.1);		/* show the third ring */
		ShowCircularText(7.0, str3);

		htextsize(0.9, 0.9);		/* show the inside ring */
		ShowCircularText(5.0, str4);

		if (qread(&val)) {
			if (val == 'q') {
				gexit();
				exit(0);
			}
		}

		color(BLACK);
		clear();
	}

	gexit();
}
Example #5
0
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
void vDrawHelp()
{
 
  	float x = 0.0, y = 0.0, z = -10.0;
	float r_x = 0.0, r_y = 0.0, r_z = -10.0;
	float xang = 0.0, yang = 180.0, zang = 0.0;
	float wang = 0.0, bgang = 0.0;
	float lx = 0.0, ly = CHAN_Y/2.0 + 0.5, lz = -12.0;
	int st_time, titxang = 0;
   Matrix mat;
   long prev_mode;
   char str[30];
   fmfonthandle font1, font2;
	int len = strlen(Message);
	static i = 0;
	int j;
	float tmp;
	const int instr_num = 21;
	char mesg[21][100] =
	{
		"         View            Key",
		" ",
		  "        pilot           pad 7",
		  "        behind          pad 8",
		  "        behind-up       pad 4",
		  "        top             pad 5",
		" ",
		" ",
		"  Usage                               Key",
		" ",
      "                1st setting         2nd setting         3rd setting",
		" ",
		"downward        up arrow            down arrow          down arrow",
    	"upward          down arrow          up arrow            up arrow",
    	"leftward        left arrow          left arrow          left arrow",
    	"rightward       right arrow         right arrow         right arrow",
    	"left turn       pad number 2        pad number 0        akey",
    	"right turn      pad number 3        pad number period   skey",
    	"nitro           pad number 0        pad number 3        zkey",
    	"break           pad number period   pad number 2        xkey",
    	"fire            pad enter           pad enter           dkey",
	};


	#ifdef DOFF
		printf("draw help\n");
	#endif
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    

	glPushMatrix();

	gluLookAt(0.3, 1.0, -8.0, r_x, r_y, r_z, 0);
	setup_lig();
	vDrawLight(GL_LIGHT0, GL_LIGHT0, lx, ly, lz);
	vDrawBody(-8.2, 0.0, 0.0, 0.0, x,y,z, 0.0, 180.0, 0.0, 0.0);

	glPushMatrix();
	tmp = Speed;
	Speed = 0.0;
   	vDrawChannel(FALSE);
   	vDrawSqs();
	Speed = tmp;
	glPopMatrix();

	glPopMatrix();


    glPushMatrix();
   glLoadIdentity();
   prev_mode = glGetIntegerv(GL_MATRIX_MODE);
   glMatrixMode(GL_PROJECTION);
   glGetIntegerf(GL_PROJECTION_MATRIX, mat);;

    	glColor3fv(fBlueVec);
   		ortho2(-160, 160, -130, 130);
 
		for (j=0; j<instr_num; j++)
		{
   			cmov2(-150, 100-j*10);
   			charstr(mesg[j]);
		}
 
   glLoadMatrixf(mat);
   glMatrixMode(prev_mode);
   glPopMatrix();


    glutSwapBuffers();
    glFlush();
}
Example #6
0
/*
 * using curves
 */
main()
{
	char	dev[20];
	int	i;
	short	val;

	vinit("mswin");
	winopen("curves");

	qdevice(KEYBD);
	unqdevice(INPUTCHANGE);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	ortho2(-200.0, 400.0, -100.0, 500.0);

	color(BLACK);
	clear();

	color(YELLOW);

	/*
	 * label the control points in geom1
	 */
        for (i = 0; i < 4; i++) {
		cmov2(geom1[i][0], geom1[i][1]);
		sprintf(dev, "%d", i);
		charstr(dev);
	}
								 
	/*
	 * label the control points in geom2
	 */
	for (i = 0; i < 6; i++) {
		cmov2(geom2[i][0], geom2[i][1]);
		sprintf(dev, "%d", i);
		charstr(dev);
	}

	/*
	 * set the number of line segments appearing in each curve to 20
	 */
	curveprecision((short)20);

	/*
	 * copy the bezier basis matrix into the basis matrix stack and
	 * set the curve basis accordingly.
	 */
	defbasis((short)1, bezier);
	curvebasis((short)1);

	color(RED);

	/*
	 * draw a curve using the current basis matrix (bezier in this case)
	 * and the control points in geom1
	 */
	crv(geom1);

	cmov2(70.0, 60.0);
	charstr("Bezier Curve Segment");

	cmov2(-190.0, 450.0);
	charstr("Three overlapping Bezier Curves");

	/*
	 * crvn draws overlapping curve segments according to geom2, the
	 * number of curve segments drawn is three less than the number of
	 * points passed, assuming there are a least four points in the
	 * geometry matrix (in this case geom2). This call will draw 3
	 * overlapping curve segments in the current basis matrix - still
	 * bezier.
	 */
	crvn(6L, geom2);

	qread(&val);

	/*
	 * load in the cardinal basis matrix
	 */
	defbasis((short)1, cardinal);
	curvebasis((short)1);

	color(MAGENTA);

	cmov2(70.0, 10.0);
	charstr("Cardinal Curve Segment");

	/*
	 * plot out a curve segment using the cardinal basis matrix
	 */
	crv(geom1);

	cmov2(-190.0, 400.0);
	charstr("Three overlapping Cardinal Curves");

	/*
	 * now draw a bunch of them again.
	 */
	crvn(6L, geom2);

	qread(&val);

	/*
	 * change the basis matrix again
	 */
	defbasis((short)1, bspline);
	curvebasis((short)1);

	color(GREEN);

	cmov2(70.0, -40.0);
	charstr("Bspline Curve Segment");

	/*
	 * now draw our curve segment in the new basis...
	 */
	crv(geom1);

	cmov2(-190.0, 350.0);
	charstr("Three overlapping Bspline Curves");

	/*
	 * ...and do some overlapping ones
	 */
	crvn(6L, geom2);

	qread(&val);

	gexit();
}
Example #7
0
/*
 * 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);
}
Example #8
0
/*
 * a routine to demonstrate using locator.
 */
main()
{
	int		i, bt, act, nchars;
	short		data;
	Scoord		x, y, sx, sy;
	Screencoord	minx, maxx, miny, maxy;

	ginit();

	color(BLACK);
	clear();

	color(BLUE);

	getviewport(&minx, &maxx, &miny, &maxy);

	ortho2((Coord)minx, (Coord)maxx, (Coord)miny, (Coord)maxy);

	/*
	 * draw some axes
	 */
	move2s((Scoord)minx, (Scoord)((maxy - miny) / 2));
	draw2s((Scoord)maxx, (Scoord)((maxy - miny) / 2));

	move2s((Scoord)((maxx - minx) / 2), (Scoord)miny);
	draw2s((Scoord)((maxx - minx) / 2), (Scoord)maxy);

	color(GREEN);

	/*
	 * enable the left and middle mouse buttons
	 */
	unqdevice(INPUTCHANGE);
	qdevice(LEFTMOUSE);
	qdevice(MIDDLEMOUSE);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&data) != REDRAW)
		;

	act = 0;

	/*
	 * getvaluator tells us the valuator's value. In
	 * this case it's the X and Y positions of the mouse.
	 * Note: these come back to us in screen coordinates.
	 */
	while((bt = qread(&data)) != MIDDLEMOUSE) {
		sx = getvaluator(MOUSEX);
		sy = getvaluator(MOUSEY);
		if (bt == -1) {
			gexit();
			printf("No locator device found\n");
			exit(0);
		} else {
			if (act) {
				act = 0;
				move2s(sx, sy);
				draw2s(x, y);
			} else {
				act = 1;
				x = sx;
				y = sy;
			}
		}
		(void)qread(&data);	/* swallow the up event */
	}

	gexit();

}
Example #9
0
main()
{
    float ship[XY];
    long org[XY];
    long size[XY];
    Device dev;
    short val;
    Device mdev[XY];
    short mval[XY];
    long nhits;
    short buffer[BUFSIZE];
    Boolean run;

    prefsize(400, 400);
    winopen("select1");
    getorigin(&org[X], &org[Y]);
    getsize(&size[X], &size[Y]);
    mmode(MVIEWING);
    ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);
    qdevice(LEFTMOUSE);
    qdevice(ESCKEY);
    color(BLACK);
    clear();
    mdev[X] = MOUSEX;
    mdev[Y] = MOUSEY;

    drawplanet();
    run = TRUE;
    while (run) {
	dev = qread(&val);
	if (val == 0) {				/* on upstroke */
	    switch (dev) {
	    case LEFTMOUSE:
		getdev(XY, mdev, mval);
		ship[X] = mval[X] - org[X];
		ship[Y] = mval[Y] - org[Y];
		color(BLUE);
		sbox(ship[X], ship[Y], 
		     ship[X] + SHIPWIDTH, ship[Y] + SHIPHEIGHT);

		/*
		 * specify the selecting region to be a box surrounding the
		 * rocket ship 
		 */
		ortho2(ship[X], ship[X] + SHIPWIDTH, 
		       ship[Y], ship[Y] + SHIPHEIGHT);

		initnames();
		gselect(buffer, BUFSIZE);
		    loadname(PLANET);
		    /* no actual drawing takes place */
		    drawplanet();
		nhits = endselect(buffer);

		/*
		 * restore the Projection matrix; NB. can't use push/popmatrix 
		 * since they only work for the ModelView matrix stack 
		 * when in MVIEWING mode
		 */
		ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);

		/* 
		 * check to see if PLANET was selected; NB. nhits is NOT the
		 * number of buffer elements written
		 */
		if (nhits < 0) {
		    fprintf(stderr, "gselect buffer overflow\n");
		    run = FALSE;
		} 
		else if (nhits >= 1 && buffer[0] == 1 && buffer[1] == PLANET)
		    ringbell();
		break;
	    case ESCKEY:
		run = FALSE;
		break;
	    }
	}
    }
    gexit();
    return 0;
}
Example #10
0
/*
 *	Shows various combinations of viewing and
 *	projection transformations.
 */
main()
{
	char device[20];

	fprintf(stderr,"Enter device name: ");
	gets(device);
	vinit(device);

	color(BLACK);
	clear();

	/*
	 * we want to draw just within the boundaries of the screen
	 */
	viewport(-0.9, 0.9, -0.9, 0.9);


	ortho2(-5.0, 5.0, -5.0, 5.0);	/* set the world size */

	color(RED);
	rect(-5.0, -5.0, 5.0, 5.0);	/* draw a boundary frame */

	/*
	 * set up a perspective projection with a field of view of
	 * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1,
	 * and the far clipping plane at 1000.0.
	 */
	perspective(40.0, 1.0, 0.1, 1000.0);

	/*
	 * we want the drawing to be done with our eye point at (5.0, 8.0, 5.0)
	 * looking towards (0.0, 0.0, 0.0). The last parameter gives a twist
	 * in degrees around the line of sight, in this case zero.
	 */
	lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);

	drawtetra();

	move2(-4.5, -4.5);
	textsize(0.6, 0.9);		/* set the text size */
	drawstr("perspective/lookat");

	getkey();

	/*
	 * window can also be used to give a perspective projection. Its
	 * arguments are 6 clipping planes, left, right, bottom, top, near,
	 * and far.
	 */
	window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
	/*
	 * as window replaces the current transformation matrix we must
	 * specify our viewpoint again.
	 */
	lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);

	color(BLACK);
	clear();

	color(GREEN);
	rect(-5.0, -5.0, 5.0, 5.0);

	drawtetra();

	move2(-4.5,-4.5);
	textsize(0.6, 0.9);		/* set the text size */
	drawstr("window/lookat");

	getkey();

	/*
	 * set up our original perspective projection again.
	 */
	perspective(40.0, 1.0, 0.1, 1000.0);
	/*
	 * polarview also specifies our viewpoint, but, unlike lookat, in polar
	 * coordinates. Its arguments are the distance from the world origin, an
	 * azimuthal angle in the x-y plane measured from the y axis, an 
	 * incidence angle in the y-z plane measured from the z axis, and a
	 * twist around the line of sight.
	 */
	polarview(15.0, 30.0, 30.0, 30.0);

	color(BLACK);
	clear();

	color(MAGENTA);
	rect(-5.0, -5.0, 5.0, 5.0);

	drawtetra();

	move2(-4.5,-4.5);
	textsize(0.6, 0.9);		/* set the text size */
	drawstr("perspective/polarview");

	getkey();

	/*
	 * once more with window for comparison
	 */
	window(-4.0, 4.0, -4.0, 4.0, -4.0, 4.0);
	polarview(6.0, 20.0, -30.0, 70.0);

	color(BLACK);
	clear();

	color(YELLOW);
	rect(-5.0, -5.0, 5.0, 5.0);

	drawtetra();

	move2(-4.5,-4.5);
	textsize(0.6, 0.9);		/* set the text size */
	drawstr("window/polarview");

	getkey();

	vexit();
}