FS2_Open
Open source remastering of the Freespace 2 engine
objcollide.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _COLLIDESTUFF_H
13 #define _COLLIDESTUFF_H
14 
15 #include "globalincs/pstypes.h"
16 
17 class object;
18 struct CFILE;
19 struct mc_info;
20 
21 // used for ship:ship and ship:debris
22 typedef struct collision_info_struct {
23  object *heavy;
24  object *light;
25  vec3d heavy_collision_cm_pos; // should be zero
26  vec3d light_collision_cm_pos; // relative cm collision pos
27  vec3d r_heavy; // relative to A
28  vec3d r_light; // relative to B
29  vec3d hit_pos; // relative hit position in A's rf (r_heavy)
30  vec3d collision_normal; // normal outward from heavy
31  float hit_time; // time normalized [0,1] when sphere hits model
32  float impulse; // damage scales according to impulse
33  vec3d light_rel_vel; // velocity of light relative to heavy before collison
34  int collide_rotate; // if collision is detected purely from rotation
35  int submodel_num; // submodel of heavy object that is hit
36  int edge_hit; // if edge is hit, need to change collision normal
37  int submodel_rot_hit; // if collision is against rotating submodel
38  bool is_landing; //SUSHI: Maybe treat current collision as a landing
40 
41 //Collision physics constants
42 #define COLLISION_FRICTION_FACTOR 0.0f //Default value if not set in ships.tbl
43 #define COLLISION_ROTATION_FACTOR 0.2f //Default value if not set in ships.tbl
44 #define MIN_LANDING_SOUND_VEL 2.0f
45 #define LANDING_POS_OFFSET 0.05f
46 
47 //===============================================================================
48 // GENERAL COLLISION DETECTION HELPER FUNCTIONS
49 // These are in CollideGeneral.cpp and are used by one or more of the collision-
50 // type specific collision modules.
51 //===============================================================================
52 
53 // Keeps track of pairs of objects for collision detection
54 typedef struct obj_pair {
55  object *a;
56  object *b;
58  int next_check_time; // a timestamp that when elapsed means to check for a collision
59  struct obj_pair *next;
60 } obj_pair;
61 
62 
63 #define COLLISION_OF(a,b) (((a)<<8)|(b))
64 
65 #define COLLISION_TYPE_NONE 0
66 #define COLLISION_TYPE_OLD 1 // checks all n objects with each other each frame
67 #define COLLISION_TYPE_NEW 2 // keeps track of collision pairs. throws out collisions that won't happen.
68 
69 extern int collision_type;
70 
71 #define SUBMODEL_NO_ROT_HIT 0
72 #define SUBMODEL_ROT_HIT 1
73 void set_hit_struct_info(collision_info_struct *hit, mc_info *mc, int submodel_rot_hit);
74 
75 void obj_pairs_close();
76 void obj_reset_pairs();
77 void obj_add_pair( object *A, object *B, int check_time = -1, int add_to_end = 0 );
78 
79 void obj_add_collider(int obj_index);
80 void obj_remove_collider(int obj_index);
81 void obj_reset_colliders();
82 
85 void obj_quicksort_colliders(SCP_vector<int> *list, int left, int right, int axis);
86 void obj_find_overlap_colliders(SCP_vector<int> *overlap_list_out, SCP_vector<int> *list, int axis, bool collide);
87 float obj_get_collider_endpoint(int obj_num, int axis, bool min);
88 void obj_collide_pair(object *A, object *B);
89 
90 // retimes all collision pairs to be checked (in 25ms by default)
91 void obj_all_collisions_retime(int checkdly=25);
92 void obj_collide_retime_cached_pairs(int checkdly=25);
93 
94 // Returns TRUE if the weapon will never hit the other object.
95 // If it can it predicts how long until these two objects need
96 // to be checked and fills the time in in current_pair.
97 // CODE is locatated in CollideGeneral.cpp
98 int weapon_will_never_hit( object *weapon, object *other, obj_pair * current_pair );
99 
100 
101 // See if two lines intersect by doing recursive subdivision.
102 // Bails out if larger distance traveled is less than sum of radii + 1.0f.
103 // CODE is locatated in CollideGeneral.cpp
104 int collide_subdivide(vec3d *p0, vec3d *p1, float prad, vec3d *q0, vec3d *q1, float qrad);
105 
106 
107 //===============================================================================
108 // SPECIFIC COLLISION DETECTION FUNCTIONS
109 //===============================================================================
110 
111 // Checks weapon-weapon collisions. pair->a and pair->b are weapons.
112 // Returns 1 if all future collisions between these can be ignored
113 // CODE is locatated in CollideWeaponWeapon.cpp
114 int collide_weapon_weapon( obj_pair * pair );
115 
116 // Checks ship-weapon collisions. pair->a is ship and pair->b is weapon.
117 // Returns 1 if all future collisions between these can be ignored
118 // CODE is locatated in CollideShipWeapon.cpp
119 int collide_ship_weapon( obj_pair * pair );
120 void ship_weapon_do_hit_stuff(object *pship_obj, object *weapon_obj, vec3d *world_hitpos, vec3d *hitpos, int quadrant_num, int submodel_num = -1);
121 
122 // Checks debris-weapon collisions. pair->a is debris and pair->b is weapon.
123 // Returns 1 if all future collisions between these can be ignored
124 // CODE is locatated in CollideDebrisWeapon.cpp
125 int collide_debris_weapon( obj_pair * pair );
126 
127 // Checks debris-ship collisions. pair->a is debris and pair->b is ship.
128 // Returns 1 if all future collisions between these can be ignored
129 // CODE is locatated in CollideDebrisShip.cpp
130 int collide_debris_ship( obj_pair * pair );
131 
134 
135 // Checks ship-ship collisions. pair->a and pair->b are ships.
136 // Returns 1 if all future collisions between these can be ignored
137 // CODE is locatated in CollideShipShip.cpp
138 int collide_ship_ship( obj_pair * pair );
139 
140 // Predictive functions.
141 // Returns true if vector from curpos to goalpos with radius radius will collide with object goalobjp
142 int pp_collide(vec3d *curpos, vec3d *goalpos, object *goalobjp, float radius);
143 
144 // Return true if objp will collide with some large ship if it moves distance distance.
145 int collide_predict_large_ship(object *objp, float distance);
146 
147 // function to remove old weapons when no more weapon slots available.
148 int collide_remove_weapons(void);
149 
150 void collide_ship_ship_do_sound(vec3d *world_hit_pos, object *A, object *B, int player_involved);
152 
153 int get_ship_quadrant_from_global(vec3d *global_pos, object *objp);
154 
155 int reject_due_collision_groups(object *A, object *B);
156 
158 #endif
void set_hit_struct_info(collision_info_struct *hit, mc_info *mc, int submodel_rot_hit)
void obj_remove_collider(int obj_index)
void obj_check_all_collisions()
Definition: objcollide.cpp:530
int collision_type
int collide_debris_ship(obj_pair *pair)
void obj_reset_pairs()
Definition: objcollide.cpp:98
void obj_add_collider(int obj_index)
int(* check_collision)(obj_pair *pair)
Definition: objcollide.h:57
Definition: weapon.h:163
int collide_ship_ship(obj_pair *pair)
Definition: pstypes.h:88
void obj_reset_colliders()
hull_check p0
Definition: lua.cpp:5051
int reject_due_collision_groups(object *A, object *B)
Definition: objcollide.cpp:165
void init_collision_info_struct(collision_info_struct *cis)
Definition: cfile.h:28
void obj_find_overlap_colliders(SCP_vector< int > *overlap_list_out, SCP_vector< int > *list, int axis, bool collide)
int get_ship_quadrant_from_global(vec3d *global_pos, object *objp)
matrix * B
Definition: lua.cpp:445
object * objp
Definition: lua.cpp:3105
int next_check_time
Definition: objcollide.h:58
void obj_collide_retime_cached_pairs(int checkdly=25)
hull_check submodel_num
Definition: lua.cpp:5048
int collide_asteroid_weapon(obj_pair *pair)
vec3d heavy_collision_cm_pos
Definition: objcollide.h:25
void collide_ship_ship_do_sound(vec3d *world_hit_pos, object *A, object *B, int player_involved)
void obj_pairs_close()
Definition: objcollide.cpp:70
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
void obj_quicksort_colliders(SCP_vector< int > *list, int left, int right, int axis)
object * a
Definition: objcollide.h:55
int collide_asteroid_ship(obj_pair *pair)
int pp_collide(vec3d *curpos, vec3d *goalpos, object *goalobjp, float radius)
Definition: objcollide.cpp:926
int collide_weapon_weapon(obj_pair *pair)
void obj_all_collisions_retime(int checkdly=25)
Definition: objcollide.cpp:80
struct obj_pair * next
Definition: objcollide.h:59
mc_info * collide
Definition: lua.cpp:4532
hull_check p1
Definition: lua.cpp:5052
Definition: object.h:141
void ship_weapon_do_hit_stuff(object *pship_obj, object *weapon_obj, vec3d *world_hitpos, vec3d *hitpos, int quadrant_num, int submodel_num=-1)
int collide_debris_weapon(obj_pair *pair)
int collide_ship_weapon(obj_pair *pair)
GLdouble GLdouble right
Definition: Glext.h:10330
struct obj_pair obj_pair
struct collision_info_struct collision_info_struct
void collide_ship_ship_sounds_init()
int collide_subdivide(vec3d *p0, vec3d *p1, float prad, vec3d *q0, vec3d *q1, float qrad)
Definition: objcollide.cpp:628
object * b
Definition: objcollide.h:56
int collide_predict_large_ship(object *objp, float distance)
Definition: objcollide.cpp:967
int weapon_will_never_hit(object *weapon, object *other, obj_pair *current_pair)
Definition: objcollide.cpp:730
void obj_collide_pair(object *A, object *B)
int collide_remove_weapons(void)
matrix * A
Definition: lua.cpp:444
void obj_sort_and_collide()
void obj_add_pair(object *A, object *B, int check_time=-1, int add_to_end=0)
Definition: objcollide.cpp:174
float obj_get_collider_endpoint(int obj_num, int axis, bool min)
vec3d light_collision_cm_pos
Definition: objcollide.h:26
GLint left
Definition: Glext.h:7283