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