-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbounder.c
More file actions
485 lines (442 loc) · 23.1 KB
/
bounder.c
File metadata and controls
485 lines (442 loc) · 23.1 KB
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*
This file is compiled separately.
*/
///HIGH LEVEL ALERT///
/**THIS FUNCTION HAS HIGH PROBABILITY OF CAUSING CRITICAL GLITCHES**/
#include <sl_def.h>
#include "def.h"
#include "mymath.h"
#include "bounder.h"
_boundBox BoundBoxHost[MAX_PHYS_PROXY];
_boundBox BoundBoxDraw[MAX_PHYS_PROXY];
_boundBox * RBBs;
_boundBox * DBBs;
_boundBox pl_RBB;
_boundBox sl_RBB;
_object_arguments bound_box_starter;
Uint8 curBoxes = 0;
//Usage:
// param X, Y, Z: The location of the box (center)
// param xrot, yrot, zrot: the rotation of the box.
// param source_data->x_radius, source_data->y_radius, source_data->z_radius: the X, Y, and Z radius of the box.
//note: export models as -Y forward, Z up.
// param bbox: the bounding box struct to be modified.
// Something's wrong with this, because X+ is the same as X-. Do not use it.
void makeBoundBox(_object_arguments * source_data, int euler)
{
FIXED prevXpos[XYZ];
prevXpos[X] = source_data->modified_box->Xplus[X];
prevXpos[Y] = source_data->modified_box->Xplus[Y];
prevXpos[Z] = source_data->modified_box->Xplus[Z];
FIXED prevYpos[XYZ];
prevYpos[X] = source_data->modified_box->Yplus[X];
prevYpos[Y] = source_data->modified_box->Yplus[Y];
prevYpos[Z] = source_data->modified_box->Yplus[Z];
FIXED prevZpos[XYZ];
prevZpos[X] = source_data->modified_box->Zplus[X];
prevZpos[Y] = source_data->modified_box->Zplus[Y];
prevZpos[Z] = source_data->modified_box->Zplus[Z];
FIXED prevNXpos[XYZ];
prevNXpos[X] = source_data->modified_box->Xneg[X];
prevNXpos[Y] = source_data->modified_box->Xneg[Y];
prevNXpos[Z] = source_data->modified_box->Xneg[Z];
FIXED prevNYpos[XYZ];
prevNYpos[X] = source_data->modified_box->Yneg[X];
prevNYpos[Y] = source_data->modified_box->Yneg[Y];
prevNYpos[Z] = source_data->modified_box->Yneg[Z];
FIXED prevNZpos[XYZ];
prevNZpos[X] = source_data->modified_box->Zneg[X];
prevNZpos[Y] = source_data->modified_box->Zneg[Y];
prevNZpos[Z] = source_data->modified_box->Zneg[Z];
//Give the box its previous location
source_data->modified_box->prevPos[X] = source_data->modified_box->pos[X];
source_data->modified_box->prevPos[Y] = source_data->modified_box->pos[Y];
source_data->modified_box->prevPos[Z] = source_data->modified_box->pos[Z];
//Give the box its location
source_data->modified_box->pos[X] = source_data->x_location;
source_data->modified_box->pos[Y] = source_data->y_location;
source_data->modified_box->pos[Z] = source_data->z_location;
//Give the box its rotation
source_data->modified_box->boxRot[X] = source_data->x_rotation;
source_data->modified_box->boxRot[Y] = source_data->y_rotation;
source_data->modified_box->boxRot[Z] = source_data->z_rotation;
//Give the box its radius
source_data->modified_box->brad[X] = source_data->x_radius;
source_data->modified_box->brad[Y] = source_data->y_radius;
source_data->modified_box->brad[Z] = source_data->z_radius;
//SETUP UNIT VECTOR X
int unitX[3] = {65536, 0, 0};
int unitY[3] = {0, 65536, 0};
int unitZ[3] = {0, 0, 65536};
//Passing vector used as some RAM to throw the vector around safely.
int unitP[3] = {0, 0, 0};
if(euler == 0)
{
///////////////////////////////////////////////////////////////////////////
// Matches XYZ Euler in Blender, but is actually XZY Euler.
// Because Y and Z are swapped.
///////////////////////////////////////////////////////////////////////////
//Calculate UVX
fxrotX(unitX, unitP, source_data->modified_box->boxRot[X]);
fxrotZ(unitP, unitX, source_data->modified_box->boxRot[Z]);
fxrotY(unitX, source_data->modified_box->UVX, source_data->modified_box->boxRot[Y]);
//Calculate UVY
fxrotX(unitY, unitP, source_data->modified_box->boxRot[X]);
fxrotZ(unitP, unitY, source_data->modified_box->boxRot[Z]);
fxrotY(unitY, source_data->modified_box->UVY, source_data->modified_box->boxRot[Y]);
//Calculate UVZ
fxrotX(unitZ, unitP, source_data->modified_box->boxRot[X]);
fxrotZ(unitP, unitZ, source_data->modified_box->boxRot[Z]);
fxrotY(unitZ, source_data->modified_box->UVZ, source_data->modified_box->boxRot[Y]);
} else if(euler == 1)
{
///////////////////////////////////////////////////////////////////////////
// YZX Euler
///////////////////////////////////////////////////////////////////////////
//Calculate UVX
fxrotY(unitX, unitP, source_data->modified_box->boxRot[Y]);
fxrotZ(unitP, unitX, source_data->modified_box->boxRot[Z]);
fxrotX(unitX, source_data->modified_box->UVX, source_data->modified_box->boxRot[X]);
//Calculate UVY
fxrotY(unitY, unitP, source_data->modified_box->boxRot[Y]);
fxrotZ(unitP, unitY, source_data->modified_box->boxRot[Z]);
fxrotX(unitY, source_data->modified_box->UVY, source_data->modified_box->boxRot[X]);
//Calculate UVZ
fxrotY(unitZ, unitP, source_data->modified_box->boxRot[Y]);
fxrotZ(unitP, unitZ, source_data->modified_box->boxRot[Z]);
fxrotX(unitZ, source_data->modified_box->UVZ, source_data->modified_box->boxRot[X]);
}
source_data->modified_box->Xplus[X] = fxm((source_data->modified_box->brad[X]), source_data->modified_box->UVX[X]);
source_data->modified_box->Xplus[Y] = fxm((source_data->modified_box->brad[X]), source_data->modified_box->UVX[Y]);
source_data->modified_box->Xplus[Z] = fxm((source_data->modified_box->brad[X]), source_data->modified_box->UVX[Z]);
source_data->modified_box->Yplus[X] = fxm((source_data->modified_box->brad[Y]), source_data->modified_box->UVY[X]);
source_data->modified_box->Yplus[Y] = fxm((source_data->modified_box->brad[Y]), source_data->modified_box->UVY[Y]);
source_data->modified_box->Yplus[Z] = fxm((source_data->modified_box->brad[Y]), source_data->modified_box->UVY[Z]);
source_data->modified_box->Zplus[X] = fxm((source_data->modified_box->brad[Z]), source_data->modified_box->UVZ[X]);
source_data->modified_box->Zplus[Y] = fxm((source_data->modified_box->brad[Z]), source_data->modified_box->UVZ[Y]);
source_data->modified_box->Zplus[Z] = fxm((source_data->modified_box->brad[Z]), source_data->modified_box->UVZ[Z]);
//---------------------------------------------------------------------------------------------------------------
source_data->modified_box->UVNX[X] = -source_data->modified_box->UVX[X];
source_data->modified_box->UVNX[Y] = -source_data->modified_box->UVX[Y];
source_data->modified_box->UVNX[Z] = -source_data->modified_box->UVX[Z];
source_data->modified_box->UVNY[X] = -source_data->modified_box->UVY[X];
source_data->modified_box->UVNY[Y] = -source_data->modified_box->UVY[Y];
source_data->modified_box->UVNY[Z] = -source_data->modified_box->UVY[Z];
source_data->modified_box->UVNZ[X] = -source_data->modified_box->UVZ[X];
source_data->modified_box->UVNZ[Y] = -source_data->modified_box->UVZ[Y];
source_data->modified_box->UVNZ[Z] = -source_data->modified_box->UVZ[Z];
//axis given: Y (on Z axis and does not change Y axis) circle going only right/left, forward/backward
source_data->modified_box->Xneg[X] = -source_data->modified_box->Xplus[X];
source_data->modified_box->Xneg[Y] = -source_data->modified_box->Xplus[Y];
source_data->modified_box->Xneg[Z] = -source_data->modified_box->Xplus[Z];
//axis given: X (on Y axis and does not change X axis) circle going only up/down, forward/backward
source_data->modified_box->Yneg[X] = -source_data->modified_box->Yplus[X];
source_data->modified_box->Yneg[Y] = -source_data->modified_box->Yplus[Y];
source_data->modified_box->Yneg[Z] = -source_data->modified_box->Yplus[Z];
//axis given: Z (on X axis and does not change Z axis) Circle going only up/down, left/right
source_data->modified_box->Zneg[X] = -source_data->modified_box->Zplus[X];
source_data->modified_box->Zneg[Y] = -source_data->modified_box->Zplus[Y];
source_data->modified_box->Zneg[Z] = -source_data->modified_box->Zplus[Z];
//end of negative
//Determine a velocity from the difference of current and last position
segment_to_vector(source_data->modified_box->prevPos, source_data->modified_box->pos, source_data->modified_box->velocity);
segment_to_vector(prevXpos, source_data->modified_box->Xplus, source_data->modified_box->veloX);
segment_to_vector(prevYpos, source_data->modified_box->Yplus, source_data->modified_box->veloY);
segment_to_vector(prevZpos, source_data->modified_box->Zplus, source_data->modified_box->veloZ);
segment_to_vector(prevNXpos, source_data->modified_box->Xneg, source_data->modified_box->veloNX);
segment_to_vector(prevNYpos, source_data->modified_box->Yneg, source_data->modified_box->veloNY);
segment_to_vector(prevNZpos, source_data->modified_box->Zneg, source_data->modified_box->veloNZ);
source_data->modified_box->nextPos[X] = source_data->x_location + fxm(source_data->modified_box->velocity[X], time_fixed_scale);
source_data->modified_box->nextPos[Y] = source_data->y_location + fxm(source_data->modified_box->velocity[Y], time_fixed_scale);
source_data->modified_box->nextPos[Z] = source_data->z_location + fxm(source_data->modified_box->velocity[Z], time_fixed_scale);
}
//Usage:
// param X, Y, Z: The location of the box (center)
// param xrot, yrot, zrot: the rotation of the box.
// param source_data->x_radius, source_data->y_radius, source_data->z_radius: the X, Y, and Z radius of the box.
// param bbox: the bounding box struct to be modified.
//Modified version to suit a Y axis gimbal lock. In other words, Y rotation is around a fixed post.
///Also, this doesn't make a box. It's just matrix generation, but with a radius and some velocities sprinkled on top; you can _make_ a box from it.
void make2AxisBox(_object_arguments * source_data)
{
FIXED prevXpos[XYZ];
prevXpos[X] = source_data->modified_box->Xplus[X];
prevXpos[Y] = source_data->modified_box->Xplus[Y];
prevXpos[Z] = source_data->modified_box->Xplus[Z];
FIXED prevYpos[XYZ];
prevYpos[X] = source_data->modified_box->Yplus[X];
prevYpos[Y] = source_data->modified_box->Yplus[Y];
prevYpos[Z] = source_data->modified_box->Yplus[Z];
FIXED prevZpos[XYZ];
prevZpos[X] = source_data->modified_box->Zplus[X];
prevZpos[Y] = source_data->modified_box->Zplus[Y];
prevZpos[Z] = source_data->modified_box->Zplus[Z];
FIXED prevNXpos[XYZ];
prevNXpos[X] = source_data->modified_box->Xneg[X];
prevNXpos[Y] = source_data->modified_box->Xneg[Y];
prevNXpos[Z] = source_data->modified_box->Xneg[Z];
FIXED prevNYpos[XYZ];
prevNYpos[X] = source_data->modified_box->Yneg[X];
prevNYpos[Y] = source_data->modified_box->Yneg[Y];
prevNYpos[Z] = source_data->modified_box->Yneg[Z];
FIXED prevNZpos[XYZ];
prevNZpos[X] = source_data->modified_box->Zneg[X];
prevNZpos[Y] = source_data->modified_box->Zneg[Y];
prevNZpos[Z] = source_data->modified_box->Zneg[Z];
//Give the box its previous location
source_data->modified_box->prevPos[X] = source_data->modified_box->pos[X];
source_data->modified_box->prevPos[Y] = source_data->modified_box->pos[Y];
source_data->modified_box->prevPos[Z] = source_data->modified_box->pos[Z];
//Give the box its location
source_data->modified_box->pos[X] = source_data->x_location;
source_data->modified_box->pos[Y] = source_data->y_location;
source_data->modified_box->pos[Z] = source_data->z_location;
//Give the box its rotation
source_data->modified_box->boxRot[X] = source_data->x_rotation;
source_data->modified_box->boxRot[Y] = source_data->y_rotation;
source_data->modified_box->boxRot[Z] = source_data->z_rotation;
//Give the box its radius
source_data->modified_box->brad[X] = source_data->x_radius;
source_data->modified_box->brad[Y] = source_data->y_radius;
source_data->modified_box->brad[Z] = source_data->z_radius;
FIXED sinX = slSin(source_data->modified_box->boxRot[X]);
FIXED cosX = slCos(source_data->modified_box->boxRot[X]);
FIXED sinY = slSin(source_data->modified_box->boxRot[Y]);
FIXED cosY = slCos(source_data->modified_box->boxRot[Y]);
FIXED sinZ = slSin(source_data->modified_box->boxRot[Z]);
FIXED cosZ = slCos(source_data->modified_box->boxRot[Z]);
//SETUP UNIT VECTOR X
///left - right points. Affected as: X rotation causes no movement. Y rotation causes movement on X-Z axis. Z rotation causes movement on Y-X axis.
source_data->modified_box->UVX[X] = fxm(cosY, cosZ) - fxm(fxm(sinY, -sinX), -sinZ);
source_data->modified_box->UVX[Y] = fxm(sinZ, cosX);
source_data->modified_box->UVX[Z] = -fxm(sinY, cosZ) - fxm(fxm(-sinX, -sinZ), cosY);
source_data->modified_box->Xplus[X] = fxm((source_data->x_radius), source_data->modified_box->UVX[X]);
source_data->modified_box->Xplus[Y] = fxm((source_data->x_radius), source_data->modified_box->UVX[Y]);
source_data->modified_box->Xplus[Z] = fxm((source_data->x_radius), source_data->modified_box->UVX[Z]);
//SETUP UNIT VECTOR Y
///up - down points. Affected as: X rotation causes movement on Y-Z axis. Y rotation causes no movement. Z rotation causes movement on Y-X axis.
source_data->modified_box->UVY[X] = -fxm(fxm(sinY, sinX), cosZ) - fxm(sinZ, cosY);
source_data->modified_box->UVY[Y] = fxm(cosX, cosZ);
source_data->modified_box->UVY[Z] = fxm(fxm(-sinX, cosY), cosZ) + fxm(sinZ, sinY);
source_data->modified_box->Yplus[X] = fxm((source_data->y_radius), source_data->modified_box->UVY[X]);
source_data->modified_box->Yplus[Y] = fxm((source_data->y_radius), source_data->modified_box->UVY[Y]);
source_data->modified_box->Yplus[Z] = fxm((source_data->y_radius), source_data->modified_box->UVY[Z]);
///Fwd - back points. Affected as: Y rotation causes movement on X-Z axis. X rotation causes movement on Y-Z. Z rotation causes no movement.
//SETUP UNIT VECTOR Z
source_data->modified_box->UVZ[X] = fxm(sinY, cosX);
source_data->modified_box->UVZ[Y] = (sinX);
source_data->modified_box->UVZ[Z] = fxm(cosX, cosY);
source_data->modified_box->Zplus[X] = fxm((source_data->z_radius), source_data->modified_box->UVZ[X]);
source_data->modified_box->Zplus[Y] = fxm((source_data->z_radius), source_data->modified_box->UVZ[Y]);
source_data->modified_box->Zplus[Z] = fxm((source_data->z_radius), source_data->modified_box->UVZ[Z]);
//---------------------------------------------------------------------------------------------------------------
source_data->modified_box->UVNX[X] = -source_data->modified_box->UVX[X];
source_data->modified_box->UVNX[Y] = -source_data->modified_box->UVX[Y];
source_data->modified_box->UVNX[Z] = -source_data->modified_box->UVX[Z];
source_data->modified_box->UVNY[X] = -source_data->modified_box->UVY[X];
source_data->modified_box->UVNY[Y] = -source_data->modified_box->UVY[Y];
source_data->modified_box->UVNY[Z] = -source_data->modified_box->UVY[Z];
source_data->modified_box->UVNZ[X] = -source_data->modified_box->UVZ[X];
source_data->modified_box->UVNZ[Y] = -source_data->modified_box->UVZ[Y];
source_data->modified_box->UVNZ[Z] = -source_data->modified_box->UVZ[Z];
//axis given: Y (on Z axis and does not change Y axis) circle going only right/left, forward/backward
source_data->modified_box->Xneg[X] = -source_data->modified_box->Xplus[X];
source_data->modified_box->Xneg[Y] = -source_data->modified_box->Xplus[Y];
source_data->modified_box->Xneg[Z] = -source_data->modified_box->Xplus[Z];
//axis given: X (on Y axis and does not change X axis) circle going only up/down, forward/backward
source_data->modified_box->Yneg[X] = -source_data->modified_box->Yplus[X];
source_data->modified_box->Yneg[Y] = -source_data->modified_box->Yplus[Y];
source_data->modified_box->Yneg[Z] = -source_data->modified_box->Yplus[Z];
//axis given: Z (on X axis and does not change Z axis) Circle going only up/down, left/right
source_data->modified_box->Zneg[X] = -source_data->modified_box->Zplus[X];
source_data->modified_box->Zneg[Y] = -source_data->modified_box->Zplus[Y];
source_data->modified_box->Zneg[Z] = -source_data->modified_box->Zplus[Z];
//end of negative
//Determine a velocity from the difference of current and last position
segment_to_vector(source_data->modified_box->prevPos, source_data->modified_box->pos, source_data->modified_box->velocity);
segment_to_vector(prevXpos, source_data->modified_box->Xplus, source_data->modified_box->veloX);
segment_to_vector(prevYpos, source_data->modified_box->Yplus, source_data->modified_box->veloY);
segment_to_vector(prevZpos, source_data->modified_box->Zplus, source_data->modified_box->veloZ);
segment_to_vector(prevNXpos, source_data->modified_box->Xneg, source_data->modified_box->veloNX);
segment_to_vector(prevNYpos, source_data->modified_box->Yneg, source_data->modified_box->veloNY);
segment_to_vector(prevNZpos, source_data->modified_box->Zneg, source_data->modified_box->veloNZ);
source_data->modified_box->nextPos[X] = source_data->x_location + fxm(source_data->modified_box->velocity[X], time_fixed_scale);
source_data->modified_box->nextPos[Y] = source_data->y_location + fxm(source_data->modified_box->velocity[Y], time_fixed_scale);
source_data->modified_box->nextPos[Z] = source_data->z_location + fxm(source_data->modified_box->velocity[Z], time_fixed_scale);
}
void finalize_collision_proxy(_boundBox * box)
{
/*
Y- Z+
3-----------2
/ | /|
0---+--------1 |
X- | | | | X+
| 7--------+--6
| / |/
4------------5
Z- Y+
Verts
0 = X- Y- Z-
1 = X+ Y- Z-
2 = X+ Y- Z+
3 = X- Y- Z+
4 = X- Y+ Z-
5 = X+ Y+ Z-
6 = X+ Y+ Z+
7 = X- Y+ Z+
Polygons:
0: 3 - 2 - 1 - 0, normal Y-
1: 0 - 1 - 5 - 4, normal Z-
2: 0 - 4 - 7 - 3, normal X-
3: 4 - 5 - 6 - 7, normal Y+
4: 3 - 7 - 6 - 2, normal Z+
5: 1 - 2 - 6 - 5, normal X+
*/
box->nmtbl[0] = box->UVNY;
box->nmtbl[1] = box->UVNZ;
box->nmtbl[2] = box->UVNX;
box->nmtbl[3] = box->UVY;
box->nmtbl[4] = box->UVZ;
box->nmtbl[5] = box->UVX;
box->cftbl[0] = box->Yneg;
box->cftbl[1] = box->Zneg;
box->cftbl[2] = box->Xneg;
box->cftbl[3] = box->Yplus;
box->cftbl[4] = box->Zplus;
box->cftbl[5] = box->Xplus;
box->pntbl[0][X] = (box->Xneg[X] + box->Yneg[X] + box->Zneg[X] + box->pos[X]);
box->pntbl[0][Y] = (box->Xneg[Y] + box->Yneg[Y] + box->Zneg[Y] + box->pos[Y]);
box->pntbl[0][Z] = (box->Xneg[Z] + box->Yneg[Z] + box->Zneg[Z] + box->pos[Z]);
box->pntbl[1][X] = (box->Xplus[X] + box->Yneg[X] + box->Zneg[X] + box->pos[X]);
box->pntbl[1][Y] = (box->Xplus[Y] + box->Yneg[Y] + box->Zneg[Y] + box->pos[Y]);
box->pntbl[1][Z] = (box->Xplus[Z] + box->Yneg[Z] + box->Zneg[Z] + box->pos[Z]);
box->pntbl[2][X] = (box->Xplus[X] + box->Yneg[X] + box->Zplus[X] + box->pos[X]);
box->pntbl[2][Y] = (box->Xplus[Y] + box->Yneg[Y] + box->Zplus[Y] + box->pos[Y]);
box->pntbl[2][Z] = (box->Xplus[Z] + box->Yneg[Z] + box->Zplus[Z] + box->pos[Z]);
box->pntbl[3][X] = (box->Xneg[X] + box->Yneg[X] + box->Zplus[X] + box->pos[X]);
box->pntbl[3][Y] = (box->Xneg[Y] + box->Yneg[Y] + box->Zplus[Y] + box->pos[Y]);
box->pntbl[3][Z] = (box->Xneg[Z] + box->Yneg[Z] + box->Zplus[Z] + box->pos[Z]);
box->pntbl[4][X] = (box->Xneg[X] + box->Yplus[X] + box->Zneg[X] + box->pos[X]);
box->pntbl[4][Y] = (box->Xneg[Y] + box->Yplus[Y] + box->Zneg[Y] + box->pos[Y]);
box->pntbl[4][Z] = (box->Xneg[Z] + box->Yplus[Z] + box->Zneg[Z] + box->pos[Z]);
box->pntbl[5][X] = (box->Xplus[X] + box->Yplus[X] + box->Zneg[X] + box->pos[X]);
box->pntbl[5][Y] = (box->Xplus[Y] + box->Yplus[Y] + box->Zneg[Y] + box->pos[Y]);
box->pntbl[5][Z] = (box->Xplus[Z] + box->Yplus[Z] + box->Zneg[Z] + box->pos[Z]);
box->pntbl[6][X] = (box->Xplus[X] + box->Yplus[X] + box->Zplus[X] + box->pos[X]);
box->pntbl[6][Y] = (box->Xplus[Y] + box->Yplus[Y] + box->Zplus[Y] + box->pos[Y]);
box->pntbl[6][Z] = (box->Xplus[Z] + box->Yplus[Z] + box->Zplus[Z] + box->pos[Z]);
box->pntbl[7][X] = (box->Xneg[X] + box->Yplus[X] + box->Zplus[X] + box->pos[X]);
box->pntbl[7][Y] = (box->Xneg[Y] + box->Yplus[Y] + box->Zplus[Y] + box->pos[Y]);
box->pntbl[7][Z] = (box->Xneg[Z] + box->Yplus[Z] + box->Zplus[Z] + box->pos[Z]);
box->pltbl[0][0] = box->pntbl[3];
box->pltbl[0][1] = box->pntbl[2];
box->pltbl[0][2] = box->pntbl[1];
box->pltbl[0][3] = box->pntbl[0];
box->pltbl[1][0] = box->pntbl[0];
box->pltbl[1][1] = box->pntbl[1];
box->pltbl[1][2] = box->pntbl[5];
box->pltbl[1][3] = box->pntbl[4];
box->pltbl[2][0] = box->pntbl[0];
box->pltbl[2][1] = box->pntbl[4];
box->pltbl[2][2] = box->pntbl[7];
box->pltbl[2][3] = box->pntbl[3];
box->pltbl[3][0] = box->pntbl[4];
box->pltbl[3][1] = box->pntbl[5];
box->pltbl[3][2] = box->pntbl[6];
box->pltbl[3][3] = box->pntbl[7];
box->pltbl[4][0] = box->pntbl[3];
box->pltbl[4][1] = box->pntbl[7];
box->pltbl[4][2] = box->pntbl[6];
box->pltbl[4][3] = box->pntbl[2];
box->pltbl[5][0] = box->pntbl[1];
box->pltbl[5][1] = box->pntbl[2];
box->pltbl[5][2] = box->pntbl[6];
box->pltbl[5][3] = box->pntbl[5];
box->status[3] = 'B';
}
void set_box_scale(_boundBox * box, int sx, int sy, int sz)
{
box->status[4] = 'S';
box->renderScale[X] = sx;
box->renderScale[Y] = sy;
box->renderScale[Z] = sz;
//To scale a box, multiply through the matrix values (UVX,UVY,UVZ).
//Scaling a box is only valid for part of one frame. Be aware of that.
}
void apply_box_scale(_boundBox * box)
{
//A scaled box is not valid for collision.
//It could be made valid, but I don't want to.
box->status[1] = 'N';
box->UVX[X] = fxm(box->UVX[X], box->renderScale[X]);
box->UVX[Y] = fxm(box->UVX[Y], box->renderScale[Y]);
box->UVX[Z] = fxm(box->UVX[Z], box->renderScale[Z]);
box->UVY[X] = fxm(box->UVY[X], box->renderScale[X]);
box->UVY[Y] = fxm(box->UVY[Y], box->renderScale[Y]);
box->UVY[Z] = fxm(box->UVY[Z], box->renderScale[Z]);
box->UVZ[X] = fxm(box->UVZ[X], box->renderScale[X]);
box->UVZ[Y] = fxm(box->UVZ[Y], box->renderScale[Y]);
box->UVZ[Z] = fxm(box->UVZ[Z], box->renderScale[Z]);
}
void flush_boxes(int start)
{
////////////////////////////////////////////////////
//Flush boxes
//Very important for making sure things don't render when they aren't supposed to.
////////////////////////////////////////////////////
// First step: Copy the master's working RBB to the slave's working DBB.
////////////////////////////////////////////////////
//Afterwards, purge the boxes and proceed with the rest of the code which will update the boxes.
////////////////////////////////////////////////////
for(int i = start; i < MAX_PHYS_PROXY; i++)
{
//If you reach a box marked as void, stop. Don't need to go any further.
if(RBBs[i].boxID == BOXID_VOID) break;
RBBs[i].boxID = BOXID_VOID;
RBBs[i].collisionID = BOXID_VOID;
RBBs[i].status[0] = 'N';
RBBs[i].status[1] = 'N';
RBBs[i].status[2] = 'N';
RBBs[i].status[3] = 'N';
RBBs[i].status[4] = 'N';
RBBs[i].status[5] = 'N';
}
////////////////////////////////////////////////////
}
void initPhys(void){
//The bound box / matrix parameter struct has to be uncached, since it is shared between master & slave.
// But don't be stupid like I was for a long time. See, I used to put it in LWRAM. LWRAM is SLOW!!!!
RBBs = (_boundBox *)((unsigned int)(&BoundBoxHost[0]));
DBBs = (_boundBox *)((unsigned int)(&BoundBoxDraw[0]));
for(Uint8 x = 0; x<MAX_PHYS_PROXY; x++){
RBBs[x].status[0] = 'N';
RBBs[x].status[1] = 'N';
RBBs[x].status[2] = 'N';
RBBs[x].status[3] = 'N';
RBBs[x].status[4] = 'N';
RBBs[x].velocity[X] = 0;
RBBs[x].velocity[Y] = 0;
RBBs[x].velocity[Z] = 0;
RBBs[x].veloX[X] = 0;
RBBs[x].veloX[Y] = 0;
RBBs[x].veloX[Z] = 0;
RBBs[x].veloNX[X] = 0;
RBBs[x].veloNX[Y] = 0;
RBBs[x].veloNX[Z] = 0;
RBBs[x].veloY[X] = 0;
RBBs[x].veloY[Y] = 0;
RBBs[x].veloY[Z] = 0;
RBBs[x].veloNY[X] = 0;
RBBs[x].veloNY[Y] = 0;
RBBs[x].veloNY[Z] = 0;
RBBs[x].veloZ[X] = 0;
RBBs[x].veloZ[Y] = 0;
RBBs[x].veloZ[Z] = 0;
RBBs[x].veloNZ[X] = 0;
RBBs[x].veloNZ[Y] = 0;
RBBs[x].veloNZ[Z] = 0;
RBBs[x].boxID = -1;
RBBs[x].collisionID = -1;
}
}