2003-03-18 19:48:24 +00:00
|
|
|
|
2003-05-06 21:52:58 +00:00
|
|
|
#include <AppKit/NSGraphics.h>
|
|
|
|
#include <AppKit/DPSOperators.h>
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "Clipper.h"
|
|
|
|
#include "Map.h"
|
|
|
|
#include "XYView.h"
|
2010-09-11 11:30:01 +00:00
|
|
|
#include "ZView.h"
|
2010-09-09 11:46:38 +00:00
|
|
|
#include "CameraView.h"
|
|
|
|
#include "QuakeEd.h"
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
id clipper_i;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
@implementation Clipper
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-init
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
[super init];
|
|
|
|
clipper_i = self;
|
2010-09-11 10:03:41 +00:00
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(BOOL) hide
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int oldnum;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
oldnum = num;
|
|
|
|
num = 0;
|
|
|
|
return (oldnum > 0);
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-flipNormal
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
vec3_t temp;
|
|
|
|
|
|
|
|
if (num == 2) {
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (pos[0], temp);
|
|
|
|
VectorCopy (pos[1], pos[0]);
|
|
|
|
VectorCopy (temp, pos[1]);
|
2010-09-11 10:03:41 +00:00
|
|
|
} else if (num == 3) {
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (pos[0], temp);
|
|
|
|
VectorCopy (pos[2], pos[0]);
|
|
|
|
VectorCopy (temp, pos[2]);
|
2010-09-11 10:03:41 +00:00
|
|
|
} else {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("no clipplane\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
NSBeep ();
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(BOOL) getFace:(face_t *) f
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
vec3_t v1, v2, norm;
|
|
|
|
int i;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (vec3_origin, plane.normal);
|
|
|
|
plane.dist = 0;
|
|
|
|
if (num < 2)
|
|
|
|
return NO;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (num == 2) {
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (pos[0], pos[2]);
|
|
|
|
pos[2][2] += 16;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (pos[i], f->planepts[i]);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorSubtract (pos[2], pos[0], v1);
|
|
|
|
VectorSubtract (pos[1], pos[0], v2);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
CrossProduct (v1, v2, norm);
|
|
|
|
VectorNormalize (norm);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (!norm[0] && !norm[1] && !norm[2])
|
2003-03-18 19:48:24 +00:00
|
|
|
return NO;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[texturepalette_i getTextureDef:&f->texture];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
XYClick
|
|
|
|
================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-XYClick:(NSPoint) pt
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
vec3_t new;
|
|
|
|
|
|
|
|
new[0] =[xyview_i snapToGrid:pt.x];
|
|
|
|
new[1] =[xyview_i snapToGrid:pt.y];
|
|
|
|
new[2] =[map_i currentMinZ];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
// see if a point is allready there
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
if (new[0] == pos[i][0] && new[1] == pos[i][1]) {
|
|
|
|
if (pos[i][2] ==[map_i currentMinZ])
|
|
|
|
pos[i][2] =[map_i currentMaxZ];
|
2003-03-18 19:48:24 +00:00
|
|
|
else
|
2010-09-11 10:03:41 +00:00
|
|
|
pos[i][2] =[map_i currentMinZ];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (num == 3)
|
|
|
|
num = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (new, pos[num]);
|
|
|
|
num++;
|
|
|
|
|
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
XYDrag
|
|
|
|
================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-(BOOL) XYDrag:(NSPoint *) pt
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
if (fabs (pt->x - pos[i][0] > 10) || fabs (pt->y - pos[i][1] > 10))
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
2010-09-11 10:03:41 +00:00
|
|
|
// drag this point
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-ZClick:(NSPoint) pt
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-carve
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
[map_i makeSelectedPerform:@selector (carveByClipper)];
|
2003-03-18 19:48:24 +00:00
|
|
|
num = 0;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-cameraDrawSelf
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
vec3_t mid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
linecolor (1, 0.5, 0);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (pos[i], mid);
|
|
|
|
mid[0] -= 8;
|
|
|
|
mid[1] -= 8;
|
|
|
|
CameraMoveto (mid);
|
|
|
|
mid[0] += 16;
|
|
|
|
mid[1] += 16;
|
|
|
|
CameraLineto (mid);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (pos[i], mid);
|
|
|
|
mid[0] -= 8;
|
|
|
|
mid[1] += 8;
|
|
|
|
CameraMoveto (mid);
|
|
|
|
mid[0] += 16;
|
|
|
|
mid[1] -= 16;
|
|
|
|
CameraLineto (mid);
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-XYDrawSelf
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
char text[8];
|
|
|
|
|
|
|
|
PSsetrgbcolor (1, 0.5, 0);
|
2010-09-11 11:30:01 +00:00
|
|
|
GSSetFont (DEFCTXT, [NSFont fontWithName: @"Helvetica-Medium"
|
|
|
|
size: 10 / [xyview_i currentScale]]);
|
2010-09-11 10:03:41 +00:00
|
|
|
PSrotate (0);
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
PSmoveto (pos[i][0] - 4, pos[i][1] - 4);
|
2003-03-18 19:48:24 +00:00
|
|
|
sprintf (text, "%i", i);
|
|
|
|
PSshow (text);
|
|
|
|
PSstroke ();
|
2010-09-11 10:03:41 +00:00
|
|
|
PSarc (pos[i][0], pos[i][1], 10, 0, 360);
|
2003-03-18 19:48:24 +00:00
|
|
|
PSstroke ();
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-ZDrawSelf
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
char text[8];
|
|
|
|
|
|
|
|
PSsetrgbcolor (1, 0.5, 0);
|
2010-09-11 11:30:01 +00:00
|
|
|
GSSetFont (DEFCTXT, [NSFont fontWithName: @"Helvetica-Medium"
|
|
|
|
size: 10 / [zview_i currentScale]]);
|
2010-09-11 10:03:41 +00:00
|
|
|
PSrotate (0);
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
PSmoveto (-28 + i * 8 - 4, pos[i][2] - 4);
|
2003-03-18 19:48:24 +00:00
|
|
|
sprintf (text, "%i", i);
|
|
|
|
PSshow (text);
|
|
|
|
PSstroke ();
|
2010-09-11 10:03:41 +00:00
|
|
|
PSarc (-28 + i * 8, pos[i][2], 10, 0, 360);
|
2003-03-18 19:48:24 +00:00
|
|
|
PSstroke ();
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|