home *** CD-ROM | disk | FTP | other *** search
/ MegaDoom Adventures / PMWMEGADOOM.iso / doom / creators / ibsp101s / drawing.c < prev    next >
C/C++ Source or Header  |  1994-07-10  |  6KB  |  292 lines

  1. /* drawing.m */
  2. #include "idbsp.h"
  3.  
  4. /* id           window_i, view_i; */
  5. STORAGE            *window_i,
  6.                    *view_i;
  7. float               scale = 0.125;
  8. NXRect              worldbounds;
  9.  
  10. /*
  11.    ================
  12.    =
  13.    = IDRectFromPoints
  14.    =
  15.    = Makes the rectangle just touch the two points
  16.    =
  17.    ================
  18.  */
  19.  
  20. void                IDRectFromPoints(NXRect * rect, NXPoint const *p1, NXPoint const *p2)
  21. {
  22. /* return a rectangle that encloses the two points */
  23.     if (p1 -> x < p2 -> x)
  24.         {
  25.         rect -> origin.x = p1 -> x;
  26.         rect -> size.width = p2 -> x - p1 -> x + 1;
  27.         }
  28.     else
  29.         {
  30.         rect -> origin.x = p2 -> x;
  31.         rect -> size.width = p1 -> x - p2 -> x + 1;
  32.         }
  33.  
  34.     if (p1 -> y < p2 -> y)
  35.         {
  36.         rect -> origin.y = p1 -> y;
  37.         rect -> size.height = p2 -> y - p1 -> y + 1;
  38.         }
  39.     else
  40.         {
  41.         rect -> origin.y = p2 -> y;
  42.         rect -> size.height = p1 -> y - p2 -> y + 1;
  43.         }
  44. }
  45.  
  46.  
  47. /*
  48.    ==================
  49.    =
  50.    = IDEnclosePoint
  51.    =
  52.    = Make the rect enclose the point if it doesn't allready
  53.    =
  54.    ==================
  55.  */
  56.  
  57. void                IDEnclosePoint(NXRect * rect, NXPoint const *point)
  58. {
  59.     float               right,
  60.                         top;
  61.  
  62.     right = rect -> origin.x + rect -> size.width - 1;
  63.     top = rect -> origin.y + rect -> size.height - 1;
  64.  
  65.     if (point -> x < rect -> origin.x)
  66.         rect -> origin.x = point -> x;
  67.     if (point -> y < rect -> origin.y)
  68.         rect -> origin.y = point -> y;
  69.     if (point -> x > right)
  70.         right = point -> x;
  71.     if (point -> y > top)
  72.         top = point -> y;
  73.  
  74.     rect -> size.width = right - rect -> origin.x + 1;
  75.     rect -> size.height = top - rect -> origin.y + 1;
  76. }
  77.  
  78.  
  79. /*
  80.    ===========
  81.    =
  82.    = BoundLineStore
  83.    =
  84.    ===========
  85.  */
  86.  
  87. /* void BoundLineStore (id lines_i, NXRect *r) */
  88. void                BoundLineStore(STORAGE * lines_i, NXRect * r)
  89. {
  90.     int                 i,
  91.                         c;
  92.     worldline_t        *line_p;
  93.  
  94. /*  c = [lines_i count]; */
  95.     c = lines_i -> count;
  96.     if (!c)
  97.         Error("BoundLineStore: empty list");
  98.  
  99. /* line_p = [lines_i elementAt:0]; */
  100.     line_p = lines_i -> data;
  101.     IDRectFromPoints(r, &line_p -> p1, &line_p -> p2);
  102.  
  103.     for (i = 1; i < c; i++)
  104.         {
  105. /*      line_p = [lines_i elementAt:i]; */
  106.         line_p = (worldline_t *) lines_i -> data + i;
  107.         IDEnclosePoint(r, &line_p -> p1);
  108.         IDEnclosePoint(r, &line_p -> p2);
  109.         }
  110. }
  111.  
  112.  
  113. /*
  114.    ===========
  115.    =
  116.    = DrawLineStore
  117.    =
  118.    = Draws all of the lines in the given storage object
  119.    =
  120.    ===========
  121.  */
  122.  
  123. /* void DrawLineStore (id lines_i) */
  124. void                DrawLineStore(STORAGE * lines_i)
  125. {
  126.  
  127. #if 0
  128.     int                 i,
  129.                         c;
  130.     worldline_t        *line_p;
  131.  
  132.     if (!draw)
  133.         return;
  134.  
  135. /*  c = [lines_i count]; */
  136.     c = lines_i -> count;
  137.  
  138.     for (i = 0; i < c; i++)
  139.         {
  140. /*      line_p = [lines_i elementAt:i]; */
  141.         line_p = (worldline_t *) lines_i -> data + i;
  142.         PSmoveto(line_p -> p1.x, line_p -> p1.y);
  143.         PSlineto(line_p -> p2.x, line_p -> p2.y);
  144.         PSstroke();
  145.         }
  146.     NXPing();
  147. #endif
  148. }
  149.  
  150. /*
  151.    ===========
  152.    =
  153.    = DrawLine
  154.    =
  155.    = Draws all of the lines in the given storage object
  156.    =
  157.    ===========
  158.  */
  159.  
  160. void                DrawLineDef(maplinedef_t * ld)
  161. {
  162.  
  163. #if 0
  164.     mapvertex_t        *v1,
  165.                        *v2;
  166.  
  167.     if (!draw)
  168.         return;
  169. /*
  170.    v1 = [mapvertexstore_i elementAt: ld->v1];
  171.    v2 = [mapvertexstore_i elementAt: ld->v2];
  172.  */
  173.     v1 = mapvertexstore_i -> data + ld -> v1;
  174.     v2 = mapvertexstore_i -> data + ld -> v2;
  175.     PSmoveto(v1 -> x, v1 -> y);
  176.     PSlineto(v2 -> x, v2 -> y);
  177.     PSstroke();
  178.     NXPing();
  179. #endif
  180. }
  181.  
  182.  
  183. /*
  184.    ===========
  185.    =
  186.    = DrawMap
  187.    =
  188.    ===========
  189.  */
  190.  
  191. void                DrawMap(void)
  192. {
  193.     NXRect              scaled;
  194.  
  195.     BoundLineStore(linestore_i, &worldbounds);
  196.     worldbounds.origin.x -= 8;
  197.     worldbounds.origin.y -= 8;
  198.     worldbounds.size.width += 16;
  199.     worldbounds.size.height += 16;
  200.  
  201. #if 0
  202.     if (!draw)
  203.         return;
  204.  
  205.     scaled.origin.x = 300;
  206.     scaled.origin.y = 80;
  207.     scaled.size.width = worldbounds.size.width * scale;
  208.     scaled.size.height = worldbounds.size.height * scale;
  209. /*
  210.    window_i =
  211.    [[Window alloc]
  212.    initContent: &scaled
  213.    style:           NX_TITLEDSTYLE
  214.    backing:     NX_RETAINED
  215.    buttonMask:      0
  216.    defer:           NO
  217.    ];
  218.  
  219.    [window_i display];
  220.    [window_i orderFront: nil];
  221.    view_i = [window_i contentView];
  222.  
  223.    [view_i
  224.    setDrawSize: worldbounds.size.width
  225.    :                worldbounds.size.height];
  226.    [view_i
  227.    setDrawOrigin:   worldbounds.origin.x
  228.    :                worldbounds.origin.y];
  229.  
  230.    [view_i lockFocus];
  231.    PSsetgray (NX_BLACK);
  232.    DrawLineStore (linestore_i);
  233.  */
  234. #endif
  235. }
  236.  
  237.  
  238. /*
  239.    ===========
  240.    =
  241.    = EraseWindow
  242.    =
  243.    ===========
  244.  */
  245.  
  246. void                EraseWindow(void)
  247. {
  248.  
  249. #if 0
  250.     if (!draw)
  251.         return;
  252.  
  253.     NXEraseRect(&worldbounds);
  254.     NXPing();
  255. #endif
  256. }
  257.  
  258.  
  259. /*
  260.    ============================
  261.    =
  262.    = DrawDivLine
  263.    =
  264.    ============================
  265.  */
  266.  
  267. void                DrawDivLine(divline_t * div)
  268. {
  269.  
  270. #if 0
  271.     float               vx,
  272.                         vy,
  273.                         dist;
  274.  
  275.     if (!draw)
  276.         return;
  277.  
  278.     PSsetgray(NX_BLACK);
  279.  
  280.     dist = sqrt(pow(div -> dx, 2) + pow(div -> dy, 2));
  281.     vx = div -> dx / dist;
  282.     vy = div -> dy / dist;
  283.  
  284.     dist = MAX(worldbounds.size.width, worldbounds.size.height);
  285.  
  286.     PSmoveto(div -> pt.x - vx * dist, div -> pt.y - vy * dist);
  287.     PSlineto(div -> pt.x + vx * dist, div -> pt.y + vy * dist);
  288.     PSstroke();
  289.     NXPing();
  290. #endif
  291. }
  292.