-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgl_planes.pas
267 lines (225 loc) · 7.38 KB
/
gl_planes.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// ------------------------------------------------------------------------------
// DelphiQuake, Copyright (C) 2005-2011 by Jim Valavanis
// E-Mail: jimmyvalavanis@yahoo.gr
//
// Copyright (C) 1996-1997 Id Software, Inc.
//
// 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 the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ------------------------------------------------------------------------------
{$I dquake.inc}
{$Z4}
unit gl_planes;
interface
uses
q_delphi,
q_vector,
bspconst;
const
VERTEXSIZE = 7;
// plane_t structure
// !!! if this is changed, it must be changed in asm_i386.h too !!!
type
Pmplane_t = ^mplane_t;
mplane_t = record
normal: TVector3f;
dist: single;
PlaneType: byte; // for texture axis selection and fast side tests
signbits: byte; // signx + signy<<1 + signz<<1
pad: array[0..1] of byte;
end;
mplane_tArray = array[0..$FFFF] of mplane_t;
Pmplane_tArray = ^mplane_tArray;
type
PPmsurface_t = ^Pmsurface_t;
Pmsurface_t = ^msurface_t;
Ptexture_t = ^texture_t;
PPtexture_t = ^Ptexture_t;
Pglpoly_t = ^glpoly_t;
Pmedge_t = ^medge_t;
Pmtexinfo_t = ^mtexinfo_t;
Pmnode_t = ^mnode_t;
msurface_t = record
visframe: integer; // should be drawn when node is crossed
plane: Pmplane_t;
flags: integer;
firstedge: integer; // look up in model->surfedges[], negative numbers
numedges: integer; // are backwards edges
texturemins: array[0..1] of short;
extents: array[0..1] of short;
light_s, light_t: integer; // gl lightmap coordinates
polys: Pglpoly_t; // multiple if warped
texturechain: Pmsurface_t;
texinfo: Pmtexinfo_t;
// lighting info
dlightframe: integer;
dlightbits: integer;
lightmaptexturenum: integer;
styles: array[0..MAXLIGHTMAPS - 1] of byte;
cached_light: array[0..MAXLIGHTMAPS - 1] of integer; // values currently used in lightmap
cached_dlight: qboolean; // true if dynamic light in cache
samples: PByteArray; // [numstyles*surfsize]
end;
msurface_tArray = array[0..$FFFF] of msurface_t;
Pmsurface_tArray = ^msurface_tArray;
msurface_tPArray = array[0..$FFFF] of Pmsurface_t;
Pmsurface_tPArray = ^msurface_tPArray;
texture_t = record
name: array[0..15] of char;
width: unsigned;
height: unsigned;
gl_texturenum: integer;
texturechain: Pmsurface_t; // for gl_texsort drawing
anim_total: integer; // total tenths in sequence ( 0 = no)
anim_min, anim_max: integer; // time for this frame min <=time< max
anim_next: Ptexture_t; // in the animation sequence
alternate_anims: Ptexture_t; // bmodels in frmae 1 use these
offsets: array[0..MIPLEVELS - 1] of unsigned; // four mip maps stored
end;
texture_tPArray = array[0..$FFFF] of Ptexture_t;
Ptexture_tPArray = ^texture_tPArray;
glpoly_t = record
next: Pglpoly_t;
chain: Pglpoly_t;
numverts: integer;
flags: integer; // for SURF_UNDERWATER
verts: array[0..3, 0..VERTEXSIZE - 1] of single; // variable sized (xyz s1t1 s2t2)
end;
mnode_t = record
// common with leaf
contents: integer; // 0, to differentiate from leafs
visframe: integer; // node needs to be traversed if current
minmaxs: array[0..5] of single; // for bounding box culling
parent: Pmnode_t;
// node specific
plane: Pmplane_t;
children: array[0..1] of Pmnode_t;
firstsurface: unsigned_short;
numsurfaces: unsigned_short;
end;
mnode_tArray = array[0..$FFFF] of mnode_t;
Pmnode_tArray = ^mnode_tArray;
medge_t = record
v: array[0..1] of unsigned_short;
cachededgeoffset: unsigned_int;
end;
medge_tArray = array[0..$FFFF] of medge_t;
Pmedge_tArray = ^medge_tArray;
mtexinfo_t = record
vecs: array[0..1, 0..3] of single;
mipadjust: single;
texture: Ptexture_t;
flags: integer;
end;
mtexinfo_tArray = array[0..$FFFF] of mtexinfo_t;
Pmtexinfo_tArray = ^mtexinfo_tArray;
// JVAL moved from mathlib.c
function BoxOnPlaneSide(emins: PVector3f; emaxs: PVector3f; p: Pmplane_t): integer;
// JVAL moved from mathlib.h
function BOX_ON_PLANE_SIDE(emins: PVector3f; emaxs: PVector3f; p: Pmplane_t): integer;
implementation
uses
sys_win;
(*
==================
BOPS_Error
Split out like this for ASM to call.
==================
*)
procedure BOPS_Error;
begin
Sys_Error('BoxOnPlaneSide: Bad signbits');
end;
(*
==================
BoxOnPlaneSide
Returns 1, 2, or 1 + 2
==================
*)
function BoxOnPlaneSide(emins: PVector3f; emaxs: PVector3f; p: Pmplane_t): integer;
var
dist1, dist2: single;
begin
// general case
case p.signbits of // JVAL change with if??? same values to dist1, dist2
0:
begin
dist1 := p.normal[0] * emaxs[0] + p.normal[1] * emaxs[1] + p.normal[2] * emaxs[2];
dist2 := p.normal[0] * emins[0] + p.normal[1] * emins[1] + p.normal[2] * emins[2];
end;
1:
begin
dist1 := p.normal[0] * emins[0] + p.normal[1] * emaxs[1] + p.normal[2] * emaxs[2];
dist2 := p.normal[0] * emaxs[0] + p.normal[1] * emins[1] + p.normal[2] * emins[2];
end;
2:
begin
dist1 := p.normal[0] * emaxs[0] + p.normal[1] * emins[1] + p.normal[2] * emaxs[2];
dist2 := p.normal[0] * emins[0] + p.normal[1] * emaxs[1] + p.normal[2] * emins[2];
end;
3:
begin
dist1 := p.normal[0] * emins[0] + p.normal[1] * emins[1] + p.normal[2] * emaxs[2];
dist2 := p.normal[0] * emaxs[0] + p.normal[1] * emaxs[1] + p.normal[2] * emins[2];
end;
4:
begin
dist1 := p.normal[0] * emaxs[0] + p.normal[1] * emaxs[1] + p.normal[2] * emins[2];
dist2 := p.normal[0] * emins[0] + p.normal[1] * emins[1] + p.normal[2] * emaxs[2];
end;
5:
begin
dist1 := p.normal[0] * emins[0] + p.normal[1] * emaxs[1] + p.normal[2] * emins[2];
dist2 := p.normal[0] * emaxs[0] + p.normal[1] * emins[1] + p.normal[2] * emaxs[2];
end;
6:
begin
dist1 := p.normal[0] * emaxs[0] + p.normal[1] * emins[1] + p.normal[2] * emins[2];
dist2 := p.normal[0] * emins[0] + p.normal[1] * emaxs[1] + p.normal[2] * emaxs[2];
end;
7:
begin
dist1 := p.normal[0] * emins[0] + p.normal[1] * emins[1] + p.normal[2] * emins[2];
dist2 := p.normal[0] * emaxs[0] + p.normal[1] * emaxs[1] + p.normal[2] * emaxs[2];
end;
else
begin
dist1 := 0;
dist2 := 0; // shut up compiler
BOPS_Error;
end;
end;
result := 0;
if dist1 >= p.dist then
result := 1;
if dist2 < p.dist then
result := result or 2;
end;
function BOX_ON_PLANE_SIDE(emins: PVector3f; emaxs: PVector3f; p: Pmplane_t): integer;
begin
if p.PlaneType < 3 then
begin
if p.dist <= emins[p.PlaneType] then
result := 1
else if p.dist >= emaxs[p.PlaneType] then
result := 2
else
result := 3
end
else
result := BoxOnPlaneSide(emins, emaxs, p);
end;
end.