Clipper.m 3.2 KB

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