/* * 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(); }
/* Transform body normals, draw front */ void drawbody(Matrix Rot) { double bodyScale = 1.0/theBodyRadius; register int i, j, k, n; pushmatrix(); scale(bodyScale, bodyScale, bodyScale); for (j=0; j<bodyNFaces; j++) { double dot = Rot[X][Z]*theFaceNormals[j][X] +Rot[Y][Z]*theFaceNormals[j][Y] +Rot[Z][Z]*theFaceNormals[j][Z]; if (dot>0.0) { /* Front-facing polygon, so draw it */ short shadedColor[3]; dot += 0.4; if (dot>1.0) dot = 1.0; shadedColor[0] = dot*theFaceColors[j][0]; shadedColor[1] = dot*theFaceColors[j][1]; shadedColor[2] = dot*theFaceColors[j][2]; n = theFaceVertices[j][0]; RGBcolor(shadedColor[0], shadedColor[1], shadedColor[2]); bgnpolygon(); for (k=1; k<=n; k++) { i = theFaceVertices[j][k]; v4f(thePoints[i]); } endpolygon(); } } popmatrix(); }
void R4Matrix:: Pop(void) const { // Pop top of stack #if (RN_3D_GRFX == RN_IRISGL) popmatrix(); #elif (RN_3D_GRFX == RN_OPENGL) glPopMatrix(); #elif (RN_3D_GRFX == RN_3DR) G3dPopTransform(R3dr_gc); #else RNAbort("Not Implemented"); #endif }
main() { char dev[20]; int i; fprintf(stderr,"Enter device: "); gets(dev); vinit(dev); color(BLACK); clear(); /* * Set up two viewports (They actually overlap) */ viewport(-1.0, 0.3, -1.0, 0.3); ortho(-2.0, 5.0, -2.0, 5.0, -2.0, 5.0); lookat(0.0, 0.0, 0.0, -3.0, 2.0, -4.0, 0.0); /* * Save it */ pushviewport(); pushmatrix(); viewport(-0.3, 1.0, -0.3, 1.0); ortho(-2.0, 5.0, -2.0, 5.0, -2.0, 5.0); lookat(0.0, 0.0, 0.0, 3.0, 2.0, -4.0, 0.0); textsize(0.4, 0.4); /* * patchcurves provides a number of curves in the t and u * directions. patchprecision gives the minimum number of line * segments making up the curves in the t and u directions. The * actual number of linesegments in t or u is equal to the closest * integer multiple of the number of curves, > nsegs, in t or u, * greater than or equal to the number set by patchprecision in u or * t. eg. curves in t will be made up of 21 line segments so that we * can match up the 7 curves in u; curves in u will have 24 as 4 by 5 * gives 20. */ patchcurves(4, 7); patchprecision(20, 20); for (i = 0; i < 4; i++) { axes(); /* * patchbasis sets the basis matrices for the t and u * functions * */ patchbasis(basis[i], basis[i]); /* * Draw with viewport 2 */ move(0.0, 4.0, 0.0); drawstr(labels[i]); /* * now draw the patches according to the geometry matrices in * x1, y1, and z1, x2, y2, z2. */ drawhull(x1, y1, z1); patch(x1, y1, z1); drawhull(x2, y2, z2); patch(x2, y2, z2); getkey(); /* * Now with viewport 1 */ popviewport(); popmatrix(); axes(); move(0.0, 4.0, 0.0); drawstr(labels[i]); /* * now draw the patches according to the geometry matrices in * x1, y1, and z1, x2, y2, z2. */ drawhull(x1, y1, z1); patch(x1, y1, z1); drawhull(x2, y2, z2); patch(x2, y2, z2); getkey(); /* * Save viewport 1 again and reset to viewport 2 */ pushviewport(); pushmatrix(); viewport(-0.3, 1.0, -0.3, 1.0); ortho(-1.5, 5.0, -1.5, 5.0, -1.5, 5.0); lookat(0.0, 0.0, 0.0, 3.0, 2.0, -4.0, 0.0); color(BLACK); clear(); } vexit(); }
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(); }
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: ; } } } }
main() { int i, itest, dobackface, dofill, dodouble; char buf[100]; float H; short idata; int xr, yr; vinit("mswin"); winopen("piston"); /* * Wait for REDRAW event ... */ while (qread(&idata) != REDRAW) ; doublebuffer(); gconfig(); unqdevice(INPUTCHANGE); qdevice(QKEY); qdevice(FKEY); qdevice(BKEY); qdevice(ESCKEY); qdevice(REDRAW); makecyl(); polymode(PYM_FILL); backface(1); /* * 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(400, 1.5, 0.1, 600.0); lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0); /* * here we loop back here adnaseum until someone hits a key */ xr = yr = 0; while(1) { for (i = 0; i < 360; i += 5) { color(BLACK); clear(); color(RED); H = 1.0 + cos(2.0 * 3.14159265*i / 180.0); yr = 500 - (int)getvaluator(MOUSEY); xr = 500 - (int)getvaluator(MOUSEX); yr = 500 - (int)getvaluator(MOUSEY); xr *= 3; yr *= 3; pushmatrix(); rotate(xr, 'x'); rotate(yr, 'y'); piston(H); popmatrix(); if (dodouble) swapbuffers(); if (qtest()) { itest = qread(&idata); itest = qread(&idata); /* Zap Up event */ if (itest == BKEY) { dobackface = !dobackface; backface(dobackface); } else if (itest == FKEY) { dofill = !dofill; if (dofill) polymode(PYM_FILL); else polymode(PYM_LINE); } else if(itest == QKEY || itest == ESCKEY) { gexit(); exit(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); }
static void _dxf_DRAW_GNOMON (tdmInteractor I, void *udata, float rot[4][4], int draw) { /* * draw == 1 to draw gnomon, draw == 0 to undraw. This is done with * two separate calls in order to support explicit erasure of edges for * some implementations. A draw is always preceded by an undraw and * the pair of invocations is atomic. * * Computations are done in normalized screen coordinates in order to * render arrow heads correctly. */ DEFDATA(I,tdmRotateData) ; DEFPORT(I_PORT_HANDLE) ; int dummy = 0 ; float origin[2] ; float xaxis[2], yaxis[2], zaxis[2] ; float xlabel[2], ylabel[2], zlabel[2] ; ENTRY(("_dxf_DRAW_GNOMON (0x%x, 0x%x, 0x%x, %d)",I, udata, rot, draw)); if (PDATA(font) == -1) { /* font width for axes labels in normalized coordinates */ font(0) ; PDATA(font) = 0 ; PDATA(swidth) = (float)strwidth("Z")/(float)GNOMONRADIUS ; /* 1 pixel in normalized coordinates */ PDATA(nudge) = 1.0/(float)GNOMONRADIUS ; } else font(PDATA(font)) ; if (draw) { lmcolor(LMC_COLOR) ; cpack(0xffffffff) ; linewidth(1) ; } else { if (PDATA(redrawmode) != tdmViewEchoMode) { /* * In tdmViewEchoMode (DX's Execute On Change), we are drawing * the gnomon echo on top of a background image that is redrawn * with every frame of a direct interaction. * * If we're not in that mode, the background image is static * while the gnomon echo rotates in front of it, so erasing the * gnomon means we have to repair damage to the background. We * do this by blitting a portion of the static image to the * back buffer, drawing the gnomon over that, then blitting the * combined results back to the front buffer. */ /* force graphics output into back buffer */ frontbuffer(FALSE) ; backbuffer(TRUE) ; /* erase gnomon background */ lrectwrite (PDATA(illx), PDATA(illy), PDATA(iurx), PDATA(iury), PDATA(background)) ; } #ifndef NOSHADOW /* draw wide black lines to ensure visibility against background */ lmcolor(LMC_COLOR) ; cpack(0x0) ; linewidth(2) ; #else EXIT(("No shadow")); return ; #endif } origin[0] = 0 ; origin[1] = 0 ; xaxis[0] = 0.7 * rot[0][0] ; xaxis[1] = 0.7 * rot[0][1] ; yaxis[0] = 0.7 * rot[1][0] ; yaxis[1] = 0.7 * rot[1][1] ; zaxis[0] = 0.7 * rot[2][0] ; zaxis[1] = 0.7 * rot[2][1] ; xlabel[0] = 0.8 * rot[0][0] ; xlabel[1] = 0.8 * rot[0][1] ; ylabel[0] = 0.8 * rot[1][0] ; ylabel[1] = 0.8 * rot[1][1] ; zlabel[0] = 0.8 * rot[2][0] ; zlabel[1] = 0.8 * rot[2][1] ; pushmatrix() ; loadmatrix(identity) ; bgnline() ; v2f(origin) ; v2f(xaxis) ; endline() ; _dxf_DRAW_ARROWHEAD(PORT_CTX, xaxis[0], xaxis[1]) ; bgnline() ; v2f(origin) ; v2f(yaxis) ; endline() ; _dxf_DRAW_ARROWHEAD(PORT_CTX, yaxis[0], yaxis[1]) ; bgnline() ; v2f(origin) ; v2f(zaxis) ; endline() ; _dxf_DRAW_ARROWHEAD(PORT_CTX, zaxis[0], zaxis[1]) ; if (xlabel[0] <= 0) xlabel[0] -= PDATA(swidth) ; if (xlabel[1] <= 0) xlabel[1] -= PDATA(swidth) ; if (ylabel[0] <= 0) ylabel[0] -= PDATA(swidth) ; if (ylabel[1] <= 0) ylabel[1] -= PDATA(swidth) ; if (zlabel[0] <= 0) zlabel[0] -= PDATA(swidth) ; if (zlabel[1] <= 0) zlabel[1] -= PDATA(swidth) ; #ifndef NOSHADOW if (!draw) { /* offset text slightly for shadow */ xlabel[0] += PDATA(nudge) ; xlabel[1] -= PDATA(nudge) ; ylabel[0] += PDATA(nudge) ; ylabel[1] -= PDATA(nudge) ; zlabel[0] += PDATA(nudge) ; zlabel[1] -= PDATA(nudge) ; } #endif font(0) ; cmov2 (xlabel[0], xlabel[1]) ; charstr ("X") ; cmov2 (ylabel[0], ylabel[1]) ; charstr ("Y") ; cmov2 (zlabel[0], zlabel[1]) ; charstr ("Z") ; popmatrix() ; if (draw && PDATA(redrawmode) != tdmViewEchoMode) { /* copy rendered gnomon from back buffer to front buffer */ readsource(SRC_BACK) ; frontbuffer(TRUE) ; backbuffer(FALSE) ; rectcopy (PDATA(illx), PDATA(illy), PDATA(iurx), PDATA(iury), PDATA(illx), PDATA(illy)) ; /* restore original buffer config from current tdmFrontBufferDraw */ _dxf_BUFFER_RESTORE_CONFIG (PORT_CTX, dummy, PDATA(buffermode), tdmFrontBufferDraw) ; } EXIT(("")); }