Added sin and asin in addition to linear and square mapping of
wii-rotation to steering value, all can be combined using weights. Code is not tested (sorry, no access to wiimote atm). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12527 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
8df713d666
commit
c18ccef5b3
@ -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
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user