void AddAxes(float axes[NUM_JOYAXIS]) { // Add to game axes. for (int i = 0; i < GetNumAxes(); ++i) { if(Axes[i].GameAxis != JOYAXIS_None) axes[Axes[i].GameAxis] -= float(Axes[i].Value * Multiplier * Axes[i].Multiplier); } }
bool JoystickInfo::PollAxes(u32 &pkey) { for (int i = 0; i < GetNumAxes(); ++i) { // Sixaxis, dualshock3 hack u32 found_hack = devname.find(string("PLAYSTATION(R)3")); if (found_hack != string::npos) { // The analog mode of the hat button is quite erratic. Values can be in half- axis // or full axis... So better keep them as button for the moment -- gregory if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb)) continue; // Disable accelerometer if ((i >= 4 && i <= 6)) continue; } s32 value = SDL_JoystickGetAxis(GetJoy(), i); s32 old_value = GetAxisState(i); if (abs(value - old_value) < 0x1000) continue; if (value != old_value) { PAD_LOG("Change in joystick %d: %d.\n", i, value); // There are several kinds of axes // Half+: 0 (release) -> 32768 // Half-: 0 (release) -> -32768 // Full (like dualshock 3): -32768 (release) ->32768 const s32 full_axis_ceil = -0x6FFF; const s32 half_axis_ceil = 0x1FFF; // Normally, old_value contains the release state so it can be used to detect the types of axis. bool is_full_axis = (old_value < full_axis_ceil) ? true : false; if ((!is_full_axis && abs(value) <= half_axis_ceil) || (is_full_axis && value <= full_axis_ceil)) // we don't want this { continue; } if ((!is_full_axis && abs(value) > half_axis_ceil) || (is_full_axis && value > full_axis_ceil)) { bool sign = (value < 0); pkey = axis_to_key(is_full_axis, sign, i); return true; } } } return false; }
void SetDefaultConfig() { for(int i = 0;i < GetNumAxes();i++) { AxisInfo info; if(i < NumAxes) info.Name.Format("Axis %d", i+1); else info.Name.Format("Hat %d (%c)", (i-NumAxes)/2 + 1, (i-NumAxes)%2 == 0 ? 'x' : 'y'); info.DeadZone = MIN_DEADZONE; info.Multiplier = 1.0f; info.Value = 0.0; info.ButtonValue = 0; if(i >= 5) info.GameAxis = JOYAXIS_None; else info.GameAxis = DefaultAxes[i]; Axes.Push(info); } }