-/*
-===========
-IN_JoyMove
-===========
-*/
-static void IN_JoyMove (void)
-{
- float speed, aspeed;
- float fAxisValue, fTemp;
- int i, mouselook = (in_mlook.state & 1) || freelook.integer;
-
- // complete initialization if first time in
- // this is needed as cvars are not available at initialization time
- if( joy_advancedinit != true )
- {
- Joy_AdvancedUpdate_f();
- joy_advancedinit = true;
- }
-
- if (joy_avail)
- {
- int i, key_index;
- DWORD buttonstate, povstate;
-
- // loop through the joystick buttons
- // key a joystick event or auxillary event for higher number buttons for each state change
- buttonstate = ji.dwButtons;
- for (i=0 ; i < (int) joy_numbuttons ; i++)
- {
- if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
- {
- key_index = (i < 16) ? K_JOY1 : K_AUX1;
- Key_Event (key_index + i, 0, true);
- }
-
- if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
- {
- key_index = (i < 16) ? K_JOY1 : K_AUX1;
- Key_Event (key_index + i, 0, false);
- }
- }
- joy_oldbuttonstate = buttonstate;
-
- if (joy_haspov)
- {
- // convert POV information into 4 bits of state information
- // this avoids any potential problems related to moving from one
- // direction to another without going through the center position
- povstate = 0;
- if(ji.dwPOV != JOY_POVCENTERED)
- {
- if (ji.dwPOV == JOY_POVFORWARD)
- povstate |= 0x01;
- if (ji.dwPOV == JOY_POVRIGHT)
- povstate |= 0x02;
- if (ji.dwPOV == JOY_POVBACKWARD)
- povstate |= 0x04;
- if (ji.dwPOV == JOY_POVLEFT)
- povstate |= 0x08;
- }
- // determine which bits have changed and key an auxillary event for each change
- for (i=0 ; i < 4 ; i++)
- {
- if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
- {
- Key_Event (K_AUX29 + i, 0, true);
- }
-
- if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
- {
- Key_Event (K_AUX29 + i, 0, false);
- }
- }
- joy_oldpovstate = povstate;
- }
- }
-
- // verify joystick is available and that the user wants to use it
- if (!joy_avail || !in_joystick.integer)
- {
- return;
- }
-
- // collect the joystick data, if possible
- if (IN_ReadJoystick () != true)
- {
- return;
- }
-
- if (in_speed.state & 1)
- speed = cl_movespeedkey.value;
- else
- speed = 1;
- // LordHavoc: viewzoom affects sensitivity for sniping
- aspeed = speed * host_realframetime * cl.viewzoom;
-
- // loop through the axes
- for (i = 0; i < JOY_MAX_AXES; i++)
- {
- // get the floating point zero-centered, potentially-inverted data for the current axis
- fAxisValue = (float) *pdwRawValue[i];
- // move centerpoint to zero
- fAxisValue -= 32768.0;
-
- if (joy_wwhack2.integer != 0.0)
- {
- if (dwAxisMap[i] == AxisTurn)
- {
- // this is a special formula for the Logitech WingMan Warrior
- // y=ax^b; where a = 300 and b = 1.3
- // also x values are in increments of 800 (so this is factored out)
- // then bounds check result to level out excessively high spin rates
- fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
- if (fTemp > 14000.0)
- fTemp = 14000.0;
- // restore direction information
- fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
- }
- }
-
- // convert range from -32768..32767 to -1..1
- fAxisValue /= 32768.0;
-
- switch (dwAxisMap[i])
- {
- case AxisForward:
- if ((joy_advanced.integer == 0) && mouselook)
- {
- // user wants forward control to become look control
- if (fabs(fAxisValue) > joy_pitchthreshold.value)
- {
- // if mouse invert is on, invert the joystick pitch value
- // only absolute control support here (joy_advanced is false)
- if (m_pitch.value < 0.0)
- {
- cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
- }
- else
- {
- cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
- }
- V_StopPitchDrift();
- }
- else
- {
- // no pitch movement
- // disable pitch return-to-center unless requested by user
- // *** this code can be removed when the lookspring bug is fixed
- // *** the bug always has the lookspring feature on
- if(lookspring.value == 0.0)
- V_StopPitchDrift();
- }
- }
- else
- {
- // user wants forward control to be forward control
- if (fabs(fAxisValue) > joy_forwardthreshold.value)
- {
- cl.cmd.forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
- }
- }
- break;
-
- case AxisSide:
- if (fabs(fAxisValue) > joy_sidethreshold.value)
- {
- cl.cmd.sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
- }
- break;
-
- case AxisTurn:
- if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
- {
- // user wants turn control to become side control
- if (fabs(fAxisValue) > joy_sidethreshold.value)
- {
- cl.cmd.sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
- }
- }
- else
- {
- // user wants turn control to be turn control
- if (fabs(fAxisValue) > joy_yawthreshold.value)
- {
- if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
- {
- cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
- }
- else
- {
- cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
- }
-
- }
- }
- break;
-
- case AxisLook:
- if (mouselook)
- {
- if (fabs(fAxisValue) > joy_pitchthreshold.value)
- {
- // pitch movement detected and pitch movement desired by user
- if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
- {
- cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
- }
- else
- {
- cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
- }
- V_StopPitchDrift();
- }
- else
- {
- // no pitch movement
- // disable pitch return-to-center unless requested by user
- // *** this code can be removed when the lookspring bug is fixed
- // *** the bug always has the lookspring feature on
- if(lookspring.integer == 0)
- V_StopPitchDrift();
- }
- }
- break;
-
- default:
- break;
- }
- }
-}
-