2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // in_win.c -- windows 95 mouse and joystick code
21 // 02/21/97 JCB Added extended DirectInput code to support external controllers.
26 //#include "dosisms.h"
28 #define DINPUT_BUFFERSIZE 16
29 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
31 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
32 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
35 cvar_t m_filter = {"m_filter","0"};
38 int mouse_oldbuttonstate;
40 int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
42 static qboolean restore_spi;
43 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
45 unsigned int uiWheelMessage;
47 qboolean mouseinitialized;
48 static qboolean mouseparmsvalid, mouseactivatetoggle;
49 //static qboolean mouseshowtoggle = 1;
50 static qboolean dinput_acquired;
52 static unsigned int mstate_di;
54 // joystick defines and variables
55 // where should defines be moved?
56 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
57 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
58 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
68 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
71 DWORD dwAxisFlags[JOY_MAX_AXES] =
73 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
76 DWORD dwAxisMap[JOY_MAX_AXES];
77 DWORD dwControlMap[JOY_MAX_AXES];
78 PDWORD pdwRawValue[JOY_MAX_AXES];
80 // none of these cvars are saved over a session
81 // this means that advanced controller configuration needs to be executed
82 // each time. this avoids any problems with getting back to a default usage
83 // or when changing from one controller to another. this way at least something
85 cvar_t in_joystick = {"joystick","0", true};
86 cvar_t joy_name = {"joyname", "joystick"};
87 cvar_t joy_advanced = {"joyadvanced", "0"};
88 cvar_t joy_advaxisx = {"joyadvaxisx", "0"};
89 cvar_t joy_advaxisy = {"joyadvaxisy", "0"};
90 cvar_t joy_advaxisz = {"joyadvaxisz", "0"};
91 cvar_t joy_advaxisr = {"joyadvaxisr", "0"};
92 cvar_t joy_advaxisu = {"joyadvaxisu", "0"};
93 cvar_t joy_advaxisv = {"joyadvaxisv", "0"};
94 cvar_t joy_forwardthreshold = {"joyforwardthreshold", "0.15"};
95 cvar_t joy_sidethreshold = {"joysidethreshold", "0.15"};
96 cvar_t joy_pitchthreshold = {"joypitchthreshold", "0.15"};
97 cvar_t joy_yawthreshold = {"joyyawthreshold", "0.15"};
98 cvar_t joy_forwardsensitivity = {"joyforwardsensitivity", "-1.0"};
99 cvar_t joy_sidesensitivity = {"joysidesensitivity", "-1.0"};
100 cvar_t joy_pitchsensitivity = {"joypitchsensitivity", "1.0"};
101 cvar_t joy_yawsensitivity = {"joyyawsensitivity", "-1.0"};
102 cvar_t joy_wwhack1 = {"joywwhack1", "0.0"};
103 cvar_t joy_wwhack2 = {"joywwhack2", "0.0"};
105 qboolean joy_avail, joy_advancedinit, joy_haspov;
106 DWORD joy_oldbuttonstate, joy_oldpovstate;
110 DWORD joy_numbuttons;
112 static LPDIRECTINPUT g_pdi;
113 static LPDIRECTINPUTDEVICE g_pMouse;
117 static HINSTANCE hInstDI;
119 static qboolean dinput;
121 typedef struct MYDATA {
122 LONG lX; // X axis goes here
123 LONG lY; // Y axis goes here
124 LONG lZ; // Z axis goes here
125 BYTE bButtonA; // One button goes here
126 BYTE bButtonB; // Another button goes here
127 BYTE bButtonC; // Another button goes here
128 BYTE bButtonD; // Another button goes here
131 static DIOBJECTDATAFORMAT rgodf[] = {
132 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
133 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
134 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
135 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
136 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
137 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
138 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
141 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
143 static DIDATAFORMAT df = {
144 sizeof(DIDATAFORMAT), // this structure
145 sizeof(DIOBJECTDATAFORMAT), // size of object data format
146 DIDF_RELAXIS, // absolute axis coordinates
147 sizeof(MYDATA), // device data size
148 NUM_OBJECTS, // number of objects
149 rgodf, // and here they are
152 // forward-referenced functions
153 void IN_StartupJoystick (void);
154 void Joy_AdvancedUpdate_f (void);
155 void IN_JoyMove (usercmd_t *cmd);
163 void Force_CenterView_f (void)
165 cl.viewangles[PITCH] = 0;
174 void IN_UpdateClipCursor (void)
177 if (mouseinitialized && mouseactive && !dinput)
179 ClipCursor (&window_rect);
189 void IN_ShowMouse (void)
191 // if (!mouseshowtoggle)
194 // mouseshowtoggle = 1;
204 void IN_HideMouse (void)
206 // if (mouseshowtoggle)
209 // mouseshowtoggle = 0;
219 void IN_ActivateMouse (void)
222 mouseactivatetoggle = true;
224 if (mouseinitialized)
230 if (!dinput_acquired)
232 IDirectInputDevice_Acquire(g_pMouse);
233 dinput_acquired = true;
244 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
246 SetCursorPos (window_center_x, window_center_y);
247 SetCapture (mainwindow);
248 ClipCursor (&window_rect);
262 void IN_DeactivateMouse (void)
265 mouseactivatetoggle = false;
267 if (mouseinitialized)
275 IDirectInputDevice_Unacquire(g_pMouse);
276 dinput_acquired = false;
283 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
299 qboolean IN_InitDInput (void)
302 DIPROPDWORD dipdw = {
304 sizeof(DIPROPDWORD), // diph.dwSize
305 sizeof(DIPROPHEADER), // diph.dwHeaderSize
307 DIPH_DEVICE, // diph.dwHow
309 DINPUT_BUFFERSIZE, // dwData
314 hInstDI = LoadLibrary("dinput.dll");
318 Con_SafePrintf ("Couldn't load dinput.dll\n");
323 if (!pDirectInputCreate)
325 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
327 if (!pDirectInputCreate)
329 Con_SafePrintf ("Couldn't get DI proc addr\n");
334 // register with DirectInput and get an IDirectInput to play with.
335 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
342 // obtain an interface to the system mouse device.
343 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
347 Con_SafePrintf ("Couldn't open DI mouse device\n");
351 // set the data format to "mouse format".
352 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
356 Con_SafePrintf ("Couldn't set DI mouse format\n");
360 // set the cooperativity level.
361 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
362 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
366 Con_SafePrintf ("Couldn't set DI coop level\n");
371 // set the buffer size to DINPUT_BUFFERSIZE elements.
372 // the buffer size is a DWORD property associated with the device
373 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
377 Con_SafePrintf ("Couldn't set DI buffersize\n");
390 void IN_StartupMouse (void)
392 if ( COM_CheckParm ("-nomouse") )
395 mouseinitialized = true;
397 if (COM_CheckParm ("-dinput"))
399 dinput = IN_InitDInput ();
403 Con_SafePrintf ("DirectInput initialized\n");
407 Con_SafePrintf ("DirectInput not initialized\n");
413 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
417 if ( COM_CheckParm ("-noforcemspd") )
418 newmouseparms[2] = originalmouseparms[2];
420 if ( COM_CheckParm ("-noforcemaccel") )
422 newmouseparms[0] = originalmouseparms[0];
423 newmouseparms[1] = originalmouseparms[1];
426 if ( COM_CheckParm ("-noforcemparms") )
428 newmouseparms[0] = originalmouseparms[0];
429 newmouseparms[1] = originalmouseparms[1];
430 newmouseparms[2] = originalmouseparms[2];
437 // if a fullscreen video mode was set before the mouse was initialized,
438 // set the mouse state appropriately
439 if (mouseactivatetoggle)
452 Cvar_RegisterVariable (&m_filter);
454 // joystick variables
455 Cvar_RegisterVariable (&in_joystick);
456 Cvar_RegisterVariable (&joy_name);
457 Cvar_RegisterVariable (&joy_advanced);
458 Cvar_RegisterVariable (&joy_advaxisx);
459 Cvar_RegisterVariable (&joy_advaxisy);
460 Cvar_RegisterVariable (&joy_advaxisz);
461 Cvar_RegisterVariable (&joy_advaxisr);
462 Cvar_RegisterVariable (&joy_advaxisu);
463 Cvar_RegisterVariable (&joy_advaxisv);
464 Cvar_RegisterVariable (&joy_forwardthreshold);
465 Cvar_RegisterVariable (&joy_sidethreshold);
466 Cvar_RegisterVariable (&joy_pitchthreshold);
467 Cvar_RegisterVariable (&joy_yawthreshold);
468 Cvar_RegisterVariable (&joy_forwardsensitivity);
469 Cvar_RegisterVariable (&joy_sidesensitivity);
470 Cvar_RegisterVariable (&joy_pitchsensitivity);
471 Cvar_RegisterVariable (&joy_yawsensitivity);
472 Cvar_RegisterVariable (&joy_wwhack1);
473 Cvar_RegisterVariable (&joy_wwhack2);
475 Cmd_AddCommand ("force_centerview", Force_CenterView_f);
476 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
478 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
481 IN_StartupJoystick ();
489 void IN_Shutdown (void)
491 // usingmouse = false;
492 IN_DeactivateMouse ();
497 IDirectInputDevice_Release(g_pMouse);
503 IDirectInput_Release(g_pdi);
514 void IN_MouseEvent (int mstate)
518 if (mouseactive && !dinput)
520 // perform button actions
521 for (i=0 ; i<mouse_buttons ; i++)
523 if ( (mstate & (1<<i)) &&
524 !(mouse_oldbuttonstate & (1<<i)) )
526 Key_Event (K_MOUSE1 + i, true);
529 if ( !(mstate & (1<<i)) &&
530 (mouse_oldbuttonstate & (1<<i)) )
532 Key_Event (K_MOUSE1 + i, false);
536 mouse_oldbuttonstate = mstate;
546 void IN_MouseMove (usercmd_t *cmd)
548 int i, mx, my, mouselook = (in_mlook.state & 1) || freelook.value;
549 DIDEVICEOBJECTDATA od;
565 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
566 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
568 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
570 dinput_acquired = true;
571 IDirectInputDevice_Acquire(g_pMouse);
575 /* Unable to read data or no data available */
576 if (FAILED(hr) || dwElements == 0)
581 /* Look at the element to see what happened */
594 if (od.dwData & 0x80)
601 if (od.dwData & 0x80)
604 mstate_di &= ~(1<<1);
608 if (od.dwData & 0x80)
611 mstate_di &= ~(1<<2);
616 // perform button actions
617 for (i=0 ; i<mouse_buttons ; i++)
619 if ( (mstate_di & (1<<i)) &&
620 !(mouse_oldbuttonstate & (1<<i)) )
622 Key_Event (K_MOUSE1 + i, true);
625 if ( !(mstate_di & (1<<i)) &&
626 (mouse_oldbuttonstate & (1<<i)) )
628 Key_Event (K_MOUSE1 + i, false);
632 mouse_oldbuttonstate = mstate_di;
636 GetCursorPos (¤t_pos);
637 mx = current_pos.x - window_center_x + mx_accum;
638 my = current_pos.y - window_center_y + my_accum;
644 // Con_DPrintf("mx=%d, my=%d\n", mx, my);
648 mouse_x = (mx + old_mouse_x) * 0.5;
649 mouse_y = (my + old_mouse_y) * 0.5;
660 mouse_x *= sensitivity.value;
661 mouse_y *= sensitivity.value;
663 // add mouse X/Y movement to cmd
664 if ( (in_strafe.state & 1) || (lookstrafe.value && mouselook))
665 cmd->sidemove += m_side.value * mouse_x;
667 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
672 // LordHavoc: changed limits on pitch from -70 to 80, to -90 to 90
673 if (mouselook && !(in_strafe.state & 1))
675 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
676 if (cl.viewangles[PITCH] > 90)
677 cl.viewangles[PITCH] = 90;
678 if (cl.viewangles[PITCH] < -90)
679 cl.viewangles[PITCH] = -90;
683 if ((in_strafe.state & 1) && noclip_anglehack)
684 cmd->upmove -= m_forward.value * mouse_y;
686 cmd->forwardmove -= m_forward.value * mouse_y;
689 // if the mouse has moved, force it to the center, so there's room to move
692 SetCursorPos (window_center_x, window_center_y);
702 void IN_Move (usercmd_t *cmd)
705 if (ActiveApp && !Minimized)
718 void IN_Accumulate (void)
724 GetCursorPos (¤t_pos);
726 mx_accum += current_pos.x - window_center_x;
727 my_accum += current_pos.y - window_center_y;
729 // force the mouse to the center, so there's room to move
730 SetCursorPos (window_center_x, window_center_y);
741 void IN_ClearStates (void)
748 mouse_oldbuttonstate = 0;
758 void IN_StartupJoystick (void)
764 // assume no joystick
767 // abort startup if user requests no joystick
768 if ( COM_CheckParm ("-nojoy") )
771 // verify joystick driver is present
772 if ((numdevs = joyGetNumDevs ()) == 0)
774 Con_Printf ("\njoystick not found -- driver not present\n\n");
778 // cycle through the joystick ids for the first valid one
779 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
781 memset (&ji, 0, sizeof(ji));
782 ji.dwSize = sizeof(ji);
783 ji.dwFlags = JOY_RETURNCENTERED;
785 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
789 // abort startup if we didn't find a valid joystick
790 if (mmr != JOYERR_NOERROR)
792 Con_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
796 // get the capabilities of the selected joystick
797 // abort startup if command fails
798 memset (&jc, 0, sizeof(jc));
799 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
801 Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
805 // save the joystick's number of buttons and POV status
806 joy_numbuttons = jc.wNumButtons;
807 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
809 // old button and POV states default to no buttons pressed
810 joy_oldbuttonstate = joy_oldpovstate = 0;
812 // mark the joystick as available and advanced initialization not completed
813 // this is needed as cvars are not available during initialization
816 joy_advancedinit = false;
818 Con_Printf ("\njoystick detected\n\n");
827 PDWORD RawValuePointer (int axis)
844 return NULL; // LordHavoc: hush compiler warning
853 void Joy_AdvancedUpdate_f (void)
856 // called once by IN_ReadJoystick and by user whenever an update is needed
857 // cvars are now available
861 // initialize all the maps
862 for (i = 0; i < JOY_MAX_AXES; i++)
864 dwAxisMap[i] = AxisNada;
865 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
866 pdwRawValue[i] = RawValuePointer(i);
869 if( joy_advanced.value == 0.0)
871 // default joystick initialization
872 // 2 axes only with joystick control
873 dwAxisMap[JOY_AXIS_X] = AxisTurn;
874 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
875 dwAxisMap[JOY_AXIS_Y] = AxisForward;
876 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
880 if (strcmp (joy_name.string, "joystick") != 0)
882 // notify user of advanced controller
883 Con_Printf ("\n%s configured\n\n", joy_name.string);
886 // advanced initialization here
887 // data supplied by user via joy_axisn cvars
888 dwTemp = (DWORD) joy_advaxisx.value;
889 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
890 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
891 dwTemp = (DWORD) joy_advaxisy.value;
892 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
893 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
894 dwTemp = (DWORD) joy_advaxisz.value;
895 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
896 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
897 dwTemp = (DWORD) joy_advaxisr.value;
898 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
899 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
900 dwTemp = (DWORD) joy_advaxisu.value;
901 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
902 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
903 dwTemp = (DWORD) joy_advaxisv.value;
904 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
905 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
908 // compute the axes to collect from DirectInput
909 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
910 for (i = 0; i < JOY_MAX_AXES; i++)
912 if (dwAxisMap[i] != AxisNada)
914 joy_flags |= dwAxisFlags[i];
925 void IN_Commands (void)
928 DWORD buttonstate, povstate;
936 // loop through the joystick buttons
937 // key a joystick event or auxillary event for higher number buttons for each state change
938 buttonstate = ji.dwButtons;
939 for (i=0 ; i < (int) joy_numbuttons ; i++)
941 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
943 key_index = (i < 4) ? K_JOY1 : K_AUX1;
944 Key_Event (key_index + i, true);
947 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
949 key_index = (i < 4) ? K_JOY1 : K_AUX1;
950 Key_Event (key_index + i, false);
953 joy_oldbuttonstate = buttonstate;
957 // convert POV information into 4 bits of state information
958 // this avoids any potential problems related to moving from one
959 // direction to another without going through the center position
961 if(ji.dwPOV != JOY_POVCENTERED)
963 if (ji.dwPOV == JOY_POVFORWARD)
965 if (ji.dwPOV == JOY_POVRIGHT)
967 if (ji.dwPOV == JOY_POVBACKWARD)
969 if (ji.dwPOV == JOY_POVLEFT)
972 // determine which bits have changed and key an auxillary event for each change
973 for (i=0 ; i < 4 ; i++)
975 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
977 Key_Event (K_AUX29 + i, true);
980 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
982 Key_Event (K_AUX29 + i, false);
985 joy_oldpovstate = povstate;
995 qboolean IN_ReadJoystick (void)
998 memset (&ji, 0, sizeof(ji));
999 ji.dwSize = sizeof(ji);
1000 ji.dwFlags = joy_flags;
1002 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1004 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1005 // rather than having 32768 be the zero point, they have the zero point at 32668
1006 // go figure -- anyway, now we get the full resolution out of the device
1007 if (joy_wwhack1.value != 0.0)
1015 // read error occurred
1016 // turning off the joystick seems too harsh for 1 read error,\
1017 // but what should be done?
1018 // Con_Printf ("IN_ReadJoystick: no response\n");
1019 // joy_avail = false;
1030 void IN_JoyMove (usercmd_t *cmd)
1032 float speed, aspeed;
1033 float fAxisValue, fTemp;
1034 int i, mouselook = (in_mlook.state & 1) || freelook.value;
1036 // complete initialization if first time in
1037 // this is needed as cvars are not available at initialization time
1038 if( joy_advancedinit != true )
1040 Joy_AdvancedUpdate_f();
1041 joy_advancedinit = true;
1044 // verify joystick is available and that the user wants to use it
1045 if (!joy_avail || !in_joystick.value)
1050 // collect the joystick data, if possible
1051 if (IN_ReadJoystick () != true)
1056 if (in_speed.state & 1)
1057 speed = cl_movespeedkey.value;
1060 aspeed = speed * host_realframetime;
1062 // loop through the axes
1063 for (i = 0; i < JOY_MAX_AXES; i++)
1065 // get the floating point zero-centered, potentially-inverted data for the current axis
1066 fAxisValue = (float) *pdwRawValue[i];
1067 // move centerpoint to zero
1068 fAxisValue -= 32768.0;
1070 if (joy_wwhack2.value != 0.0)
1072 if (dwAxisMap[i] == AxisTurn)
1074 // this is a special formula for the Logitech WingMan Warrior
1075 // y=ax^b; where a = 300 and b = 1.3
1076 // also x values are in increments of 800 (so this is factored out)
1077 // then bounds check result to level out excessively high spin rates
1078 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1079 if (fTemp > 14000.0)
1081 // restore direction information
1082 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1086 // convert range from -32768..32767 to -1..1
1087 fAxisValue /= 32768.0;
1089 switch (dwAxisMap[i])
1092 if ((joy_advanced.value == 0.0) && mouselook)
1094 // user wants forward control to become look control
1095 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1097 // if mouse invert is on, invert the joystick pitch value
1098 // only absolute control support here (joy_advanced is false)
1099 if (m_pitch.value < 0.0)
1101 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1105 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1111 // no pitch movement
1112 // disable pitch return-to-center unless requested by user
1113 // *** this code can be removed when the lookspring bug is fixed
1114 // *** the bug always has the lookspring feature on
1115 if(lookspring.value == 0.0)
1121 // user wants forward control to be forward control
1122 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1124 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1130 if (fabs(fAxisValue) > joy_sidethreshold.value)
1132 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1137 if ((in_strafe.state & 1) || (lookstrafe.value && mouselook))
1139 // user wants turn control to become side control
1140 if (fabs(fAxisValue) > joy_sidethreshold.value)
1142 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1147 // user wants turn control to be turn control
1148 if (fabs(fAxisValue) > joy_yawthreshold.value)
1150 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1152 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1156 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1166 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1168 // pitch movement detected and pitch movement desired by user
1169 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1171 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1175 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1181 // no pitch movement
1182 // disable pitch return-to-center unless requested by user
1183 // *** this code can be removed when the lookspring bug is fixed
1184 // *** the bug always has the lookspring feature on
1185 if(lookspring.value == 0.0)
1196 // bounds check pitch
1197 if (cl.viewangles[PITCH] > 80.0)
1198 cl.viewangles[PITCH] = 80.0;
1199 if (cl.viewangles[PITCH] < -70.0)
1200 cl.viewangles[PITCH] = -70.0;