home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / source / mbq198 / draw.m < prev    next >
Encoding:
Text File  |  1996-06-26  |  7.0 KB  |  408 lines

  1. // draw.m
  2.  
  3. #include "bsp5.h"
  4. #import <appkit/appkit.h>
  5.  
  6. qboolean        draw_windowup;
  7.  
  8. id            window_i, view_i;
  9.  
  10. /*
  11. ===============
  12. Draw_OpenWindow
  13.  
  14. Opens a window of a reasonable size and stores scaling values
  15. based on the mins / maxs collected so far
  16. ===============
  17. */
  18. void Draw_OpenWindow (void)
  19. {
  20.     NXPoint        minpt, maxpt;
  21.     NXSize        size;
  22.     double        big, scale;
  23.     NXScreen    const *screens;
  24.     int            screencount;
  25.     NXRect        content;
  26.  
  27.     if (!NXApp)
  28.         NXApp = [Application new];
  29.         
  30.     [NXApp getScreens:&screens count:&screencount];
  31.     
  32.     minpt.x = brushset->mins[0] + brushset->mins[1]/2 - 512;
  33.     minpt.y = brushset->mins[2] + brushset->mins[1]/2 - 512;
  34.     maxpt.x = brushset->maxs[0] + brushset->maxs[1]/2 + 512;
  35.     maxpt.y = brushset->maxs[2] + brushset->maxs[1]/2 + 512;
  36.     
  37.     size.width = maxpt.x - minpt.x;
  38.     size.height = maxpt.y - minpt.y;
  39.     
  40.     content.origin.x = 0;
  41.     content.origin.y = 0;
  42.  
  43.     big = MAX(size.width,size.height);
  44.     if (screencount > 1)
  45.         scale = 1280/big;
  46.     else
  47.         scale = 512/big;
  48.  
  49.     content.size.width = size.width * scale;
  50.     content.size.height = size.height * scale;
  51.         
  52.     window_i =
  53.     [[Window alloc]
  54.         initContent:    &content
  55.         style:            NX_TITLEDSTYLE
  56.         backing:        NX_RETAINED
  57.         buttonMask:        0
  58.         defer:            NO
  59.         screen:            &screens[screencount-1]
  60.     ];
  61.     view_i = [window_i contentView];
  62.     
  63.     [view_i
  64.         setDrawSize:    size.width
  65.         :                size.height];
  66.     [view_i 
  67.         setDrawOrigin:    minpt.x 
  68.         :                 minpt.y];
  69.     
  70.     [window_i display];
  71.     [window_i orderFront: nil];
  72.     
  73.     [view_i lockFocus];
  74.     PSsetgray (NX_BLACK);    
  75.     PSsetlinewidth (0.1);
  76.     NXPing ();
  77. }
  78.  
  79. /*
  80. ===============
  81. Draw_Open2D
  82.  
  83. Opens a window of a reasonable size and stores scaling values
  84. based on the mins / maxs collected so far
  85. ===============
  86. */
  87. void Draw_Open2D (void)
  88. {
  89.     NXPoint        minpt, maxpt;
  90.     NXSize        size;
  91.     double        big, scale;
  92.     NXScreen    const *screens;
  93.     int            screencount;
  94.     NXRect        content;
  95.  
  96.     if (!NXApp)
  97.         NXApp = [Application new];
  98.         
  99.     [NXApp getScreens:&screens count:&screencount];
  100.     
  101.     minpt.x = brushset->mins[0] + brushset->mins[1]/2 - 512;
  102.     minpt.y = brushset->mins[2] + brushset->mins[1]/2 - 512;
  103.     maxpt.x = brushset->maxs[0] + brushset->maxs[1]/2 + 512;
  104.     maxpt.y = brushset->maxs[2] + brushset->maxs[1]/2 + 512;
  105.     
  106.     size.width = maxpt.x - minpt.x;
  107.     size.height = maxpt.y - minpt.y;
  108.     
  109.     content.origin.x = 0;
  110.     content.origin.y = 0;
  111.  
  112.     big = MAX(size.width,size.height);
  113.     if (screencount > 1)
  114.         scale = 1280/big;
  115.     else
  116.         scale = 512/big;
  117.  
  118.     content.size.width = size.width * scale;
  119.     content.size.height = size.height * scale;
  120.         
  121.     window_i =
  122.     [[Window alloc]
  123.         initContent:    &content
  124.         style:            NX_TITLEDSTYLE
  125.         backing:        NX_RETAINED
  126.         buttonMask:        0
  127.         defer:            NO
  128.         screen:            &screens[screencount-1]
  129.     ];
  130.     view_i = [window_i contentView];
  131.     
  132.     [view_i
  133.         setDrawSize:    size.width
  134.         :                size.height];
  135.     [view_i 
  136.         setDrawOrigin:    minpt.x 
  137.         :                 minpt.y];
  138.     
  139.     [window_i display];
  140.     [window_i orderFront: nil];
  141.     
  142.     [view_i lockFocus];
  143.     PSsetgray (NX_BLACK);    
  144.     PSsetlinewidth (0.1);
  145.     NXPing ();
  146. }
  147.  
  148. /*
  149. ================
  150. Draw_CheckWindow
  151. ================
  152. */
  153. void Draw_CheckWindow (void)
  154. {
  155.     if (draw_windowup)
  156.         return;
  157.         
  158.     draw_windowup = true;
  159.     
  160.     Draw_OpenWindow ();
  161. }
  162.  
  163. void PSmoveto3 (vec3_t pt)
  164. {
  165.     PSmoveto (pt[0]+pt[1]/2, pt[2]+pt[1]/2);
  166. }
  167.  
  168. void PSlineto3 (vec3_t pt)
  169. {
  170.     PSlineto (pt[0]+pt[1]/2, pt[2]+pt[1]/2);
  171. }
  172.  
  173. /*
  174. ============
  175. Draw_DrawFace
  176. ============
  177. */
  178. void Draw_DrawFace (face_t *f)
  179. {
  180.     int        i;
  181.     double    *pt;
  182.     
  183.     if (!drawflag)
  184.         return;
  185.     Draw_CheckWindow ();        // bring up window if nor allready up
  186.     
  187.     pt = f->pts[f->numpoints-1];
  188.     PSmoveto (pt[0]+pt[1]/2, pt[2]+pt[1]/2);
  189.     pt = f->pts[0];
  190.     for (i=0 ; i<f->numpoints ; i++, pt+= 3)
  191.         PSlineto (pt[0]+pt[1]/2, pt[2]+pt[1]/2);
  192.     
  193.     PSstroke ();
  194.     NXPing ();
  195. }
  196.  
  197.  
  198. /*
  199. ============
  200. Draw_ClearWindow
  201. ============
  202. */
  203. void Draw_ClearWindow (void)
  204. {
  205.     NXRect    b;
  206.     
  207.     if (!drawflag)
  208.         return;
  209.     Draw_CheckWindow ();        // bring up window if nor allready up
  210.     [view_i getBounds: &b];
  211.     NXEraseRect (&b);
  212.     NXPing ();
  213. }
  214.  
  215. /*
  216. ============
  217. Draw_Set*
  218. ============
  219. */
  220. void Draw_SetRed (void)
  221. {
  222.     if (!NXApp)
  223.         return;
  224.     PSsetrgbcolor (1.0,0,0);    
  225. }
  226.  
  227. void Draw_SetGrey (void)
  228. {
  229.     if (!NXApp)
  230.         return;
  231.     PSsetrgbcolor (0.7,0.7,0.7);
  232. }
  233.  
  234. void Draw_SetBlack (void)
  235. {
  236.     if (!NXApp)
  237.         return;
  238.     PSsetrgbcolor (0,0,0);
  239. }
  240.  
  241.  
  242. void Draw_SetColor (int c)
  243. {
  244.     switch (c&7)
  245.     {
  246.     case 0:
  247.         PSsetrgbcolor (0,0,0);
  248.         break;
  249.     case 1:
  250.         PSsetrgbcolor (0,0,1);
  251.         break;
  252.     case 2:
  253.         PSsetrgbcolor (0,1,0);
  254.         break;
  255.     case 3:
  256.         PSsetrgbcolor (0,1,1);
  257.         break;
  258.     case 4:
  259.         PSsetrgbcolor (1,0,0);
  260.         break;
  261.     case 5:
  262.         PSsetrgbcolor (1,0,1);
  263.         break;
  264.     case 6:
  265.         PSsetrgbcolor (1,1,0);
  266.         break;
  267.     case 7:
  268.         PSsetrgbcolor (1,1,1);
  269.         break;
  270.     }
  271. }
  272.  
  273.  
  274. void DrawPoint (vec3_t v)
  275. {
  276.     if (!drawflag)
  277.         return;
  278.     Draw_CheckWindow ();        // bring up window if nor allready up
  279.  
  280.     PSarc (v[0]+v[1]/2, v[2]+v[1]/2, 2, 0, 360);
  281.     PSfill ();
  282.     NXPing ();
  283. }
  284.  
  285.  
  286. void DrawPortal (portal_t *p)
  287. {
  288.     int        i;
  289.     winding_t    *w;
  290.     
  291.     if (!drawflag)
  292.         return;
  293.     Draw_CheckWindow ();        // bring up window if nor allready up
  294.     w = p->winding;
  295.     PSmoveto3 (w->points[w->numpoints-1]);
  296.     for (i=0 ; i< w->numpoints ; i++)
  297.         PSlineto3 (w->points[i]);
  298.  
  299.     PSstroke ();
  300.     NXPing ();
  301. }
  302.  
  303. void FillPortal (portal_t *p)
  304. {
  305.     int        i;
  306.     winding_t    *w;
  307.     
  308.     if (!drawflag)
  309.         return;
  310.     Draw_CheckWindow ();        // bring up window if nor allready up
  311.     w = p->winding;
  312.     PSmoveto3 (w->points[w->numpoints-1]);
  313.     for (i=0 ; i< w->numpoints ; i++)
  314.         PSlineto3 (w->points[i]);
  315.  
  316.     PSfill ();    
  317.     NXPing ();
  318. }
  319.  
  320. void DrawLeaf (node_t *l, int color)
  321. {
  322.     portal_t    *p;
  323.     
  324.     if (!drawflag)
  325.         return;
  326.     Draw_CheckWindow ();        // bring up window if nor allready up
  327.  
  328.     Draw_SetColor (color);
  329.     for (p=l->portals ; p ; )
  330.     {
  331.         FillPortal (p);
  332.         if (p->nodes[0] == l)
  333.             p = p->next[0];
  334.         else
  335.             p = p->next[1];
  336.     }
  337.     
  338.     Draw_SetColor (0);
  339.     for (p=l->portals ; p ; )
  340.     {
  341.         DrawPortal (p);
  342.         if (p->nodes[0] == l)
  343.             p = p->next[0];
  344.         else
  345.             p = p->next[1];
  346.     }
  347. }
  348.  
  349. void DrawBrush (brush_t *b)
  350. {
  351.     face_t    *f;
  352.     
  353.     for (f=b->faces ; f ; f=f->next)
  354.         Draw_DrawFace (f);
  355. }
  356.  
  357.  
  358. void DrawWinding (winding_t *w)
  359. {
  360.     int        i;
  361.     
  362.     if (!drawflag)
  363.         return;
  364.     Draw_CheckWindow ();        // bring up window if nor allready up
  365.  
  366.     Draw_SetColor (2);
  367.     PSmoveto3 (w->points[w->numpoints-1]);
  368.     for (i=0 ; i<w->numpoints ; i++)
  369.         PSlineto3 (w->points[i]);
  370.     PSfill ();
  371.     
  372.     Draw_SetColor (0);
  373.     PSmoveto3 (w->points[w->numpoints-1]);
  374.     for (i=0 ; i<w->numpoints ; i++)
  375.         PSlineto3 (w->points[i]);
  376.     PSstroke ();
  377.  
  378.     Draw_SetColor (0);
  379.     for (i=0 ; i<w->numpoints ; i++)
  380.         DrawPoint (w->points[i]);
  381.     NXPing ();
  382. }
  383.  
  384. void DrawTri (vec3_t p1, vec3_t p2, vec3_t p3)
  385. {
  386.     if (!drawflag)
  387.         return;
  388.     Draw_CheckWindow ();        // bring up window if not allready up
  389.  
  390.     Draw_SetColor (3);
  391.     PSmoveto3 (p1);
  392.     PSlineto3 (p2);
  393.     PSlineto3 (p3);
  394.     PSlineto3 (p1);
  395.     PSfill ();
  396.     
  397.     Draw_SetColor (0);
  398.     PSmoveto3 (p1);
  399.     PSlineto3 (p2);
  400.     PSlineto3 (p3);
  401.     PSlineto3 (p1);
  402.     PSstroke ();
  403.  
  404.     NXPing ();
  405. }
  406.  
  407.  
  408.