2001-10-14 05:55:21 +00:00
|
|
|
/*
|
|
|
|
Clipper.h
|
|
|
|
|
|
|
|
Clipping plane class
|
|
|
|
|
|
|
|
Copyright (C) 2001 Jeff Teunissen <deek@d2dc.net>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "Config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <QF/mathlib.h>
|
|
|
|
#include <QF/bspfile.h>
|
|
|
|
|
|
|
|
#import <AppKit/NSGraphics.h>
|
|
|
|
#import <AppKit/DPSOperators.h>
|
2001-02-09 01:52:44 +00:00
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
#import "CameraView.h"
|
|
|
|
#import "Clipper.h"
|
|
|
|
#import "Forge.h"
|
|
|
|
#import "Map.h"
|
|
|
|
#import "SetBrush.h"
|
|
|
|
#import "XYView.h"
|
|
|
|
#import "ZView.h"
|
2001-02-09 01:52:44 +00:00
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
Clipper *clipper;
|
2001-02-09 01:52:44 +00:00
|
|
|
|
|
|
|
@implementation Clipper
|
|
|
|
|
|
|
|
- init
|
|
|
|
{
|
|
|
|
[super init];
|
2001-10-14 05:55:21 +00:00
|
|
|
clipper = self;
|
2001-02-09 01:52:44 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hide
|
|
|
|
{
|
|
|
|
int oldnum;
|
|
|
|
|
|
|
|
oldnum = num;
|
|
|
|
num = 0;
|
|
|
|
return (oldnum > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- flipNormal
|
|
|
|
{
|
|
|
|
vec3_t temp;
|
|
|
|
|
|
|
|
switch (num) {
|
|
|
|
case 2:
|
|
|
|
VectorCopy (pos[0], temp);
|
|
|
|
VectorCopy (pos[1], pos[0]);
|
|
|
|
VectorCopy (temp, pos[1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
VectorCopy (pos[0], temp);
|
|
|
|
VectorCopy (pos[2], pos[0]);
|
|
|
|
VectorCopy (temp, pos[2]);
|
|
|
|
break;
|
|
|
|
default:
|
2001-10-14 05:55:21 +00:00
|
|
|
NSLog (@"No clipping plane");
|
2001-02-09 01:52:44 +00:00
|
|
|
NSBeep ();
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) getFace: (face_t *) f
|
|
|
|
{
|
|
|
|
vec3_t v1, v2, norm;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
VectorCopy (vec3_origin, plane.normal);
|
|
|
|
plane.dist = 0;
|
|
|
|
if (num < 2)
|
|
|
|
return NO;
|
|
|
|
if (num == 2)
|
|
|
|
{
|
|
|
|
VectorCopy (pos[0], pos[2]);
|
|
|
|
pos[2][2] += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0 ; i<3 ; i++)
|
|
|
|
VectorCopy (pos[i], f->planepts[i]);
|
|
|
|
|
|
|
|
VectorSubtract (pos[2], pos[0], v1);
|
|
|
|
VectorSubtract (pos[1], pos[0], v2);
|
|
|
|
|
|
|
|
CrossProduct (v1, v2, norm);
|
|
|
|
VectorNormalize (norm);
|
|
|
|
|
|
|
|
if ( !norm[0] && !norm[1] && !norm[2] )
|
|
|
|
return NO;
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
[texturepalette_i setTextureDef: &f->texture];
|
2001-02-09 01:52:44 +00:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
XYClick
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
- XYClick: (NSPoint) pt
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
vec3_t new;
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
new[0] = [xyView snapToGrid: pt.x];
|
|
|
|
new[1] = [xyView snapToGrid: pt.y];
|
|
|
|
new[2] = [map currentMinZ];
|
2001-02-09 01:52:44 +00:00
|
|
|
|
2001-02-22 00:15:03 +00:00
|
|
|
// see if a point is already there
|
2001-02-09 01:52:44 +00:00
|
|
|
for (i=0 ; i<num ; i++) {
|
|
|
|
if (new[0] == pos[i][0] && new[1] == pos[i][1]) {
|
2001-10-14 05:55:21 +00:00
|
|
|
if (pos[i][2] == [map currentMinZ])
|
|
|
|
pos[i][2] = [map currentMaxZ];
|
2001-02-09 01:52:44 +00:00
|
|
|
else
|
2001-10-14 05:55:21 +00:00
|
|
|
pos[i][2] = [map currentMinZ];
|
|
|
|
[forge updateAll];
|
2001-02-09 01:52:44 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (num == 3)
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
VectorCopy (new, pos[num]);
|
|
|
|
num++;
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
[forge updateAll];
|
2001-02-09 01:52:44 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
XYDrag
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
- (BOOL) XYDrag: (NSPoint *) pt
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0 ; i<3 ; i++) {
|
|
|
|
if (fabs(pt->x - pos[i][0] > 10) || fabs(pt->y - pos[i][1] > 10))
|
|
|
|
continue; // drag this point
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- ZClick: (NSPoint) pt
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
- carve
|
|
|
|
{
|
2001-10-14 05:55:21 +00:00
|
|
|
[map makeSelectedPerform: @selector(carveByClipper)];
|
2001-02-09 01:52:44 +00:00
|
|
|
num = 0;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
- (void) cameraDrawSelf
|
2001-02-09 01:52:44 +00:00
|
|
|
{
|
|
|
|
vec3_t mid;
|
|
|
|
int i;
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
linecolor (1, 0.5, 0);
|
2001-02-09 01:52:44 +00:00
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2001-02-09 01:52:44 +00:00
|
|
|
VectorCopy (pos[i], mid);
|
|
|
|
mid[0] -= 8;
|
|
|
|
mid[1] -= 8;
|
|
|
|
CameraMoveto (mid);
|
|
|
|
mid[0] += 16;
|
|
|
|
mid[1] += 16;
|
|
|
|
CameraLineto (mid);
|
|
|
|
|
|
|
|
VectorCopy (pos[i], mid);
|
|
|
|
mid[0] -= 8;
|
|
|
|
mid[1] += 8;
|
|
|
|
CameraMoveto (mid);
|
|
|
|
mid[0] += 16;
|
|
|
|
mid[1] -= 16;
|
|
|
|
CameraLineto (mid);
|
|
|
|
}
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
return;
|
2001-02-09 01:52:44 +00:00
|
|
|
}
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
- (void) xyDrawSelf
|
2001-02-09 01:52:44 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char text[8];
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
PSsetrgbcolor (1, 0.5, 0);
|
|
|
|
PSselectfont ("Helvetica-Medium", 10 / [xyView currentScale]);
|
|
|
|
PSrotate (0);
|
2001-02-09 01:52:44 +00:00
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
PSmoveto (pos[i][0] - 4, pos[i][1] - 4);
|
2001-02-09 01:52:44 +00:00
|
|
|
sprintf (text, "%i", i);
|
|
|
|
PSshow (text);
|
|
|
|
PSstroke ();
|
2001-10-14 05:55:21 +00:00
|
|
|
PSarc (pos[i][0], pos[i][1], 10, 0, 360);
|
2001-02-09 01:52:44 +00:00
|
|
|
PSstroke ();
|
|
|
|
}
|
2001-10-14 05:55:21 +00:00
|
|
|
return;
|
2001-02-09 01:52:44 +00:00
|
|
|
}
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
- (void) zDrawSelf
|
2001-02-09 01:52:44 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char text[8];
|
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
PSsetrgbcolor (1, 0.5, 0);
|
|
|
|
PSselectfont ("Helvetica-Medium", 10 / [zView currentScale]);
|
|
|
|
PSrotate (0);
|
2001-02-09 01:52:44 +00:00
|
|
|
|
2001-10-14 05:55:21 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
PSmoveto ((-28 + (i * 8)) - 4, pos[i][2] - 4);
|
2001-02-09 01:52:44 +00:00
|
|
|
sprintf (text, "%i", i);
|
|
|
|
PSshow (text);
|
|
|
|
PSstroke ();
|
2001-10-14 05:55:21 +00:00
|
|
|
PSarc ((-28 + (i * 8)), pos[i][2], 10, 0, 360);
|
2001-02-09 01:52:44 +00:00
|
|
|
PSstroke ();
|
|
|
|
}
|
2001-10-14 05:55:21 +00:00
|
|
|
return;
|
2001-02-09 01:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|