]> icculus.org git repositories - taylor/freespace2.git/blob - include/physics.h
Initial revision
[taylor/freespace2.git] / include / physics.h
1 /*
2  * $Logfile: /Freespace2/code/Physics/Physics.h $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Clues to the meaning of life on Shivan planet Sphlighesphlaightseh
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:12  root
11  * Initial revision
12  *
13  * 
14  * 6     8/13/99 10:49a Andsager
15  * Knossos and HUGE ship warp out.  HUGE ship warp in.  Stealth search
16  * modes dont collide big ships.
17  * 
18  * 5     7/03/99 5:50p Dave
19  * Make rotated bitmaps draw properly in padlock views.
20  * 
21  * 4     5/11/99 10:16p Andsager
22  * First pass on engine wash effect.  Rotation (control input), damage,
23  * shake.  
24  * 
25  * 3     3/19/99 9:51a Dave
26  * Checkin to repair massive source safe crash. Also added support for
27  * pof-style nebulae, and some new weapons code.
28  * 
29  * 2     10/07/98 10:53a Dave
30  * Initial checkin.
31  * 
32  * 1     10/07/98 10:50a Dave
33  * 
34  * 49    6/30/98 2:23p Dave
35  * Revised object update system. Removed updates for all weapons. Put
36  * button info back into control info packet.
37  * 
38  * 48    3/12/98 5:21p Andsager
39  * Optimize physics for lasers and dumbfire missiles
40  * 
41  * 47    2/03/98 6:01p Andsager
42  * Fix excessive rotvel in debris_create.  Check using physics function
43  * check_rotvel_limit.
44  * 
45  * 46    12/29/97 5:10p Allender
46  * fixed problems with speed not being reported properly in multiplayer
47  * games.  Made read_flying_controls take frametime as a parameter.  More
48  * ship/weapon select stuff
49  * 
50  * 45    12/02/97 11:17p Andsager
51  * Added reduced_damp_decay timestamp.
52  * 
53  * 44    11/17/97 5:15p Andsager
54  * 
55  * 43    9/09/97 10:14p Andsager
56  * 
57  * 42    9/04/97 5:09p Andsager
58  * implement physics using moment of inertia and mass (from BSPgen).
59  * Added to phys_info struct.  Updated ship_info, polymodel structs.
60  * Updated weapon ($Mass and $Force) and ship ($Mass -> $Density) tables
61  * 
62  * 41    8/29/97 10:13a Allender
63  * work on server/client prediction code -- doesn't work too well.  Made
64  * all clients simulate their own orientation with the server giving
65  * corrections every so often.
66  * 
67  * 40    8/19/97 9:56a John
68  * new thruster effect fairly functional
69  * 
70  * 39    8/11/97 9:50a Allender
71  * fixed afterburner snafu
72  * 
73  * 38    8/08/97 9:59a Allender
74  * added afterburner code into multiplayer.  Required adding a new physics
75  * info flag to indicate afterburners ready to fire. (needed for
76  * multiplayer).  Removed some now unused variables in afterburner.cpp
77  * 
78  * 37    7/31/97 12:44p Andsager
79  * 
80  * 36    7/27/97 5:14p Lawrance
81  * add afterburners to the player control info
82  * 
83  * 35    7/25/97 9:07a Andsager
84  * modified apply_whack
85  * 
86  * 34    7/23/97 5:10p Andsager
87  * Enhanced shockwave effect with shake based on blast force.  
88  * 
89  * 33    7/22/97 2:40p Andsager
90  * shockwaves now cause proper rotation of ships
91  * 
92  * 32    7/21/97 4:12p Mike
93  * Two ships move as one while docked, including physics whacks.  Spin of
94  * objects when killed based on speed.
95  * 
96  * 31    7/16/97 11:53a Andsager
97  * 
98  * 30    7/15/97 12:03p Andsager
99  * New physics stuff
100  * 
101  * 29    7/11/97 11:54a John
102  * added rotated 3d bitmaps.
103  * 
104  * 28    6/26/97 12:37p Allender
105  * added debug laser back in
106  * 
107  * 27    5/08/97 11:42a Allender
108  * re-ordered game loop (again).  Player weapons now created in simulation
109  * loop of code, not immediately.
110  * 
111  * 26    4/17/97 10:02a Lawrance
112  * allow ship shaking for ABURN_DECAY_TIME after afterburners cut out
113  * 
114  * 25    4/16/97 10:48p Mike
115  * Afterburner shake.
116  * Made afterburner engagement a bit in physics flags, removed from ship
117  * flags, removed a parameter to physics_read_flying_controls().
118  * 
119  * 24    4/10/97 3:20p Mike
120  * Change hull damage to be like shields.
121  * 
122  * 23    3/04/97 3:10p Mike
123  * Intermediate checkin: Had to resolve some build errors.  Working on two
124  * docked ships moving as one.
125  *
126  * $NoKeywords: $
127  */
128
129 #ifndef _PHYSICS_H
130 #define _PHYSICS_H
131
132 #include "vecmat.h"
133
134
135 #define PF_ACCELERATES                  (1 << 1)
136 #define PF_USE_VEL                              (1 << 2)                //      Use velocity present in physics_info struct, don't call physics_sim_vel.
137 #define PF_AFTERBURNER_ON               (1 << 3)                //      Afterburner currently engaged.
138 #define PF_SLIDE_ENABLED                (1 << 4)                // Allow descent style sliding
139 #define PF_REDUCED_DAMP         (1 << 5)                // Allows reduced damping on z (for death, shockwave) (CAN be reset in physics)
140 #define PF_IN_SHOCKWAVE         (1 << 6)                // Indicates whether object has recently been hit by shockwave (used to enable shake)
141 #define PF_DEAD_DAMP                    (1 << 7)                // Makes forward damping same as sideways (NOT reset in physics)
142 #define PF_AFTERBURNER_WAIT     (1 << 8)                // true when afterburner cannot be used.  replaces variable used in afterburner code
143 #define PF_CONST_VEL                    (1 << 9)                // Use velocity in phys_info struct.  Optimize weapons in phys_sim 
144 #define PF_WARP_IN                              (1 << 10)       //      Use when ship is warping in
145 #define PF_SPECIAL_WARP_IN      (1 << 11)       //      Use when ship is warping in and we want to slow the ship faster than normal game physics
146 #define PF_WARP_OUT                             (1 << 12)       //      Use when ship is warping out
147 #define PF_SPECIAL_WARP_OUT     (1 << 13)       //      Use when ship is warping out and we want to slow the ship faster than normal game physics
148
149 //information for physics sim for an object
150 typedef struct physics_info {
151         uint            flags;                  //misc physics flags
152
153         float           mass;                           //the mass of this object
154
155         matrix  I_body_inv;             // inverse moment of inertia tensor (used to calculate rotational effects)
156
157         float           rotdamp;                        //rotational velocity damping
158         float           side_slip_time_const;   // time const for achieving desired velocity in the local sideways direction
159                                                                                                 //   value should be zero for no sideslip and increase depending on desired slip
160
161         vector  max_vel;                        //maximum foward velocity in x,y,z
162         vector  afterburner_max_vel;    // maximum foward velocity in x,y,z while afterburner engaged
163         vector  max_rotvel;             //maximum p,b,h rotational velocity
164         float           max_rear_vel;   //maximum velocity in the backwards Z direction
165
166         // Acceleration rates.  Only used if flag PF_ACCELERATES is set
167         // starting from rest   time to reach .50  v_max        0.69 time const
168         //                                                              time to reach .75  v_max        1.39 time const
169         //
170         float           forward_accel_time_const;       // forward acceleration time const
171         float           afterburner_forward_accel_time_const;   // forward acceleration time const while afterburner engaged
172         float           forward_decel_time_const;       // forward deceleration time const
173         float           slide_accel_time_const;         // slide acceleration time const
174         float           slide_decel_time_const;         // slide deceleration time const
175         float           shockwave_shake_amp;                    // amplitude of shockwave shake at onset
176
177         // These get changed by the control code.  The physics uses these
178         // as input values when doing physics.
179         vector  prev_ramp_vel;                          // follows the user's desired velocity
180         vector  desired_vel;                            // in world coord
181         vector  desired_rotvel;                 // in local coord
182         float           forward_thrust;                 // How much the forward thruster is applied.  0-1.
183                 
184         // Data that changes each frame.  Physics fills these in each frame.
185         vector  vel;                                            // The current velocity vector of this object
186         vector  rotvel;                                 // The current rotational velecity (angles)
187         float           speed;                                  // Yes, this can be derived from velocity, but that's expensive!
188         float           fspeed;                                 //      Speed in the forward direction.
189         float           heading;
190         vector  prev_fvec;                              //      Used in AI for momentum.
191         matrix  last_rotmat;                    //      Used for moving two objects together and for editor.
192
193         int             afterburner_decay;      // timestamp used to control how long ship shakes after afterburner released
194         int             shockwave_decay;                // timestamp used to control how long ship affected after hit by shockwave
195         int             reduced_damp_decay;     // timestamp used to control how long ship ship has reduced damp physics        
196 } physics_info;
197
198 // All of these are numbers from -1.0 to 1.0 indicating
199 // what percent of full velocity you want to go.
200 typedef struct control_info {
201         float   pitch;                                          // -1.0 to 1.0                                  
202         float   vertical;
203         float   heading;
204         float   sideways;
205         float   bank;
206         float   forward;
207         float forward_cruise_percent;           // percentage used for forward cruising 
208                                                                                 // This is a special case from -100 to 100
209
210         // below is information that are used by the player controls for firing information.
211         int     fire_primary_count;
212         int     fire_secondary_count;
213         int     fire_countermeasure_count;
214         int     fire_debug_count;                                       // should this be around an NDEBUG #if/#endif?
215         
216         // afterburner control information
217         int     afterburner_start;
218         int     afterburner_stop;
219
220 } control_info;
221
222 extern int physics_paused;                              //      Set means don't do physics, except for player.
223
224 // To use the "Descent-ship" physics:
225 //   controls_read_all(&ci, FrameSecs );
226 //   physics_read_flying_controls( &ViewerOrient, &ViewerPhysics, FrameSecs, &ci );
227 //   physics_sim(&ViewerPos, &ViewerOrient, &ViewerPhysics, FrameSecs );                
228 extern void physics_init( physics_info * pi );
229 extern void physics_read_flying_controls( matrix * orient, physics_info * pi, control_info * ci, float sim_time, vector *wash_rot=NULL);
230 extern void physics_sim(vector *position, matrix * orient, physics_info * pi, float sim_time );
231 extern void physics_sim_editor(vector *position, matrix * orient, physics_info * pi, float sim_time);
232
233 extern void physics_sim_vel(vector * position, physics_info * pi, float sim_time, matrix * orient);
234 extern void physics_sim_rot(matrix * orient, physics_info * pi, float sim_time );
235 extern void physics_apply_whack(vector *force, vector *pos, physics_info *pi, matrix *orient, float mass);
236 extern void physics_apply_shock(vector *direction_vec, float pressure, physics_info *pi, matrix *orient, vector *min, vector *max, float radius);
237 extern void physics_collide_whack(vector *impulse, vector *delta_rotvel, physics_info *pi, matrix *orient);
238 int check_rotvel_limit( physics_info *pi );
239
240
241
242 // functions which use physics calcs to predict position and velocity
243 void physics_predict_pos(physics_info *pi, float delta_time, vector *predicted_pos);
244 void physics_predict_vel(physics_info *pi, float delta_time, vector *predicted_vel);
245 void physics_predict_pos_and_vel(physics_info *pi, float delta_time, vector *predicted_vel, vector *predicted_pos);
246
247 // If physics_set_viewer is called with the viewer's physics_info, then
248 // this variable tracks the viewer's bank.  This is used for g3_draw_rotated_bitmap.
249 extern float Physics_viewer_bank;
250
251 // If you would like Physics_viewer_bank to be tracked (Which is needed
252 // for rotating 3d bitmaps) call this and pass it a pointer to the
253 // viewer's physics info.
254 #define PHYSICS_VIEWER_FRONT                            0
255 #define PHYSICS_VIEWER_LEFT                             1
256 #define PHYSICS_VIEWER_RIGHT                            2
257 #define PHYSICS_VIEWER_REAR                             3
258 #define PHYSICS_VIEWER_UP                                       4
259 void physics_set_viewer( physics_info * p, int dir );
260
261 /*
262 #ifdef __cplusplus
263 }
264 #endif
265 */
266
267 #endif  // PHYSICS_H
268