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.
25 //#include "dosisms.h"
29 #define DINPUT_BUFFERSIZE 16
30 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
32 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
33 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
36 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
39 int mouse_oldbuttonstate;
41 int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
43 static qboolean restore_spi;
44 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
46 unsigned int uiWheelMessage;
48 qboolean mouseinitialized;
49 static qboolean mouseparmsvalid, mouseactivatetoggle;
50 static qboolean mouseshowtoggle = 1;
51 static qboolean dinput_acquired;
53 static unsigned int mstate_di;
55 // joystick defines and variables
56 // where should defines be moved?
57 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
58 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
59 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
69 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
72 DWORD dwAxisFlags[JOY_MAX_AXES] =
74 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
77 DWORD dwAxisMap[JOY_MAX_AXES];
78 DWORD dwControlMap[JOY_MAX_AXES];
79 PDWORD pdwRawValue[JOY_MAX_AXES];
81 // none of these cvars are saved over a session
82 // this means that advanced controller configuration needs to be executed
83 // each time. this avoids any problems with getting back to a default usage
84 // or when changing from one controller to another. this way at least something
86 cvar_t in_joystick = {"joystick","0", true};
87 cvar_t joy_name = {"joyname", "joystick"};
88 cvar_t joy_advanced = {"joyadvanced", "0"};
89 cvar_t joy_advaxisx = {"joyadvaxisx", "0"};
90 cvar_t joy_advaxisy = {"joyadvaxisy", "0"};
91 cvar_t joy_advaxisz = {"joyadvaxisz", "0"};
92 cvar_t joy_advaxisr = {"joyadvaxisr", "0"};
93 cvar_t joy_advaxisu = {"joyadvaxisu", "0"};
94 cvar_t joy_advaxisv = {"joyadvaxisv", "0"};
95 cvar_t joy_forwardthreshold = {"joyforwardthreshold", "0.15"};
96 cvar_t joy_sidethreshold = {"joysidethreshold", "0.15"};
97 cvar_t joy_pitchthreshold = {"joypitchthreshold", "0.15"};
98 cvar_t joy_yawthreshold = {"joyyawthreshold", "0.15"};
99 cvar_t joy_forwardsensitivity = {"joyforwardsensitivity", "-1.0"};
100 cvar_t joy_sidesensitivity = {"joysidesensitivity", "-1.0"};
101 cvar_t joy_pitchsensitivity = {"joypitchsensitivity", "1.0"};
102 cvar_t joy_yawsensitivity = {"joyyawsensitivity", "-1.0"};
103 cvar_t joy_wwhack1 = {"joywwhack1", "0.0"};
104 cvar_t joy_wwhack2 = {"joywwhack2", "0.0"};
106 qboolean joy_avail, joy_advancedinit, joy_haspov;
107 DWORD joy_oldbuttonstate, joy_oldpovstate;
111 DWORD joy_numbuttons;
113 static LPDIRECTINPUT g_pdi;
114 static LPDIRECTINPUTDEVICE g_pMouse;
118 static HINSTANCE hInstDI;
120 static qboolean dinput;
122 typedef struct MYDATA {
123 LONG lX; // X axis goes here
124 LONG lY; // Y axis goes here
125 LONG lZ; // Z axis goes here
126 BYTE bButtonA; // One button goes here
127 BYTE bButtonB; // Another button goes here
128 BYTE bButtonC; // Another button goes here
129 BYTE bButtonD; // Another button goes here
132 static DIOBJECTDATAFORMAT rgodf[] = {
133 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
134 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
135 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
136 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
137 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
138 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
139 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
142 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
144 static DIDATAFORMAT df = {
145 sizeof(DIDATAFORMAT), // this structure
146 sizeof(DIOBJECTDATAFORMAT), // size of object data format
147 DIDF_RELAXIS, // absolute axis coordinates
148 sizeof(MYDATA), // device data size
149 NUM_OBJECTS, // number of objects
150 rgodf, // and here they are
153 // forward-referenced functions
154 void IN_StartupJoystick (void);
155 void Joy_AdvancedUpdate_f (void);
156 void IN_JoyMove (usercmd_t *cmd);
164 void IN_UpdateClipCursor (void)
167 if (mouseinitialized && mouseactive && !dinput)
169 ClipCursor (&window_rect);
179 void IN_ShowMouse (void)
181 if (!mouseshowtoggle)
194 void IN_HideMouse (void)
209 void IN_ActivateMouse (void)
212 mouseactivatetoggle = true;
214 if (mouseinitialized)
220 if (!dinput_acquired)
222 IDirectInputDevice_Acquire(g_pMouse);
223 dinput_acquired = true;
234 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
236 SetCursorPos (window_center_x, window_center_y);
237 SetCapture (mainwindow);
238 ClipCursor (&window_rect);
252 void IN_DeactivateMouse (void)
255 mouseactivatetoggle = false;
257 if (mouseinitialized)
265 IDirectInputDevice_Unacquire(g_pMouse);
266 dinput_acquired = false;
273 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
289 qboolean IN_InitDInput (void)
292 DIPROPDWORD dipdw = {
294 sizeof(DIPROPDWORD), // diph.dwSize
295 sizeof(DIPROPHEADER), // diph.dwHeaderSize
297 DIPH_DEVICE, // diph.dwHow
299 DINPUT_BUFFERSIZE, // dwData
304 hInstDI = LoadLibrary("dinput.dll");
308 Con_SafePrintf ("Couldn't load dinput.dll\n");
313 if (!pDirectInputCreate)
315 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
317 if (!pDirectInputCreate)
319 Con_SafePrintf ("Couldn't get DI proc addr\n");
324 // register with DirectInput and get an IDirectInput to play with.
325 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
332 // obtain an interface to the system mouse device.
333 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
337 Con_SafePrintf ("Couldn't open DI mouse device\n");
341 // set the data format to "mouse format".
342 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
346 Con_SafePrintf ("Couldn't set DI mouse format\n");
350 // set the cooperativity level.
351 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
352 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
356 Con_SafePrintf ("Couldn't set DI coop level\n");
361 // set the buffer size to DINPUT_BUFFERSIZE elements.
362 // the buffer size is a DWORD property associated with the device
363 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
367 Con_SafePrintf ("Couldn't set DI buffersize\n");
380 void IN_StartupMouse (void)
382 if ( COM_CheckParm ("-nomouse") )
385 mouseinitialized = true;
387 if (COM_CheckParm ("-dinput"))
389 dinput = IN_InitDInput ();
393 Con_SafePrintf ("DirectInput initialized\n");
397 Con_SafePrintf ("DirectInput not initialized\n");
403 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
407 if ( COM_CheckParm ("-noforcemspd") )
408 newmouseparms[2] = originalmouseparms[2];
410 if ( COM_CheckParm ("-noforcemaccel") )
412 newmouseparms[0] = originalmouseparms[0];
413 newmouseparms[1] = originalmouseparms[1];
416 if ( COM_CheckParm ("-noforcemparms") )
418 newmouseparms[0] = originalmouseparms[0];
419 newmouseparms[1] = originalmouseparms[1];
420 newmouseparms[2] = originalmouseparms[2];
427 // if a fullscreen video mode was set before the mouse was initialized,
428 // set the mouse state appropriately
429 if (mouseactivatetoggle)
442 Cvar_RegisterVariable (&m_filter);
444 // joystick variables
445 Cvar_RegisterVariable (&in_joystick);
446 Cvar_RegisterVariable (&joy_name);
447 Cvar_RegisterVariable (&joy_advanced);
448 Cvar_RegisterVariable (&joy_advaxisx);
449 Cvar_RegisterVariable (&joy_advaxisy);
450 Cvar_RegisterVariable (&joy_advaxisz);
451 Cvar_RegisterVariable (&joy_advaxisr);
452 Cvar_RegisterVariable (&joy_advaxisu);
453 Cvar_RegisterVariable (&joy_advaxisv);
454 Cvar_RegisterVariable (&joy_forwardthreshold);
455 Cvar_RegisterVariable (&joy_sidethreshold);
456 Cvar_RegisterVariable (&joy_pitchthreshold);
457 Cvar_RegisterVariable (&joy_yawthreshold);
458 Cvar_RegisterVariable (&joy_forwardsensitivity);
459 Cvar_RegisterVariable (&joy_sidesensitivity);
460 Cvar_RegisterVariable (&joy_pitchsensitivity);
461 Cvar_RegisterVariable (&joy_yawsensitivity);
462 Cvar_RegisterVariable (&joy_wwhack1);
463 Cvar_RegisterVariable (&joy_wwhack2);
465 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
467 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
470 IN_StartupJoystick ();
478 void IN_Shutdown (void)
480 // usingmouse = false;
481 IN_DeactivateMouse ();
486 IDirectInputDevice_Release(g_pMouse);
492 IDirectInput_Release(g_pdi);
503 void IN_MouseEvent (int mstate)
507 if (mouseactive && !dinput)
509 // perform button actions
510 for (i=0 ; i<mouse_buttons ; i++)
512 if ( (mstate & (1<<i)) &&
513 !(mouse_oldbuttonstate & (1<<i)) )
515 Key_Event (K_MOUSE1 + i, true);
518 if ( !(mstate & (1<<i)) &&
519 (mouse_oldbuttonstate & (1<<i)) )
521 Key_Event (K_MOUSE1 + i, false);
525 mouse_oldbuttonstate = mstate;
535 void IN_MouseMove (usercmd_t *cmd)
537 int i, mx, my, mouselook = (in_mlook.state & 1) || freelook.value;
538 DIDEVICEOBJECTDATA od;
544 GetCursorPos (¤t_pos);
545 ui_updatemouse(current_pos.x - window_x, current_pos.y - window_y);
558 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
559 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
561 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
563 dinput_acquired = true;
564 IDirectInputDevice_Acquire(g_pMouse);
568 /* Unable to read data or no data available */
569 if (FAILED(hr) || dwElements == 0)
574 /* Look at the element to see what happened */
587 if (od.dwData & 0x80)
594 if (od.dwData & 0x80)
597 mstate_di &= ~(1<<1);
601 if (od.dwData & 0x80)
604 mstate_di &= ~(1<<2);
609 // perform button actions
610 for (i=0 ; i<mouse_buttons ; i++)
612 if ( (mstate_di & (1<<i)) &&
613 !(mouse_oldbuttonstate & (1<<i)) )
615 Key_Event (K_MOUSE1 + i, true);
618 if ( !(mstate_di & (1<<i)) &&
619 (mouse_oldbuttonstate & (1<<i)) )
621 Key_Event (K_MOUSE1 + i, false);
625 mouse_oldbuttonstate = mstate_di;
629 GetCursorPos (¤t_pos);
630 mx = current_pos.x - window_center_x + mx_accum;
631 my = current_pos.y - window_center_y + my_accum;
637 // Con_DPrintf("mx=%d, my=%d\n", mx, my);
641 mouse_x = (mx + old_mouse_x) * 0.5;
642 mouse_y = (my + old_mouse_y) * 0.5;
653 mouse_x *= sensitivity.value;
654 mouse_y *= sensitivity.value;
656 // add mouse X/Y movement to cmd
657 if ( (in_strafe.state & 1) || (lookstrafe.value && mouselook))
658 cmd->sidemove += m_side.value * mouse_x;
660 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
665 // LordHavoc: changed limits on pitch from -70 to 80, to -90 to 90
666 if (mouselook && !(in_strafe.state & 1))
668 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
669 if (cl.viewangles[PITCH] > 90)
670 cl.viewangles[PITCH] = 90;
671 if (cl.viewangles[PITCH] < -90)
672 cl.viewangles[PITCH] = -90;
676 if ((in_strafe.state & 1) && noclip_anglehack)
677 cmd->upmove -= m_forward.value * mouse_y;
679 cmd->forwardmove -= m_forward.value * mouse_y;
682 // if the mouse has moved, force it to the center, so there's room to move
685 SetCursorPos (window_center_x, window_center_y);
695 void IN_Move (usercmd_t *cmd)
698 if (ActiveApp && !Minimized)
711 void IN_Accumulate (void)
717 GetCursorPos (¤t_pos);
719 mx_accum += current_pos.x - window_center_x;
720 my_accum += current_pos.y - window_center_y;
722 // force the mouse to the center, so there's room to move
723 SetCursorPos (window_center_x, window_center_y);
734 void IN_ClearStates (void)
741 mouse_oldbuttonstate = 0;
751 void IN_StartupJoystick (void)
757 // assume no joystick
760 // abort startup if user requests no joystick
761 if ( COM_CheckParm ("-nojoy") )
764 // verify joystick driver is present
765 if ((numdevs = joyGetNumDevs ()) == 0)
767 Con_Printf ("\njoystick not found -- driver not present\n\n");
771 // cycle through the joystick ids for the first valid one
772 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
774 memset (&ji, 0, sizeof(ji));
775 ji.dwSize = sizeof(ji);
776 ji.dwFlags = JOY_RETURNCENTERED;
778 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
782 // abort startup if we didn't find a valid joystick
783 if (mmr != JOYERR_NOERROR)
785 Con_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
789 // get the capabilities of the selected joystick
790 // abort startup if command fails
791 memset (&jc, 0, sizeof(jc));
792 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
794 Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
798 // save the joystick's number of buttons and POV status
799 joy_numbuttons = jc.wNumButtons;
800 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
802 // old button and POV states default to no buttons pressed
803 joy_oldbuttonstate = joy_oldpovstate = 0;
805 // mark the joystick as available and advanced initialization not completed
806 // this is needed as cvars are not available during initialization
809 joy_advancedinit = false;
811 Con_Printf ("\njoystick detected\n\n");
820 PDWORD RawValuePointer (int axis)
837 return NULL; // LordHavoc: hush compiler warning
846 void Joy_AdvancedUpdate_f (void)
849 // called once by IN_ReadJoystick and by user whenever an update is needed
850 // cvars are now available
854 // initialize all the maps
855 for (i = 0; i < JOY_MAX_AXES; i++)
857 dwAxisMap[i] = AxisNada;
858 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
859 pdwRawValue[i] = RawValuePointer(i);
862 if( joy_advanced.value == 0.0)
864 // default joystick initialization
865 // 2 axes only with joystick control
866 dwAxisMap[JOY_AXIS_X] = AxisTurn;
867 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
868 dwAxisMap[JOY_AXIS_Y] = AxisForward;
869 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
873 if (strcmp (joy_name.string, "joystick") != 0)
875 // notify user of advanced controller
876 Con_Printf ("\n%s configured\n\n", joy_name.string);
879 // advanced initialization here
880 // data supplied by user via joy_axisn cvars
881 dwTemp = (DWORD) joy_advaxisx.value;
882 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
883 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
884 dwTemp = (DWORD) joy_advaxisy.value;
885 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
886 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
887 dwTemp = (DWORD) joy_advaxisz.value;
888 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
889 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
890 dwTemp = (DWORD) joy_advaxisr.value;
891 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
892 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
893 dwTemp = (DWORD) joy_advaxisu.value;
894 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
895 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
896 dwTemp = (DWORD) joy_advaxisv.value;
897 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
898 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
901 // compute the axes to collect from DirectInput
902 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
903 for (i = 0; i < JOY_MAX_AXES; i++)
905 if (dwAxisMap[i] != AxisNada)
907 joy_flags |= dwAxisFlags[i];
918 void IN_Commands (void)
921 DWORD buttonstate, povstate;
929 // loop through the joystick buttons
930 // key a joystick event or auxillary event for higher number buttons for each state change
931 buttonstate = ji.dwButtons;
932 for (i=0 ; i < (int) joy_numbuttons ; i++)
934 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
936 key_index = (i < 4) ? K_JOY1 : K_AUX1;
937 Key_Event (key_index + i, true);
940 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
942 key_index = (i < 4) ? K_JOY1 : K_AUX1;
943 Key_Event (key_index + i, false);
946 joy_oldbuttonstate = buttonstate;
950 // convert POV information into 4 bits of state information
951 // this avoids any potential problems related to moving from one
952 // direction to another without going through the center position
954 if(ji.dwPOV != JOY_POVCENTERED)
956 if (ji.dwPOV == JOY_POVFORWARD)
958 if (ji.dwPOV == JOY_POVRIGHT)
960 if (ji.dwPOV == JOY_POVBACKWARD)
962 if (ji.dwPOV == JOY_POVLEFT)
965 // determine which bits have changed and key an auxillary event for each change
966 for (i=0 ; i < 4 ; i++)
968 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
970 Key_Event (K_AUX29 + i, true);
973 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
975 Key_Event (K_AUX29 + i, false);
978 joy_oldpovstate = povstate;
988 qboolean IN_ReadJoystick (void)
991 memset (&ji, 0, sizeof(ji));
992 ji.dwSize = sizeof(ji);
993 ji.dwFlags = joy_flags;
995 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
997 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
998 // rather than having 32768 be the zero point, they have the zero point at 32668
999 // go figure -- anyway, now we get the full resolution out of the device
1000 if (joy_wwhack1.value != 0.0)
1008 // read error occurred
1009 // turning off the joystick seems too harsh for 1 read error,\
1010 // but what should be done?
1011 // Con_Printf ("IN_ReadJoystick: no response\n");
1012 // joy_avail = false;
1023 void IN_JoyMove (usercmd_t *cmd)
1025 float speed, aspeed;
1026 float fAxisValue, fTemp;
1027 int i, mouselook = (in_mlook.state & 1) || freelook.value;
1029 // complete initialization if first time in
1030 // this is needed as cvars are not available at initialization time
1031 if( joy_advancedinit != true )
1033 Joy_AdvancedUpdate_f();
1034 joy_advancedinit = true;
1037 // verify joystick is available and that the user wants to use it
1038 if (!joy_avail || !in_joystick.value)
1043 // collect the joystick data, if possible
1044 if (IN_ReadJoystick () != true)
1049 if (in_speed.state & 1)
1050 speed = cl_movespeedkey.value;
1053 aspeed = speed * host_realframetime;
1055 // loop through the axes
1056 for (i = 0; i < JOY_MAX_AXES; i++)
1058 // get the floating point zero-centered, potentially-inverted data for the current axis
1059 fAxisValue = (float) *pdwRawValue[i];
1060 // move centerpoint to zero
1061 fAxisValue -= 32768.0;
1063 if (joy_wwhack2.value != 0.0)
1065 if (dwAxisMap[i] == AxisTurn)
1067 // this is a special formula for the Logitech WingMan Warrior
1068 // y=ax^b; where a = 300 and b = 1.3
1069 // also x values are in increments of 800 (so this is factored out)
1070 // then bounds check result to level out excessively high spin rates
1071 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1072 if (fTemp > 14000.0)
1074 // restore direction information
1075 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1079 // convert range from -32768..32767 to -1..1
1080 fAxisValue /= 32768.0;
1082 switch (dwAxisMap[i])
1085 if ((joy_advanced.value == 0.0) && mouselook)
1087 // user wants forward control to become look control
1088 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1090 // if mouse invert is on, invert the joystick pitch value
1091 // only absolute control support here (joy_advanced is false)
1092 if (m_pitch.value < 0.0)
1094 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1098 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1104 // no pitch movement
1105 // disable pitch return-to-center unless requested by user
1106 // *** this code can be removed when the lookspring bug is fixed
1107 // *** the bug always has the lookspring feature on
1108 if(lookspring.value == 0.0)
1114 // user wants forward control to be forward control
1115 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1117 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1123 if (fabs(fAxisValue) > joy_sidethreshold.value)
1125 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1130 if ((in_strafe.state & 1) || (lookstrafe.value && mouselook))
1132 // user wants turn control to become side control
1133 if (fabs(fAxisValue) > joy_sidethreshold.value)
1135 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1140 // user wants turn control to be turn control
1141 if (fabs(fAxisValue) > joy_yawthreshold.value)
1143 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1145 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1149 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1159 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1161 // pitch movement detected and pitch movement desired by user
1162 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1164 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1168 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1174 // no pitch movement
1175 // disable pitch return-to-center unless requested by user
1176 // *** this code can be removed when the lookspring bug is fixed
1177 // *** the bug always has the lookspring feature on
1178 if(lookspring.value == 0.0)
1189 // bounds check pitch
1190 if (cl.viewangles[PITCH] > 80.0)
1191 cl.viewangles[PITCH] = 80.0;
1192 if (cl.viewangles[PITCH] < -70.0)
1193 cl.viewangles[PITCH] = -70.0;