Debian Codegraph @

physics/findintersection.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/lib/findintersection.h $
21 * $Revision: 51 $
22 * $Date: 6/10/99 6:32p $
23 * $Author: Chris $
24 *
25 * Find intersection header
26 *
27 * $Log: /DescentIII/Main/lib/findintersection.h $
28 *
29 * 51 6/10/99 6:32p Chris
30 * New Editor Support
31 *
32 * 50 5/18/99 11:10a Matt
33 * Added variable ceiling height.
34 *
35 * 49 4/20/99 8:14p Chris
36 * Added support for object's that hit the ceiling and for making the
37 * level always check for the ceiling (inside and outside the mine)
38 *
39 * 48 1/15/99 5:59p Chris
40 *
41 * 47 1/13/99 2:29a Chris
42 * Massive AI, OSIRIS update
43 *
44 * 46 1/05/99 12:24p Chris
45 * More OSIRIS improvements
46 *
47 * 45 1/01/99 4:10p Chris
48 * Added some const parameters, improved ray cast object collide/rejection
49 * code
50 *
51 * 44 11/23/98 11:07a Chris
52 * Added another parameter to fvi_QuickDistObjectList
53 *
54 * 43 10/29/98 5:20p Chris
55 * Player ships collide smaller now
56 *
57 * 42 10/22/98 10:25p Kevin
58 * took out volatile
59 *
60 * 41 10/21/98 9:41p Chris
61 * Improved walking code!
62 *
63 * 40 10/17/98 12:25p Chris
64 * Fixed attached flares
65 *
66 * 39 10/16/98 8:33p Chris
67 * Fixed attached flare problem
68 *
69 * 38 10/16/98 3:39p Chris
70 * Improved the object linking system and AI and physics
71 *
72 * 37 10/16/98 1:07p Chris
73 * Lowered the max hits to 2 for now (we don't even use the info anyhow)
74 *
75 * 36 8/03/98 3:59p Chris
76 * Added support for FQ_IGNORE_WEAPONS, added .000001 attach code, fix a
77 * bug in polymodel collision detection
78 *
79 * 35 7/23/98 12:46p Chris
80 * Added a flag to ignore external rooms
81 *
82 * 34 7/02/98 2:51p Chris
83 * Added a fast line to bbox function
84 *
85 * 33 6/15/98 7:01a Chris
86 * Cleaned out DII stuff and added new PhysicsSim extern's
87 *
88 * 32 6/03/98 6:42p Chris
89 * Added multipoint collision detection an Assert on invalid (infinite
90 * endpoint).
91 *
92 * 31 5/22/98 4:44p Chris
93 * Added better melee hit prediction
94 *
95 * 30 5/05/98 5:23p Chris
96 * Faster external room collisions with FQ_EXTERNAL_ROOMS_AS_SPHERE
97 *
98 * 29 3/23/98 11:37a Chris
99 * Added the f_lightmap_only parameter to fvi_QuickDistObjectList
100 *
101 * 28 3/23/98 11:18a Chris
102 * Added int fvi_QuickDistObjectList(vector *pos, int init_room_index,
103 * float rad, int16_t *object_index_list, int max_elements)
104 *
105 *
106 * 27 3/17/98 11:33a Chris
107 * Improved performance (AABB updates on poly-sphere collide)
108 *
109 * 26 3/16/98 12:50p Chris
110 * Speed up?
111 *
112 * 25 3/16/98 9:43a Chris
113 * Added FQ_NO_RELINK
114 *
115 * 24 2/19/98 6:17p Chris
116 * Added some debug info
117 *
118 * 23 2/11/98 10:04p Chris
119 * Added FQ_ONLY_DOOR_OBJ and fixed a bug with FQ_ONLY_PLAYER_OBJ
120 *
121 * 22 2/04/98 6:09p Matt
122 * Changed object room number to indicate a terrain cell via a flag. Got
123 * rid of the object flag which used to indicate terrain.
124 *
125 * 21 1/30/98 4:34p Jason
126 * FROM CHRIS: Changed COL_CELL size to 1
127 *
128 * 20 1/20/98 11:35a Chris
129 * Raised ceiling to MAX_TERRAIN_HEIGHT
130 *
131 * 19 1/19/98 5:05p Chris
132 * Added ceiling collisions for players and powerups
133 *
134 * 18 12/16/97 6:11p Chris
135 * Attempt to improve FVI for outside
136 *
137 * 17 10/28/97 5:46p Chris
138 * Added a quick cell list function
139 *
140 * 16 10/28/97 12:20p Chris
141 * Added support to ignore wall collisions
142 *
143 * 15 10/22/97 12:41p Chris
144 * Incremental BBOX stuff and added support for subobject hit returned
145 * from fvi
146 *
147 * 14 10/07/97 4:03p Chris
148 * Added support for object backface checking
149 *
150 * 13 10/06/97 10:52a Jason
151 * added "FQ_IGNORE_NON_LIGHTMAP_OBJECTS" flag
152 *
153 * 12 9/19/97 6:58p Chris
154 * Fixed some bugs with the big object system and removed some annoying
155 * mprintf's
156 *
157 * 11 9/19/97 1:01p Chris
158 * Added better large object support
159 *
160 * 10 9/17/97 11:00a Chris
161 * Removed dependance on segment.h
162 *
163 * 9 9/15/97 6:24p Chris
164 * Added a second chance check if no rooms are initialy found
165 *
166 * 8 9/15/97 5:20a Chris
167 * Added sphere2poly support. Rearranged object collisions.
168 *
169 * 7 9/12/97 6:36p Chris
170 * Added collision terrain segment support
171 * Added some LARGE OBJECT collision support
172 *
173 * 6 9/11/97 3:08p Chris
174 * Added support for weapons flying through holes in transparent textures.
175 *
176 * 5 9/11/97 12:43p Chris
177 * Added new support for face_physics_info from room.h. Also, changed how
178 * we detect portals. Also added recorded faces.
179 *
180 * 4 9/02/97 11:41a Chris
181 * Added support the the quick face/room from distance function
182 *
183 * 3 8/18/97 1:53a Chris
184 * Added fvi_Relink
185 *
186 * 2 8/04/97 5:35p Chris
187 * Added support for back face collisions and new fvi code
188 *
189 * 10 6/11/97 10:43a Chris
190 *
191 * 9 6/10/97 5:34p Chris
192 *
193 * 8 5/13/97 5:52p Chris
194 * Added ability to exit and enter mine. Also did some
195 * incremental improvements.
196 *
197 * 7 5/05/97 5:41a Chris
198 * Added some better polygon collision code. It is still rough though.
199 *
200 * 6 4/17/97 3:10p Chris
201 * Added edge of world object delete. Also did some incremental
202 * improvements.
203 *
204 * 5 4/15/97 4:15p Chris
205 *
206 * 4 3/24/97 12:18p Chris
207 *
208 * 3 3/03/97 1:02p Chris
209 *
210 * 2 3/03/97 5:52a Chris
211 * Pre-alpha 0.01 -- just a starting point that compiles
212 *
213 * 1 3/03/97 3:26a Chris
214 *
215 * $NoKeywords: $
216 */
217
218 #ifndef FVI_H
219 #define FVI_H
220
221 #include "object.h"
222 #include "vecmat.h"
223 #include "terrain.h"
224 #include "findintersection_external.h"
225
226 extern float Ceiling_height;
227
228 #define CEILING_HEIGHT (Ceiling_height)
229
230 #define PLAYER_SIZE_SCALAR 0.8f
231
232 extern bool FVI_always_check_ceiling;
233
234 // Big Object Info
235 #define CELLS_PER_COL_CELL 1
236 #define COL_TERRAIN_SIZE (TERRAIN_SIZE * (float)CELLS_PER_COL_CELL)
237
238 #define MIN_BIG_OBJ_RAD (COL_TERRAIN_SIZE)
239
240 // chrishack -- we could turn backface, on and off so that we
241 // can individually use backface checking on object and/or wall... :)
242
243 #define MAX_FVI_SEGS 100
244
245 #define MAX_HITS 2
246
247 #define Q_RIGHT 0
248 #define Q_LEFT 1
249 #define Q_MIDDLE 2
250
251 static 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
309 // this data structure gets filled in by find_vector_intersection()
310 struct fvi_info {
311 vector hit_pnt; // centerpoint when we hit
312 int hit_room; // what room hit_pnt is in
313 float hit_dist; // distance of the hit
314
315 int num_hits; // Number of recorded hits
316
317 int hit_type[MAX_HITS]; // what sort of intersection
318 vector hit_face_pnt[MAX_HITS]; // actual collision point (edge of rad)
319
320 int hit_face_room[MAX_HITS]; // what room the hit face is in
321 int hit_face[MAX_HITS]; // if hit wall, which face
322 vector hit_wallnorm[MAX_HITS]; // if hit wall, ptr to its surface normal
323
324 int hit_object[MAX_HITS]; // if object hit, which object
325 int hit_subobject[MAX_HITS]; // if a POLY_2_SPHERE hit, then it has the poly involved
326
327 int n_rooms; // how many segs we went through
328 int roomlist[MAX_FVI_SEGS]; // list of segs vector went through
329
330 // BBox hit results
331 matrix hit_orient;
332 vector hit_rotvel;
333 angle hit_turnroll;
334 vector hit_velocity;
335 float hit_time;
336
337 vector hit_subobj_fvec;
338 vector hit_subobj_uvec;
339 vector hit_subobj_pos;
340 };
341
342 // this data contains the parms to fvi()
343 struct fvi_query {
344 vector *p0, *p1;
345 int startroom;
346 float rad;
347 int16_t thisobjnum;
348 int *ignore_obj_list;
349 int flags;
350
351 // BBox stuff...
352 matrix *o_orient;
353 vector *o_rotvel;
354 vector *o_rotthrust;
355 vector *o_velocity;
356 angle *o_turnroll;
357 vector *o_thrust;
358 float frametime;
359 };
360
361 // Find out if a vector intersects with anything.
362 // Fills in hit_data, an fvi_info structure (see above).
363 // Parms:
364 // p0 & startseg describe the start of the vector
365 // p1 the end of the vector
366 // rad the radius of the cylinder
367 // thisobjnum used to prevent an object with colliding with itself
368 // ingore_obj_list NULL, or ptr to a list of objnums to ignore, terminated with -1
369 // check_obj_flag determines whether collisions with objects are checked
370 // Returns the hit_data->hit_type
371 extern int fvi_FindIntersection(fvi_query *fq, fvi_info *hit_data, bool no_subdivision = false);
372
373 // Face/Room list for some fvi call(s)
374 struct fvi_face_room_list {
375 uint16_t face_index;
376 uint16_t room_index;
377 };
378
379 #define MAX_RECORDED_FACES 200
380
381 // Recorded face list
382 extern fvi_face_room_list Fvi_recorded_faces[MAX_RECORDED_FACES];
383 extern int Fvi_num_recorded_faces;
384
385 // Generates a list of faces(with corresponding room numbers) within a given distance to a position.
386 // Return value is the number of faces in the list
387 extern int fvi_QuickDistFaceList(int init_room_index, vector *pos, float rad, fvi_face_room_list *quick_fr_list,
388 int max_elements);
389 // Returns the number of cells that are approximately within the specified radius
390 extern int fvi_QuickDistCellList(int init_cell_index, vector *pos, float rad, int *quick_cell_list, int max_elements);
391
392 // Returns the number of objects that are approximately within the specified radius
393 int fvi_QuickDistObjectList(vector *pos, int init_roomnum, float rad, int16_t *object_index_list, int max_elements,
394 bool f_lightmap_only, bool f_only_players_and_ais = false,
395 bool f_include_non_collide_objects = false, bool f_stop_at_closed_doors = false);
396
397 // finds the uv coords of the given point on the given seg & side
398 // fills in u & v. if l is non-NULL fills it in also
399 // extern void fvi_FindHitpointUV(float *u,float *v,float *l, vector *pnt,segment *seg,int sidenum,int facenum);
400
401 // Returns true if the object is through any walls
402 extern int fvi_ObjectIntersectsWall(object *objp);
403
404 extern int FVI_counter;
405 extern int FVI_room_counter;
406
407 bool fvi_QuickRoomCheck(vector *pos, room *cur_room, bool try_again = false);
408
409 extern fvi_info *fvi_hit_data_ptr;
410 extern fvi_query *fvi_query_ptr;
411 extern float fvi_collision_dist;
412 extern int fvi_curobj;
413 extern int fvi_moveobj;
414
415 bool PolyCollideObject(object *obj);
416
417 bool BBoxPlaneIntersection(bool fast_exit, vector *collision_point, vector *collision_normal, object *obj,
418 vector *new_pos, int nv, vector **vertex_ptr_list, vector *face_normal, matrix *orient);
419
420 extern uint32_t check_point_to_face(vector *colp, vector *face_normal, int nv, vector **vertex_ptr_list);
421
422 extern int check_vector_to_sphere_1(vector *intp, float *col_dist, const vector *p0, const vector *p1,
423 vector *sphere_pos, float sphere_rad, bool f_correcting, bool f_init_collisions);
424
425 extern int check_line_to_face(vector *newp, vector *colp, float *col_dist, vector *wall_norm, const vector *p0,
426 const vector *p1, vector *face_normal, vector **vertex_ptr_list, const int nv,
427 const float rad);
428 extern void InitFVI();
429
430 // Types of supported collisions
431 #ifdef NED_PHYSICS
432 #define RESULT_NOTHING 0
433 #define RESULT_CHECK_SPHERE_SPHERE 1
434 #define RESULT_CHECK_SPHERE_POLY 2
435 #define RESULT_CHECK_POLY_SPHERE 3
436 #define RESULT_CHECK_BBOX_POLY 4
437 #define RESULT_CHECK_POLY_BBOX 5
438 #define RESULT_CHECK_BBOX_BBOX 6
439 #define RESULT_CHECK_BBOX_SPHERE 7
440 #define RESULT_CHECK_SPHERE_BBOX 8
441 #define RESULT_CHECK_SPHERE_ROOM 9
442 #define RESULT_CHECK_BBOX_ROOM 10
443 #endif
444
445 #endif