home *** CD-ROM | disk | FTP | other *** search
/ 1,001 Nights of Doom / 1001NightsOfDoom1995wickedSensations.iso / nodebild / idbsp10.zip / DRAWING.C < prev    next >
C/C++ Source or Header  |  1994-05-28  |  5KB  |  282 lines

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