1 /* $Id: slew.c,v 1.4 2003-10-10 09:36:35 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Basic slew system for moving around the mine
20 * Revision 1.1 1995/05/16 15:30:57 allender
23 * Revision 2.0 1995/02/27 11:29:32 john
24 * New version 2.0, which has no anonymous unions, builds with
25 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
27 * Revision 1.34 1995/02/22 14:23:28 allender
28 * remove anonymous unions from object structure
30 * Revision 1.33 1995/02/22 13:24:26 john
31 * Removed the vecmat anonymous unions.
33 * Revision 1.32 1994/09/10 15:46:42 john
34 * First version of new keyboard configuration.
36 * Revision 1.31 1994/08/31 18:29:58 matt
37 * Made slew work with new key system
39 * Revision 1.30 1994/08/31 14:10:48 john
40 * Made slew go faster.
42 * Revision 1.29 1994/08/29 19:16:38 matt
43 * Made slew object not have physics movement type, so slew objects don't
46 * Revision 1.28 1994/08/24 18:59:59 john
47 * Changed key_down_time to return fixed seconds instead of
50 * Revision 1.27 1994/07/01 11:33:05 john
51 * Fixed bug with looking for stick even if one not present.
53 * Revision 1.26 1994/05/20 11:56:33 matt
54 * Cleaned up find_vector_intersection() interface
55 * Killed check_point_in_seg(), check_player_seg(), check_object_seg()
57 * Revision 1.25 1994/05/19 12:08:41 matt
58 * Use new vecmat macros and globals
60 * Revision 1.24 1994/05/14 17:16:18 matt
61 * Got rid of externs in source (non-header) files
63 * Revision 1.23 1994/05/03 12:26:38 matt
64 * Removed use of physics_info var rotvel, which wasn't used for rotational
67 * Revision 1.22 1994/02/17 11:32:34 matt
68 * Changes in object system
70 * Revision 1.21 1994/01/18 14:03:53 john
71 * made joy_get_pos use the new ints instead of
74 * Revision 1.20 1994/01/10 17:11:35 mike
75 * Add prototype for check_object_seg
77 * Revision 1.19 1994/01/05 10:53:38 john
78 * New object code by John.
80 * Revision 1.18 1993/12/22 15:32:50 john
81 * took out previos code that attempted to make
82 * modifiers cancel keydowntime.
84 * Revision 1.17 1993/12/22 11:41:56 john
85 * Made so that keydowntime recognizes editor special case!
87 * Revision 1.16 1993/12/14 18:13:52 matt
88 * Made slew work in editor even when game isn't in slew mode
90 * Revision 1.15 1993/12/07 23:53:39 matt
91 * Made slew work in editor even when game isn't in slew mode
93 * Revision 1.14 1993/12/05 22:47:49 matt
94 * Reworked include files in an attempt to cut down on build times
96 * Revision 1.13 1993/12/01 11:44:14 matt
97 * Chagned Frfract to FrameTime
99 * Revision 1.12 1993/11/08 16:21:42 john
100 * made stop_slew or whatever return an int
102 * Revision 1.11 1993/11/01 13:59:49 john
103 * more slew experiments.
113 static char rcsid[] = "$Id: slew.c,v 1.4 2003-10-10 09:36:35 btb Exp $";
130 //variables for slew system
132 object *slew_obj=NULL; //what object is slewing, or NULL if none
135 #define ROT_SPEED 8 //rate of rotation while key held down
136 #define VEL_SPEED (2*55) //rate of acceleration while key held down
138 short old_joy_x,old_joy_y; //position last time around
140 // Function Prototypes
144 // -------------------------------------------------------------------
145 //say start slewing with this object
146 void slew_init(object *obj)
150 slew_obj->control_type = CT_SLEW;
151 slew_obj->movement_type = MT_NONE;
153 slew_stop(); //make sure not moving
159 if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
161 vm_vec_zero(&slew_obj->mtype.phys_info.velocity);
165 void slew_reset_orient()
167 if (!slew_obj || slew_obj->control_type!=CT_SLEW) return;
169 slew_obj->orient.rvec.x = slew_obj->orient.uvec.y = slew_obj->orient.fvec.z = f1_0;
171 slew_obj->orient.rvec.y = slew_obj->orient.rvec.z = slew_obj->orient.uvec.x =
172 slew_obj->orient.uvec.z = slew_obj->orient.fvec.x = slew_obj->orient.fvec.y = 0;
176 int do_slew_movement(object *obj, int check_keys, int check_joy )
179 vms_vector svel, movement; //scaled velocity (per this frame)
180 vms_matrix rotmat,new_pm;
181 int joy_x,joy_y,btns;
182 int joyx_moved,joyy_moved;
185 if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
188 if (Function_mode == FMODE_EDITOR) {
189 if (FindArg("-jasen"))
190 obj->mtype.phys_info.velocity.x += VEL_SPEED * (key_down_time(KEY_PAD3) - key_down_time(KEY_PAD1));
192 obj->mtype.phys_info.velocity.x += VEL_SPEED * (key_down_time(KEY_PAD9) - key_down_time(KEY_PAD7));
193 obj->mtype.phys_info.velocity.y += VEL_SPEED * (key_down_time(KEY_PADMINUS) - key_down_time(KEY_PADPLUS));
194 obj->mtype.phys_info.velocity.z += VEL_SPEED * (key_down_time(KEY_PAD8) - key_down_time(KEY_PAD2));
196 rotang.p = (key_down_time(KEY_LBRACKET) - key_down_time(KEY_RBRACKET))/ROT_SPEED ;
197 if (FindArg("-jasen"))
198 rotang.b = (key_down_time(KEY_PAD7) - key_down_time(KEY_PAD9))/ROT_SPEED;
200 rotang.b = (key_down_time(KEY_PAD1) - key_down_time(KEY_PAD3))/ROT_SPEED;
201 rotang.h = (key_down_time(KEY_PAD6) - key_down_time(KEY_PAD4))/ROT_SPEED;
204 obj->mtype.phys_info.velocity.x += VEL_SPEED * Controls.sideways_thrust_time;
205 obj->mtype.phys_info.velocity.y += VEL_SPEED * Controls.vertical_thrust_time;
206 obj->mtype.phys_info.velocity.z += VEL_SPEED * Controls.forward_thrust_time;
208 rotang.p = Controls.pitch_time/ROT_SPEED ;
209 rotang.b = Controls.bank_time/ROT_SPEED;
210 rotang.h = Controls.heading_time/ROT_SPEED;
214 rotang.p = rotang.b = rotang.h = 0;
216 //check for joystick movement
218 if (check_joy && joy_present && (Function_mode == FMODE_EDITOR) ) {
219 joy_get_pos(&joy_x,&joy_y);
222 joyx_moved = (abs(joy_x - old_joy_x)>JOY_NULL);
223 joyy_moved = (abs(joy_y - old_joy_y)>JOY_NULL);
225 if (abs(joy_x) < JOY_NULL) joy_x = 0;
226 if (abs(joy_y) < JOY_NULL) joy_y = 0;
229 if (!rotang.p) rotang.p = fixmul(-joy_y * 512,FrameTime); else;
231 if (joyy_moved) obj->mtype.phys_info.velocity.z = -joy_y * 8192;
233 if (!rotang.h) rotang.h = fixmul(joy_x * 512,FrameTime);
235 if (joyx_moved) old_joy_x = joy_x;
236 if (joyy_moved) old_joy_y = joy_y;
239 moved = rotang.p | rotang.b | rotang.h;
241 vm_angles_2_matrix(&rotmat,&rotang);
242 vm_matrix_x_matrix(&new_pm,&obj->orient,&rotmat);
243 obj->orient = new_pm;
244 vm_transpose_matrix(&new_pm); //make those columns rows
246 moved |= obj->mtype.phys_info.velocity.x | obj->mtype.phys_info.velocity.y | obj->mtype.phys_info.velocity.z;
248 svel = obj->mtype.phys_info.velocity;
249 vm_vec_scale(&svel,FrameTime); //movement in this frame
250 vm_vec_rotate(&movement,&svel,&new_pm);
252 // obj->last_pos = obj->pos;
253 vm_vec_add2(&obj->pos,&movement);
255 moved |= (movement.x || movement.y || movement.z);
258 update_object_seg(obj); //update segment id
263 //do slew for this frame
264 int slew_frame(int check_keys)
266 return do_slew_movement( slew_obj, !check_keys, 1 );