home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglw.zip / draw.c < prev    next >
C/C++ Source or Header  |  1997-02-13  |  5KB  |  307 lines

  1. #include <stdio.h>
  2. #include "vogl.h"
  3.  
  4. static int    sync;
  5.  
  6. /*
  7.  * draw
  8.  *
  9.  * draw a line form the logical graphics position to the
  10.  * the world coordinates x, y, z.
  11.  *
  12.  */
  13. void
  14. draw(x, y, z)
  15.     float        x, y, z;
  16. {
  17.     Token    *tok;
  18.     int    vx, vy;
  19.     Vector    res;
  20.  
  21.  
  22.     if (!vdevice.initialised)
  23.         verror("draw: vogl not initialised");
  24.  
  25.     if (vdevice.inobject) {
  26.         tok = newtokens(4);
  27.  
  28.         tok[0].i = DRAW;
  29.         tok[1].f = x;
  30.         tok[2].f = y;
  31.         tok[3].f = z;
  32.  
  33.         vdevice.cpW[V_X] = x;
  34.         vdevice.cpW[V_Y] = y;
  35.         vdevice.cpW[V_Z] = z;
  36.  
  37.         vdevice.cpVvalid = 0;
  38.  
  39.         return;
  40.     }
  41.  
  42.     if (!vdevice.cpVvalid)
  43.         multvector(vdevice.cpWtrans, vdevice.cpW, vdevice.transmat->m);
  44.  
  45.     vdevice.cpW[V_X] = x;
  46.     vdevice.cpW[V_Y] = y;
  47.     vdevice.cpW[V_Z] = z;
  48.     multvector(res, vdevice.cpW, vdevice.transmat->m);
  49.  
  50.     if (vdevice.clipoff) {    
  51.         vx = WtoVx(res);        /* just draw it */
  52.         vy = WtoVy(res);
  53.      
  54.         (*vdevice.dev.Vdraw)(vx, vy);
  55.  
  56.         vdevice.cpVx = vx;
  57.         vdevice.cpVy = vy;
  58.  
  59.         vdevice.cpVvalid = 0;
  60.     } else {
  61.         if (vdevice.cpVvalid)
  62.             quickclip(vdevice.cpWtrans, res);
  63.         else
  64.             clip(vdevice.cpWtrans, res);
  65.     }
  66.  
  67.     vdevice.cpWtrans[V_X] = res[V_X];
  68.     vdevice.cpWtrans[V_Y] = res[V_Y];
  69.     vdevice.cpWtrans[V_Z] = res[V_Z];
  70.     vdevice.cpWtrans[V_W] = res[V_W];
  71. }
  72.  
  73. /*
  74.  * draws
  75.  *
  76.  * draw a line form the logical graphics position to the
  77.  * the world coordinates x, y, z expressed as a short integer data type.
  78.  *
  79.  */
  80. void
  81. draws(x, y, z)
  82.     Scoord     x, y, z;
  83. {
  84.     draw((Coord)x, (Coord)y, (Coord)z);
  85. }
  86.  
  87.  
  88. /*
  89.  * drawi
  90.  *
  91.  * draw a line form the logical graphics position to the
  92.  * the world coordinates x, y, z expressed as an integer data type.
  93.  *
  94.  */
  95. void
  96. drawi(x, y, z)
  97.     Icoord     x, y, z;
  98. {
  99.     draw((Coord)x, (Coord)y, (Coord)z);
  100. }
  101.  
  102.  
  103.  
  104. /*
  105.  * draw2
  106.  *
  107.  * draw a line from the logical graphics position  to the
  108.  * the world coordinates x, y.
  109.  *
  110.  */
  111. void
  112. draw2(x, y)
  113.     float        x, y;
  114. {
  115.     if (!vdevice.initialised)
  116.         verror("draw2: vogl not initialised");
  117.  
  118.     draw(x, y, 0.0);
  119. }
  120.  
  121. /*
  122.  * draw2s
  123.  *
  124.  * draw a line from the logical graphics position  to the
  125.  * the world coordinates x, y expressed as a short integer data type.
  126.  *
  127.  */
  128. void
  129. draw2s(x, y)
  130.     Scoord     x, y;
  131. {
  132.     draw2((Coord)x, (Coord)y);
  133. }
  134.  
  135.  
  136. /*
  137.  * draw2i
  138.  *
  139.  * draw a line from the logical graphics position  to the
  140.  * the world coordinates x, y expressed as an integer data type.
  141.  *
  142.  */
  143. void
  144. draw2i(x, y)
  145.     Icoord     x, y;
  146. {
  147.     draw2((Coord)x, (Coord)y);
  148. }
  149.  
  150. /*
  151.  * rdr
  152.  *
  153.  * 3D relative draw from the logical graphics position by dx, dy, dz.
  154.  * This is the same as the VOGLE routine rdraw.
  155.  *
  156.  */
  157. void
  158. rdr(dx, dy, dz)
  159.     float        dx, dy, dz;
  160. {
  161.     if (!vdevice.initialised) 
  162.         verror("rdr: vogl not initialised");
  163.  
  164.     draw((vdevice.cpW[V_X] + dx), (vdevice.cpW[V_Y] + dy), (vdevice.cpW[V_Z] + dz));
  165. }
  166.  
  167. /*
  168.  * rdrs
  169.  *
  170.  * 3D relative draw from the logical graphics position by dx, dy, dz
  171.  * expressed as a short integer data type.
  172.  *
  173.  */
  174. void
  175. rdrs(dx, dy, dz)
  176.     Scoord    dx, dy, dz;
  177. {
  178.     rdr((Coord)dx, (Coord)dy, (Coord)dz);
  179. }
  180.  
  181. /*
  182.  * rdri
  183.  *
  184.  * 3D relative draw from the logical graphics position by dx, dy, dz
  185.  * expressed as an integer data type.
  186.  *
  187.  */
  188. void
  189. rdri(dx, dy, dz)
  190.     Icoord    dx, dy, dz;
  191. {
  192.     rdr((Coord)dx, (Coord)dy, (Coord)dz);
  193. }
  194.  
  195.  
  196. /*
  197.  * rdr2
  198.  *
  199.  * 2D relative draw from the logical graphics position by dx, dy.
  200.  * This is the same as the VOGLE routine rdraw2.
  201.  *
  202.  */
  203. void
  204. rdr2(dx, dy)
  205.     float        dx, dy;
  206. {
  207.     if (!vdevice.initialised) 
  208.         verror("rdr2: vogl not initialised");
  209.  
  210.     draw((vdevice.cpW[V_X] + dx), (vdevice.cpW[V_Y] + dy), 0.0);
  211. }
  212.  
  213.  
  214. /*
  215.  * rdr2s
  216.  *
  217.  * 3D relative draw from the logical graphics position by dx, dy
  218.  * expressed as a short integer data type.
  219.  *
  220.  */
  221. void
  222. rdr2s(dx, dy)
  223.     Scoord    dx, dy;
  224. {
  225.     rdr2((Coord)dx, (Coord)dy);
  226. }
  227.  
  228. /*
  229.  * rdr2i
  230.  *
  231.  * 3D relative draw from the logical graphics position by dx, dy
  232.  * expressed as an integer data type.
  233.  *
  234.  */
  235. void
  236. rdr2i(dx, dy)
  237.     Icoord    dx, dy;
  238. {
  239.     rdr2((Coord)dx, (Coord)dy);
  240. }
  241.  
  242.  
  243. /*
  244.  * bgnline
  245.  *
  246.  *     Flags that all v*() routine points will be building up a line list.
  247.  */
  248. void
  249. bgnline()
  250. {
  251.     if (vdevice.bgnmode != NONE)
  252.         verror("vogl: bgnline mode already belongs to some other bgn routine");
  253.  
  254.     vdevice.bgnmode = VLINE;
  255.     vdevice.save = 1;
  256.     sync = vdevice.sync;
  257.     vdevice.sync = 0;
  258. }
  259.  
  260. /*
  261.  * endline
  262.  *
  263.  *     Flags that all v*() routine points will be simply setting the 
  264.  *     current position.
  265.  */
  266. void
  267. endline()
  268. {
  269.     vdevice.bgnmode = NONE;
  270.     vdevice.save = 0;
  271.     if (sync) {
  272.         vdevice.sync = 1;
  273.         (*vdevice.dev.Vsync)();
  274.     }
  275. }
  276.  
  277. /*
  278.  * bgnclosedline
  279.  *
  280.  *     Flags that all v*() routine points will be building up a line list.
  281.  */
  282. void
  283. bgnclosedline()
  284. {
  285.     if (vdevice.bgnmode != NONE)
  286.         verror("vogl: bgncloseline mode already belongs to some other bgn routine");
  287.  
  288.     vdevice.bgnmode = VCLINE;
  289.     vdevice.save = 1;
  290.     sync = vdevice.sync;
  291.     vdevice.sync = 0;
  292. }
  293.  
  294. /*
  295.  * endclosedline
  296.  *
  297.  *     Flags that all v*() routine points will be simply setting the 
  298.  *     current position.
  299.  */
  300. void
  301. endclosedline()
  302. {
  303.     vdevice.bgnmode = NONE;
  304.     vdevice.sync = sync;
  305.     draw(vdevice.savex, vdevice.savey, vdevice.savez);
  306. }
  307.