home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / source / clipper.m < prev    next >
Encoding:
Text File  |  1996-08-08  |  3.2 KB  |  228 lines

  1.  
  2. #include "qedefs.h"
  3.  
  4. id    clipper_i;
  5.  
  6. @implementation Clipper
  7.  
  8. - init
  9. {
  10.     [super init];
  11.     clipper_i = self;
  12.     return self;    
  13. }
  14.  
  15. - (BOOL)hide
  16. {
  17.     int        oldnum;
  18.     
  19.     oldnum = num;
  20.     num = 0;
  21.     return (oldnum > 0);
  22. }
  23.  
  24. - flipNormal
  25. {
  26.     vec3_t    temp;
  27.     
  28.     if (num == 2)
  29.     {
  30.         VectorCopy (pos[0], temp);
  31.         VectorCopy (pos[1], pos[0]);
  32.         VectorCopy (temp, pos[1]);
  33.     }
  34.     else if (num == 3)
  35.     {
  36.         VectorCopy (pos[0], temp);
  37.         VectorCopy (pos[2], pos[0]);
  38.         VectorCopy (temp, pos[2]);
  39.     }    
  40.     else
  41.     {
  42.         qprintf ("no clipplane");
  43.         NXBeep ();
  44.     }
  45.     
  46.     return self;
  47. }
  48.  
  49. - (BOOL)getFace: (face_t *)f
  50. {
  51.     vec3_t    v1, v2, norm;
  52.     int        i;
  53.     
  54.     VectorCopy (vec3_origin, plane.normal);
  55.     plane.dist = 0;
  56.     if (num < 2)
  57.         return NO;
  58.     if (num == 2)
  59.     {
  60.         VectorCopy (pos[0], pos[2]);
  61.         pos[2][2] += 16;
  62.     }
  63.     
  64.     for (i=0 ; i<3 ; i++)
  65.         VectorCopy (pos[i], f->planepts[i]);
  66.         
  67.     VectorSubtract (pos[2], pos[0], v1);
  68.     VectorSubtract (pos[1], pos[0], v2);
  69.     
  70.     CrossProduct (v1, v2, norm);
  71.     VectorNormalize (norm);
  72.     
  73.     if ( !norm[0] && !norm[1] && !norm[2] )
  74.         return NO;
  75.     
  76.     [texturepalette_i getTextureDef: &f->texture];
  77.  
  78.     return YES;
  79. }
  80.  
  81. /*
  82. ================
  83. XYClick
  84. ================
  85. */
  86. - XYClick: (NXPoint)pt
  87. {
  88.     int        i;
  89.     vec3_t    new;
  90.         
  91.     new[0] = [xyview_i snapToGrid: pt.x];
  92.     new[1] = [xyview_i snapToGrid: pt.y];
  93.     new[2] = [map_i currentMinZ];
  94.  
  95. // see if a point is allready there
  96.     for (i=0 ; i<num ; i++)
  97.     {
  98.         if (new[0] == pos[i][0] && new[1] == pos[i][1])
  99.         {
  100.             if (pos[i][2] == [map_i currentMinZ])
  101.                 pos[i][2] = [map_i currentMaxZ];
  102.             else
  103.                 pos[i][2] = [map_i currentMinZ];
  104.             [quakeed_i updateAll];
  105.             return self;
  106.         }
  107.     }
  108.     
  109.     
  110.     if (num == 3)
  111.         num = 0;
  112.     
  113.     VectorCopy (new, pos[num]);
  114.     num++;
  115.  
  116.     [quakeed_i updateAll];
  117.     
  118.     return self;
  119. }
  120.  
  121. /*
  122. ================
  123. XYDrag
  124. ================
  125. */
  126. - (BOOL)XYDrag: (NXPoint *)pt
  127. {
  128.     int        i;
  129.     
  130.     for (i=0 ; i<3 ; i++)
  131.     {
  132.         if (fabs(pt->x - pos[i][0] > 10) || fabs(pt->y - pos[i][1] > 10) )
  133.             continue;
  134.     // drag this point
  135.     
  136.     }
  137.     
  138.     return NO;
  139. }
  140.  
  141. - ZClick: (NXPoint)pt
  142. {
  143.     return self;
  144. }
  145.  
  146. //=============================================================================
  147.  
  148. - carve
  149. {
  150.     [map_i makeSelectedPerform: @selector(carveByClipper)];
  151.     num = 0;
  152.     return self;
  153. }
  154.  
  155.  
  156. - cameraDrawSelf
  157. {
  158.     vec3_t        mid;
  159.     int            i;
  160.     
  161.     linecolor (1,0.5,0);
  162.  
  163.     for (i=0 ; i<num ; i++)
  164.     {
  165.         VectorCopy (pos[i], mid);
  166.         mid[0] -= 8;
  167.         mid[1] -= 8;
  168.         CameraMoveto (mid);
  169.         mid[0] += 16;
  170.         mid[1] += 16;
  171.         CameraLineto (mid);
  172.         
  173.         VectorCopy (pos[i], mid);
  174.         mid[0] -= 8;
  175.         mid[1] += 8;
  176.         CameraMoveto (mid);
  177.         mid[0] += 16;
  178.         mid[1] -= 16;
  179.         CameraLineto (mid);
  180.     }
  181.     
  182.     return self;
  183. }
  184.  
  185. - XYDrawSelf
  186. {
  187.     int        i;
  188.     char    text[8];
  189.     
  190.     PSsetrgbcolor (1,0.5,0);
  191.     PSselectfont("Helvetica-Medium",10/[xyview_i currentScale]);
  192.     PSrotate(0);
  193.  
  194.     for (i=0 ; i<num ; i++)
  195.     {
  196.         PSmoveto (pos[i][0]-4, pos[i][1]-4);
  197.         sprintf (text, "%i", i);
  198.         PSshow (text);
  199.         PSstroke ();
  200.         PSarc ( pos[i][0], pos[i][1], 10, 0, 360);
  201.         PSstroke ();
  202.     }
  203.     return self;
  204. }
  205.  
  206. - ZDrawSelf
  207. {
  208.     int        i;
  209.     char    text[8];
  210.     
  211.     PSsetrgbcolor (1,0.5,0);
  212.     PSselectfont("Helvetica-Medium",10/[zview_i currentScale]);
  213.     PSrotate(0);
  214.  
  215.     for (i=0 ; i<num ; i++)
  216.     {
  217.         PSmoveto (-28+i*8 - 4, pos[i][2]-4);
  218.         sprintf (text, "%i", i);
  219.         PSshow (text);
  220.         PSstroke ();
  221.         PSarc ( -28+i*8, pos[i][2], 10, 0, 360);
  222.         PSstroke ();
  223.     }
  224.     return self;
  225. }
  226.  
  227. @end
  228.