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_Hcxx . . $ `physics/findintersection.h:219:9`!
220
221 #include "object.h"cxx . . $ `<file>/Descent3/object.h`/
222 #include "vecmat.h"cxx . . $ `<file>/lib/vecmat.h`/
223 #include "terrain.h"cxx . . $ `<file>/Descent3/terrain.h`/
224 #include "findintersection_external.h"cxx . . $ `<file>/lib/findintersection_external.h`/
225
226 extern float Ceiling_heightcxx . . $ Ceiling_height.;
227
228 #define CEILING_HEIGHTcxx . . $ `physics/findintersection.h:228:9`! (Ceiling_height)
229
230 #define PLAYER_SIZE_SCALARcxx . . $ `physics/findintersection.h:230:9`! 0.8f
231
232 extern bool FVI_always_check_ceilingcxx . . $ FVI_always_check_ceiling.;
233
234 // Big Object Info
235 #define CELLS_PER_COL_CELLcxx . . $ `physics/findintersection.h:235:9`! 1
236 #define COL_TERRAIN_SIZEcxx . . $ `physics/findintersection.h:236:9`! (TERRAIN_SIZE * (float)CELLS_PER_COL_CELL)
237
238 #define MIN_BIG_OBJ_RADcxx . . $ `physics/findintersection.h:238:9`! (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_SEGScxx . . $ `physics/findintersection.h:243:9`! 100
244
245 #define MAX_HITScxx . . $ `physics/findintersection.h:245:9`! 2
246
247 #define Q_RIGHTcxx . . $ `physics/findintersection.h:247:9`! 0
248 #define Q_LEFTcxx . . $ `physics/findintersection.h:248:9`! 1
249 #define Q_MIDDLEcxx . . $ `physics/findintersection.h:249:9`! 2
250
251 static inline bool FastVectorBBoxcxx . . $ FastVectorBBox(fddd3d59a725f9a2).(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_LEFTcxx . . $ `physics/findintersection.h:248:9`!;
263 can_plane[i] = min[i];
264 f_inside = false;
265 } else if (origin[i] > max[i]) {
266 quad[i] = Q_RIGHTcxx . . $ `physics/findintersection.h:247:9`!;
267 can_plane[i] = max[i];
268 f_inside = false;
269 } else {
270 quad[i] = Q_MIDDLEcxx . . $ `physics/findintersection.h:249:9`!;
271 }
272 }
273
274 if (f_inside) {
275 return true;
276 }
277
278 for (i = 0; i < 3; i++) {
279 if (quad[i] != Q_MIDDLEcxx . . $ `physics/findintersection.h:249:9`! && 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_RIGHTcxx . . $ `physics/findintersection.h:247:9`! && coord[i] < min[i]) || (quad[i] == Q_LEFTcxx . . $ `physics/findintersection.h:248:9`! && 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_infocxx . . $ fvi_info# {
311 vectorcxx . . $ vector# hit_pntcxx . . $ fvi_info#hit_pnt.; // centerpoint when we hit
312 int hit_roomcxx . . $ fvi_info#hit_room.; // what room hit_pnt is in
313 float hit_distcxx . . $ fvi_info#hit_dist.; // distance of the hit
314
315 int num_hitscxx . . $ fvi_info#num_hits.; // Number of recorded hits
316
317 int hit_typecxx . . $ fvi_info#hit_type.[MAX_HITScxx . . $ `physics/findintersection.h:245:9`!]; // what sort of intersection
318 vectorcxx . . $ vector# hit_face_pntcxx . . $ fvi_info#hit_face_pnt.[MAX_HITScxx . . $ `physics/findintersection.h:245:9`!]; // actual collision point (edge of rad)
319
320 int hit_face_roomcxx . . $ fvi_info#hit_face_room.[MAX_HITScxx . . $ `physics/findintersection.h:245:9`!]; // what room the hit face is in
321 int hit_facecxx . . $ fvi_info#hit_face.[MAX_HITScxx . . $ `physics/findintersection.h:245:9`!]; // if hit wall, which face
322 vectorcxx . . $ vector# hit_wallnormcxx . . $ fvi_info#hit_wallnorm.[MAX_HITScxx . . $ `physics/findintersection.h:245:9`!]; // if hit wall, ptr to its surface normal
323
324 int hit_objectcxx . . $ fvi_info#hit_object.[MAX_HITScxx . . $ `physics/findintersection.h:245:9`!]; // if object hit, which object
325 int hit_subobjectcxx . . $ fvi_info#hit_subobject.[MAX_HITScxx . . $ `physics/findintersection.h:245:9`!]; // if a POLY_2_SPHERE hit, then it has the poly involved
326
327 int n_roomscxx . . $ fvi_info#n_rooms.; // how many segs we went through
328 int roomlistcxx . . $ fvi_info#roomlist.[MAX_FVI_SEGScxx . . $ `physics/findintersection.h:243:9`!]; // list of segs vector went through
329
330 // BBox hit results
331 matrixcxx . . $ matrix# hit_orientcxx . . $ fvi_info#hit_orient.;
332 vectorcxx . . $ vector# hit_rotvelcxx . . $ fvi_info#hit_rotvel.;
333 anglecxx . . $ angle# hit_turnrollcxx . . $ fvi_info#hit_turnroll.;
334 vectorcxx . . $ vector# hit_velocitycxx . . $ fvi_info#hit_velocity.;
335 float hit_timecxx . . $ fvi_info#hit_time.;
336
337 vectorcxx . . $ vector# hit_subobj_fveccxx . . $ fvi_info#hit_subobj_fvec.;
338 vectorcxx . . $ vector# hit_subobj_uveccxx . . $ fvi_info#hit_subobj_uvec.;
339 vectorcxx . . $ vector# hit_subobj_poscxx . . $ fvi_info#hit_subobj_pos.;
340 };
341
342 // this data contains the parms to fvi()
343 struct fvi_querycxx . . $ fvi_query# {
344 vectorcxx . . $ vector# *p0cxx . . $ fvi_query#p0., *p1cxx . . $ fvi_query#p1.;
345 int startroomcxx . . $ fvi_query#startroom.;
346 float radcxx . . $ fvi_query#rad.;
347 int16_t thisobjnumcxx . . $ fvi_query#thisobjnum.;
348 int *ignore_obj_listcxx . . $ fvi_query#ignore_obj_list.;
349 int flagscxx . . $ fvi_query#flags.;
350
351 // BBox stuff...
352 matrixcxx . . $ matrix# *o_orientcxx . . $ fvi_query#o_orient.;
353 vectorcxx . . $ vector# *o_rotvelcxx . . $ fvi_query#o_rotvel.;
354 vectorcxx . . $ vector# *o_rotthrustcxx . . $ fvi_query#o_rotthrust.;
355 vectorcxx . . $ vector# *o_velocitycxx . . $ fvi_query#o_velocity.;
356 anglecxx . . $ angle# *o_turnrollcxx . . $ fvi_query#o_turnroll.;
357 vectorcxx . . $ vector# *o_thrustcxx . . $ fvi_query#o_thrust.;
358 float frametimecxx . . $ fvi_query#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_FindIntersectioncxx . . $ fvi_FindIntersection(e1c4d7bd350effc8).(fvi_querycxx . . $ fvi_query# *fq, fvi_infocxx . . $ fvi_info# *hit_data, bool no_subdivision = false);
372
373 // Face/Room list for some fvi call(s)
374 struct fvi_face_room_listcxx . . $ fvi_face_room_list# {
375 uint16_tcxx . . $ uint16_t# face_indexcxx . . $ fvi_face_room_list#face_index.;
376 uint16_tcxx . . $ uint16_t# room_indexcxx . . $ fvi_face_room_list#room_index.;
377 };
378
379 #define MAX_RECORDED_FACEScxx . . $ `physics/findintersection.h:379:9`! 200
380
381 // Recorded face list
382 extern fvi_face_room_listcxx . . $ fvi_face_room_list# Fvi_recorded_facescxx . . $ Fvi_recorded_faces.[MAX_RECORDED_FACEScxx . . $ `physics/findintersection.h:379:9`!];
383 extern int Fvi_num_recorded_facescxx . . $ 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_QuickDistFaceListcxx . . $ fvi_QuickDistFaceList(a662bbcbc4f3d9bd).(int init_room_index, vectorcxx . . $ vector# *pos, float rad, fvi_face_room_listcxx . . $ 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_QuickDistCellListcxx . . $ fvi_QuickDistCellList(2280b6e28a61436a).(int init_cell_index, vectorcxx . . $ 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_QuickDistObjectListcxx . . $ fvi_QuickDistObjectList(85643dfbd17d1ac8).(vectorcxx . . $ 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_ObjectIntersectsWallcxx . . $ fvi_ObjectIntersectsWall(2da2a862cad4c994).(objectcxx . . $ object# *objp);
403
404 extern int FVI_countercxx . . $ FVI_counter.;
405 extern int FVI_room_countercxx . . $ FVI_room_counter.;
406
407 bool fvi_QuickRoomCheckcxx . . $ fvi_QuickRoomCheck(46bb3ef3c66d3688).(vectorcxx . . $ vector# *pos, roomcxx . . $ room# *cur_room, bool try_again = false);
408
409 extern fvi_infocxx . . $ fvi_info# *fvi_hit_data_ptrcxx . . $ fvi_hit_data_ptr.;
410 extern fvi_querycxx . . $ fvi_query# *fvi_query_ptrcxx . . $ fvi_query_ptr.;
411 extern float fvi_collision_distcxx . . $ fvi_collision_dist.;
412 extern int fvi_curobjcxx . . $ fvi_curobj.;
413 extern int fvi_moveobjcxx . . $ fvi_moveobj.;
414
415 bool PolyCollideObjectcxx . . $ PolyCollideObject(39516aeee13ca5ab).(objectcxx . . $ object# *obj);
416
417 bool BBoxPlaneIntersectioncxx . . $ BBoxPlaneIntersection(7d87aea68d475c1c).(bool fast_exit, vectorcxx . . $ vector# *collision_point, vectorcxx . . $ vector# *collision_normal, objectcxx . . $ object# *obj,
418 vectorcxx . . $ vector# *new_pos, int nv, vectorcxx . . $ vector# **vertex_ptr_list, vectorcxx . . $ vector# *face_normal, matrixcxx . . $ matrix# *orient);
419
420 extern uint32_tcxx . . $ uint32_t# check_point_to_facecxx . . $ check_point_to_face(ccece0347280792).(vectorcxx . . $ vector# *colp, vectorcxx . . $ vector# *face_normal, int nv, vectorcxx . . $ vector# **vertex_ptr_list);
421
422 extern int check_vector_to_sphere_1cxx . . $ check_vector_to_sphere_1(ad73bf9bdb80d370).(vectorcxx . . $ vector# *intp, float *col_dist, const vectorcxx . . $ vector# *p0, const vectorcxx . . $ vector# *p1,
423 vectorcxx . . $ vector# *sphere_pos, float sphere_rad, bool f_correcting, bool f_init_collisions);
424
425 extern int check_line_to_facecxx . . $ check_line_to_face(3d5b8c488b5418a3).(vectorcxx . . $ vector# *newp, vectorcxx . . $ vector# *colp, float *col_dist, vectorcxx . . $ vector# *wall_norm, const vectorcxx . . $ vector# *p0,
426 const vectorcxx . . $ vector# *p1, vectorcxx . . $ vector# *face_normal, vectorcxx . . $ vector# **vertex_ptr_list, const int nv,
427 const float rad);
428 extern void InitFVIcxx . . $ InitFVI(49f6e7a06ebc5aa8).();
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