MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FastVectorBBox

Function FastVectorBBox

physics/findintersection.h:251–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249#define Q_MIDDLE 2
250
251static inline bool FastVectorBBox(const float *min, const float *max, const float *origin, const float *dir) {
252 bool f_inside = true;
253 char quad[3];
254 int i;
255 float max_t[3];
256 float can_plane[3];
257 int which_plane;
258 float coord[3];
259
260 for (i = 0; i < 3; i++) {
261 if (origin[i] < min[i]) {
262 quad[i] = Q_LEFT;
263 can_plane[i] = min[i];
264 f_inside = false;
265 } else if (origin[i] > max[i]) {
266 quad[i] = Q_RIGHT;
267 can_plane[i] = max[i];
268 f_inside = false;
269 } else {
270 quad[i] = Q_MIDDLE;
271 }
272 }
273
274 if (f_inside) {
275 return true;
276 }
277
278 for (i = 0; i < 3; i++) {
279 if (quad[i] != Q_MIDDLE && dir[i] != 0.0f)
280 max_t[i] = (can_plane[i] - origin[i]) / dir[i];
281 else
282 max_t[i] = -1.0f;
283 }
284
285 which_plane = 0;
286
287 for (i = 0; i < 3; i++)
288 if (max_t[which_plane] < max_t[i])
289 which_plane = i;
290
291 if (max_t[which_plane] < 0.0f)
292 return false;
293
294 for (i = 0; i < 3; i++) {
295 if (which_plane != i) {
296 coord[i] = origin[i] + max_t[which_plane] * dir[i];
297
298 if ((quad[i] == Q_RIGHT && coord[i] < min[i]) || (quad[i] == Q_LEFT && coord[i] > max[i])) {
299 return false;
300 }
301 } else {
302 coord[i] = can_plane[i];
303 }
304 }
305
306 return true;
307}
308

Callers 1

fvi_roomFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected