diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 1fa16fd25..688096113 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -342,10 +342,25 @@ namespace UserConfigParams &m_wiimote_group, "At what angle (0-128) maximum steering is reached.") ); - PARAM_PREFIX FloatUserConfigParam m_wiimote_weight - PARAM_DEFAULT( FloatUserConfigParam(0.5f, "wiimote-weight", + PARAM_PREFIX FloatUserConfigParam m_wiimote_weight_linear + PARAM_DEFAULT( FloatUserConfigParam(0.5f, "wiimote-weight-linear", &m_wiimote_group, - "A weight applied to map the wiimote angle to steering angle: 0=fully linear, 1-fully quadratic") ); + "A weight applied to the linear component of mapping wiimote angle to steering angle")); + + PARAM_PREFIX FloatUserConfigParam m_wiimote_weight_square + PARAM_DEFAULT( FloatUserConfigParam(0.5f, "wiimote-weight-square", + &m_wiimote_group, + "A weight applied to the square component of mapping wiimote angle to steering angle")); + + PARAM_PREFIX FloatUserConfigParam m_wiimote_weight_asin + PARAM_DEFAULT( FloatUserConfigParam(0.0f, "wiimote-weight-asin", + &m_wiimote_group, + "A weight applied to the asin component of mapping wiimote angle to steering angle")); + + PARAM_PREFIX FloatUserConfigParam m_wiimote_weight_sin + PARAM_DEFAULT( FloatUserConfigParam(0.0f, "wiimote-weight-sin", + &m_wiimote_group, + "A weight applied to the sin component of mapping wiimote angle to steering angle")); // ---- GP start order PARAM_PREFIX GroupUserConfigParam m_gp_start_order diff --git a/src/input/wiimote_manager.cpp b/src/input/wiimote_manager.cpp index 5225e46e7..4759c569b 100644 --- a/src/input/wiimote_manager.cpp +++ b/src/input/wiimote_manager.cpp @@ -178,14 +178,21 @@ void Wiimote::updateIrrEvent() normalized_angle = -1.0f; else if(normalized_angle>1.0f) normalized_angle = 1.0f; + // Shape the curve that determines steering depending on wiimote angle. - // Linear might be too sensitive around 0, while quadratic is not sensitive - // enough - blend between those curves using weight w - float w = UserConfigParams::m_wiimote_weight; - const float normalized_angle_2 = w * normalized_angle * normalized_angle - + (1-w) * fabsf(normalized_angle); + // The wiimote value is already normalized to be in [-1,1]. Now use a + // weighted linear combination to compute the steering value used in game. + float w1 = UserConfigParams::m_wiimote_weight_linear; + float w2 = UserConfigParams::m_wiimote_weight_square; + float wa = UserConfigParams::m_wiimote_weight_asin; + float ws = UserConfigParams::m_wiimote_weight_sin; + const float sign = normalized_angle >= 0.0f ? 1.0f : -1.0f; - const float angle = sign * normalized_angle_2 * JOYSTICK_ABS_MAX_ANGLE; + const float normalized_angle_2 = w1 * normalized_angle + + w2 * sign*normalized_angle * normalized_angle + + wa * asin(normalized_angle)*(2.0f/M_PI) + + ws * sin(normalized_angle*(M_PI/2.0f)); + const float angle = normalized_angle_2 * JOYSTICK_ABS_MAX_ANGLE; m_irr_event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_X] = (irr::s16)(irr::core::clamp(angle, -JOYSTICK_ABS_MAX_ANGLE, +JOYSTICK_ABS_MAX_ANGLE));