]> icculus.org git repositories - taylor/freespace2.git/blob - include/objcollide.h
Initial revision
[taylor/freespace2.git] / include / objcollide.h
1 /*
2  * $Logfile: /Freespace2/code/Object/ObjCollide.h $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Header file for all the Collide????.cpp modules
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:12  root
11  * Initial revision
12  *
13  * 
14  * 9     4/21/99 6:15p Dave
15  * Did some serious housecleaning in the beam code. Made it ready to go
16  * for anti-fighter "pulse" weapons. Fixed collision pair creation. Added
17  * a handy macro for recalculating collision pairs for a given object.
18  * 
19  * 8     11/19/98 11:08p Andsager
20  * Check in of physics and collision detection of rotating submodels
21  * 
22  * 7     11/17/98 4:33p Andsager
23  * add submodel_rot_hit to collision_info struct
24  * 
25  * 6     11/05/98 5:55p Dave
26  * Big pass at reducing #includes
27  * 
28  * 5     10/23/98 1:11p Andsager
29  * Make ship sparks emit correctly from rotating structures.
30  * 
31  * 4     10/20/98 1:39p Andsager
32  * Make so sparks follow animated ship submodels.  Modify
33  * ship_weapon_do_hit_stuff() and ship_apply_local_damage() to add
34  * submodel_num.  Add submodel_num to multiplayer hit packet.
35  * 
36  * 3     10/16/98 1:22p Andsager
37  * clean up header files
38  * 
39  * 2     10/07/98 10:53a Dave
40  * Initial checkin.
41  * 
42  * 1     10/07/98 10:50a Dave
43  * 
44  * 14    5/08/98 5:25p Lawrance
45  * Don't allow collision sounds too play over each so much
46  * 
47  * 13    4/24/98 5:35p Andsager
48  * Fix sparks sometimes drawing not on model.  If ship is sphere in
49  * collision, don't draw sparks.  Modify ship_apply_local_damage() to take
50  * parameter no_spark.
51  * 
52  * 12    4/01/98 1:48p Allender
53  * major changes to ship collision in multiplayer.  Clients now do own
54  * ship/ship collisions (with their own ship only)  Modifed the hull
55  * update packet to be sent quicker when object is target of player.
56  * 
57  * 11    2/26/98 10:07p Hoffoss
58  * Rewrote state saving and restoring to fix bugs and simplify the code.
59  * 
60  * 10    2/05/98 12:51a Mike
61  * Early asteroid stuff.
62  * 
63  * 9     2/04/98 6:08p Lawrance
64  * Add a light collision sound, overlay a shield collide sound if
65  * applicable.
66  * 
67  * 8     1/13/98 3:11p Allender
68  * new code to remove old weapons when no more weapon slots available.
69  * Currently not called anywhere pending further testing
70  * 
71  * 7     1/12/98 9:26p Andsager
72  * Implement collisions from rotation.
73  * 
74  * 6     1/08/98 12:12a Mike
75  * Make ships turn before warping out, if necessary, to avoid a collision.
76  * Warn player if his warpout will collide.  Abort if in stage1.
77  * 
78  * 5     1/05/98 9:07p Andsager
79  * Changed ship_shipor_debris_hit_info struct to more meaninful names
80  * 
81  * 4     12/22/97 9:56p Andsager
82  * Implement ship:debris collisions.  Generalize and move
83  * ship_ship_or_debris_hit struct from CollideShipShip to ObjCollide.h
84  * 
85  * 3     10/28/97 4:57p John
86  * Put Andsager's new sphereline collide code officially into the code
87  * base and did a little restructuring.  Fixed a few little bugs with it
88  * and added some simple bounding box elimination and did some timings.
89  * 
90  * 
91  * 2     10/25/97 10:13a Andsager
92  * Added SPHERE_POLY_CHECK to central location used by ModelCollide.cpp
93  * and Collide_ship_ship.cpp
94  * 
95  * 1     9/17/97 2:14p John
96  * Initial revision
97  *
98  * $NoKeywords: $
99  */
100
101 #ifndef _COLLIDESTUFF_H
102 #define _COLLIDESTUFF_H
103
104 #include "pstypes.h"
105
106 struct object;
107 struct CFILE;
108 struct mc_info;
109
110 // used for ship:ship and ship:debris
111 typedef struct collision_info_struct {
112         object  *heavy;
113         object  *light;
114         vector  heavy_collision_cm_pos; // should be zero
115         vector  light_collision_cm_pos; // relative cm collision pos
116         vector  r_heavy;                                                // relative to A
117         vector  r_light;                                                // relative to B
118         vector  hit_pos;                                        // relative hit position in A's rf (r_heavy)
119         vector  collision_normal;               // normal outward from heavy
120         float           hit_time;                               // time normalized [0,1] when sphere hits model
121         float           impulse;                                        // damage scales according to impulse
122         vector  light_rel_vel;                  // velocity of light relative to heavy before collison
123         int             collide_rotate;         // if collision is detected purely from rotation
124         int             submodel_num;                   // submodel of heavy object that is hit
125         int             edge_hit;                               // if edge is hit, need to change collision normal
126         int             submodel_rot_hit;               // if collision is against rotating submodel
127 } collision_info_struct;
128
129
130 //===============================================================================
131 // GENERAL COLLISION DETECTION HELPER FUNCTIONS 
132 // These are in CollideGeneral.cpp and are used by one or more of the collision-
133 // type specific collision modules.
134 //===============================================================================
135
136 // Keeps track of pairs of objects for collision detection
137 typedef struct obj_pair {
138         object *a;
139         object *b;
140         int (*check_collision)( obj_pair * pair );
141         int     next_check_time;        // a timestamp that when elapsed means to check for a collision
142         struct obj_pair *next;
143 } obj_pair;
144
145
146 #define COLLISION_OF(a,b) (((a)<<8)|(b))
147
148 #define COLLISION_TYPE_NONE     0       
149 #define COLLISION_TYPE_OLD              1       // checks all n objects with each other each frame
150 #define COLLISION_TYPE_NEW              2       // keeps track of collision pairs.  throws out collisions that won't happen.
151
152 extern int collision_type;
153
154 #define SUBMODEL_NO_ROT_HIT     0
155 #define SUBMODEL_ROT_HIT                1
156 void set_hit_struct_info(collision_info_struct *hit, mc_info *mc, int submodel_rot_hit);
157
158 void obj_reset_pairs();
159 void obj_add_pair( object *A, object *B, int check_time = -1, int add_to_end = 0 );
160
161 void obj_check_all_collisions();
162
163 // Returns TRUE if the weapon will never hit the other object.
164 // If it can it predicts how long until these two objects need
165 // to be checked and fills the time in in current_pair.
166 // CODE is locatated in CollideGeneral.cpp
167 int weapon_will_never_hit( object *weapon, object *other, obj_pair * current_pair );
168
169
170 //      See if two lines intersect by doing recursive subdivision.
171 //      Bails out if larger distance traveled is less than sum of radii + 1.0f.
172 // CODE is locatated in CollideGeneral.cpp
173 int collide_subdivide(vector *p0, vector *p1, float prad, vector *q0, vector *q1, float qrad);
174
175
176 //===============================================================================
177 // SPECIFIC COLLISION DETECTION FUNCTIONS 
178 //===============================================================================
179
180 // Checks weapon-weapon collisions.  pair->a and pair->b are weapons.
181 // Returns 1 if all future collisions between these can be ignored
182 // CODE is locatated in CollideWeaponWeapon.cpp
183 int collide_weapon_weapon( obj_pair * pair );
184
185 // Checks ship-weapon collisions.  pair->a is ship and pair->b is weapon.
186 // Returns 1 if all future collisions between these can be ignored
187 // CODE is locatated in CollideShipWeapon.cpp
188 int collide_ship_weapon( obj_pair * pair );
189 void ship_weapon_do_hit_stuff(object *ship_obj, object *weapon_obj, vector *world_hitpos, vector *hitpos, int quadrant_num, int submodel_num = -1);
190
191 // Checks debris-weapon collisions.  pair->a is debris and pair->b is weapon.
192 // Returns 1 if all future collisions between these can be ignored
193 // CODE is locatated in CollideDebrisWeapon.cpp
194 int collide_debris_weapon( obj_pair * pair );
195
196 // Checks debris-ship collisions.  pair->a is debris and pair->b is ship.
197 // Returns 1 if all future collisions between these can be ignored
198 // CODE is locatated in CollideDebrisShip.cpp
199 int collide_debris_ship( obj_pair * pair );
200
201 int collide_asteroid_ship(obj_pair *pair);
202 int collide_asteroid_weapon(obj_pair *pair);
203
204 // Checks ship-ship collisions.  pair->a and pair->b are ships.
205 // Returns 1 if all future collisions between these can be ignored
206 // CODE is locatated in CollideShipShip.cpp
207 int collide_ship_ship( obj_pair * pair );
208
209 //      Predictive functions.
210 //      Returns true if vector from curpos to goalpos with radius radius will collide with object goalobjp
211 int pp_collide(vector *curpos, vector *goalpos, object *goalobjp, float radius);
212
213 //      Return true if objp will collide with some large ship if it moves distance distance.
214 int collide_predict_large_ship(object *objp, float distance);
215
216 // function to remove old weapons when no more weapon slots available.
217 int collide_remove_weapons(void);
218
219 void collide_ship_ship_do_sound(vector *world_hit_pos, object *A, object *B, int player_involved);
220 void collide_ship_ship_sounds_init();
221
222 int get_ship_quadrant_from_global(vector *global_pos, object *objp);
223
224 #endif
225