Made wiimote settings configurable in the user's config file:
wii-mote max is the 'angle' (0-128) at which full steering is reached, and a weight factor to shape the steering depending on wiimote angle, which adds up a weighted components of a linear (weight=0) and quadratic curve (weight=1). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12447 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -333,7 +333,21 @@ namespace UserConfigParams
|
||||
PARAM_DEFAULT( StringUserConfigParam("all", "last_kart_group",
|
||||
"Last selected kart group") );
|
||||
|
||||
// ---- GP start order
|
||||
// ---- Wiimote data
|
||||
PARAM_PREFIX GroupUserConfigParam m_wiimote_group
|
||||
PARAM_DEFAULT( GroupUserConfigParam("WiiMote",
|
||||
"Settings for the wiimote") );
|
||||
PARAM_PREFIX FloatUserConfigParam m_wiimote_max
|
||||
PARAM_DEFAULT( FloatUserConfigParam(80.0f, "wiimote-max",
|
||||
&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",
|
||||
&m_wiimote_group,
|
||||
"A weight applied to map the wiimote angle to steering angle: 0=fully linear, 1-fully quadratic") );
|
||||
|
||||
// ---- GP start order
|
||||
PARAM_PREFIX GroupUserConfigParam m_gp_start_order
|
||||
PARAM_DEFAULT( GroupUserConfigParam("GpStartOrder",
|
||||
"Order karts start in GP") );
|
||||
|
||||
@@ -33,7 +33,6 @@ const int WIIMOTE_BUTTONS = 12; // A, B, left, right, top, bottom, 1, 2,
|
||||
/** Irrlicht device IDs for the wiimotes start at this value */
|
||||
static const int WIIMOTE_START_IRR_ID = 32;
|
||||
|
||||
static const float WIIMOTE_ABS_MAX_ANGLE = 80.0f;
|
||||
static const float JOYSTICK_ABS_MAX_ANGLE = 32767.0f;
|
||||
|
||||
// ============================ Helper functions ============================
|
||||
@@ -164,16 +163,19 @@ void Wiimote::updateIrrEvent()
|
||||
//printf("roll: %f\n", m_wiimote_handle->orient.roll);
|
||||
|
||||
// --- Linear response version ---
|
||||
//const float wiimote_to_joystick = -JOYSTICK_ABS_MAX_ANGLE / WIIMOTE_ABS_MAX_ANGLE;
|
||||
//const float wiimote_to_joystick = -JOYSTICK_ABS_MAX_ANGLE / float(UserConfigParams::m_wiimote_max);
|
||||
//const float angle = wiimote_to_joystick * m_wiimote_handle->orient.pitch;
|
||||
|
||||
// --- Quadratic response version ---
|
||||
const float normalized_angle = -m_wiimote_handle->orient.pitch / WIIMOTE_ABS_MAX_ANGLE; // around [-1, 1]
|
||||
const float normalized_angle_2 = normalized_angle * normalized_angle; // change the response curve to be
|
||||
// less sensitive with values near 0
|
||||
const float normalized_angle = -m_wiimote_handle->orient.pitch / UserConfigParams::m_wiimote_max;
|
||||
// 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);
|
||||
const float sign = normalized_angle >= 0.0f ? 1.0f : -1.0f;
|
||||
const float angle = sign * 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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user