diff --git a/data/gui/dialogs/android/multitouch_settings.stkgui b/data/gui/dialogs/android/multitouch_settings.stkgui
index fb7126001..253424bf7 100644
--- a/data/gui/dialogs/android/multitouch_settings.stkgui
+++ b/data/gui/dialogs/android/multitouch_settings.stkgui
@@ -53,15 +53,23 @@
-
+
+
+
diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp
index d1ba52e4f..05e1b2733 100644
--- a/src/config/user_config.hpp
+++ b/src/config/user_config.hpp
@@ -498,17 +498,23 @@ namespace UserConfigParams
&m_multitouch_group,
"Multitouch mode: 0 = undefined, 1 = steering wheel, 2 = accelerometer, 3 = gyroscope"));
- PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone_center
- PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone_center",
+ PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone
+ PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone",
&m_multitouch_group,
"A parameter in range [0, 0.5] that determines the zone that is "
"considered as centered in steering button."));
- PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone_edge
- PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone_edge",
+ PARAM_PREFIX FloatUserConfigParam m_multitouch_sensitivity_x
+ PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_sensitivity_x",
&m_multitouch_group,
- "A parameter in range [0, 0.5] that determines the zone that is "
- "considered as max value in steering button."));
+ "A parameter in range [0, 0.5] that determines the zone for y axis "
+ "that is considered as max value in steering button."));
+
+ PARAM_PREFIX FloatUserConfigParam m_multitouch_sensitivity_y
+ PARAM_DEFAULT( FloatUserConfigParam(0.5f, "multitouch_sensitivity_y",
+ &m_multitouch_group,
+ "A parameter in range [0, 0.5] that determines the zone for y axis "
+ "that is considered as max value in steering button."));
PARAM_PREFIX FloatUserConfigParam m_multitouch_tilt_factor
PARAM_DEFAULT( FloatUserConfigParam(4.0f, "multitouch_tilt_factor",
diff --git a/src/input/multitouch_device.cpp b/src/input/multitouch_device.cpp
index 4d6b5d8ee..eb5408fff 100644
--- a/src/input/multitouch_device.cpp
+++ b/src/input/multitouch_device.cpp
@@ -223,7 +223,9 @@ void MultitouchDevice::activateGyroscope()
#ifdef ANDROID
if (!m_android_device->isGyroscopeActive())
{
- m_android_device->activateGyroscope(1.0f / 60); // Assume 60 FPS, some phones can do 90 and 120 FPS but we won't handle them now
+ // Assume 60 FPS, some phones can do 90 and 120 FPS but we won't handle
+ // them now
+ m_android_device->activateGyroscope(1.0f / 60);
}
#endif
}
@@ -350,26 +352,30 @@ void MultitouchDevice::updateDeviceState(unsigned int event_id)
*/
void MultitouchDevice::updateConfigParams()
{
- m_deadzone_center = UserConfigParams::m_multitouch_deadzone_center;
- m_deadzone_center = std::min(std::max(m_deadzone_center, 0.0f), 0.5f);
+ m_deadzone = UserConfigParams::m_multitouch_deadzone;
+ m_deadzone = std::min(std::max(m_deadzone, 0.0f), 0.5f);
- m_deadzone_edge = UserConfigParams::m_multitouch_deadzone_edge;
- m_deadzone_edge = std::min(std::max(m_deadzone_edge, 0.0f), 0.5f);
+ m_sensitivity_x = UserConfigParams::m_multitouch_sensitivity_x;
+ m_sensitivity_x = std::min(std::max(m_sensitivity_x, 0.0f), 0.5f);
+
+ m_sensitivity_y = UserConfigParams::m_multitouch_sensitivity_y;
+ m_sensitivity_y = std::min(std::max(m_sensitivity_y, 0.0f), 0.5f);
} // updateConfigParams
// ----------------------------------------------------------------------------
/** Helper function that returns a steering factor for steering button.
* \param value The axis value from 0 to 1.
+ * \param sensitivity Value from 0 to 0.5.
*/
-float MultitouchDevice::getSteeringFactor(float value)
+float MultitouchDevice::getSteeringFactor(float value, float sensitivity)
{
- if (m_deadzone_edge + m_deadzone_center >= 1.0f)
+ if (sensitivity + m_deadzone >= 1.0f)
return 1.0f;
- assert(m_deadzone_edge + m_deadzone_center != 1.0f);
+ assert(sensitivity + m_deadzone != 1.0f);
- return std::min((value - m_deadzone_center) / (1.0f - m_deadzone_edge -
- m_deadzone_center), 1.0f);
+ return std::min((value - m_deadzone) / (1.0f - sensitivity -
+ m_deadzone), 1.0f);
}
// ----------------------------------------------------------------------------
@@ -379,15 +385,15 @@ void MultitouchDevice::updateAxisX(float value)
if (m_controller == NULL)
return;
- if (value < -m_deadzone_center)
+ if (value < -m_deadzone)
{
- float factor = getSteeringFactor(std::abs(value));
+ float factor = getSteeringFactor(std::abs(value), m_sensitivity_x);
m_controller->action(PA_STEER_RIGHT, 0);
m_controller->action(PA_STEER_LEFT, int(factor * Input::MAX_VALUE));
}
- else if (value > m_deadzone_center)
+ else if (value > m_deadzone)
{
- float factor = getSteeringFactor(std::abs(value));
+ float factor = getSteeringFactor(std::abs(value), m_sensitivity_x);
m_controller->action(PA_STEER_LEFT, 0);
m_controller->action(PA_STEER_RIGHT, int(factor * Input::MAX_VALUE));
}
@@ -405,14 +411,14 @@ void MultitouchDevice::updateAxisY(float value)
if (m_controller == NULL)
return;
- if (value < -m_deadzone_center)
+ if (value < -m_deadzone)
{
- float factor = getSteeringFactor(std::abs(value));
+ float factor = getSteeringFactor(std::abs(value), m_sensitivity_y);
m_controller->action(PA_ACCEL, int(factor * Input::MAX_VALUE));
}
- else if (value > m_deadzone_center)
+ else if (value > m_deadzone)
{
- float factor = getSteeringFactor(std::abs(value));
+ float factor = getSteeringFactor(std::abs(value), m_sensitivity_y);
m_controller->action(PA_BRAKE, int(factor * Input::MAX_VALUE));
}
else
@@ -420,11 +426,13 @@ void MultitouchDevice::updateAxisY(float value)
m_controller->action(PA_BRAKE, 0);
m_controller->action(PA_ACCEL, 0);
}
+
}
// ----------------------------------------------------------------------------
-/** Returns device orientation Z angle, in radians, where 0 is landscape orientation parallel to the floor.
+/** Returns device orientation Z angle, in radians, where 0 is landscape
+ * orientation parallel to the floor.
*/
float MultitouchDevice::getOrientation()
{
@@ -441,14 +449,14 @@ float MultitouchDevice::getOrientation()
void MultitouchDevice::updateOrientationFromAccelerometer(float x, float y)
{
const float ACCEL_DISCARD_THRESHOLD = 4.0f;
- const float ACCEL_MULTIPLIER = 0.05f; // Slowly adjust the angle over time, this prevents shaking
+ const float ACCEL_MULTIPLIER = 0.05f; // Slowly adjust the angle over time,
+ // this prevents shaking
const float ACCEL_CHANGE_THRESHOLD = 0.01f; // ~0.5 degrees
+ // The device is flat on the table, cannot reliably determine the
+ // orientation
if (fabsf(x) + fabsf(y) < ACCEL_DISCARD_THRESHOLD)
- {
- // The device is flat on the table, cannot reliably determine the orientation
return;
- }
float angle = atan2f(y, x);
if (angle > (M_PI / 2.0))
@@ -473,7 +481,8 @@ void MultitouchDevice::updateOrientationFromAccelerometer(float x, float y)
m_orientation += delta;
- //Log::warn("Accel", "X %03.4f Y %03.4f angle %03.4f delta %03.4f orientation %03.4f", x, y, angle, delta, m_orientation);
+ //Log::warn("Accel", "X %03.4f Y %03.4f angle %03.4f delta %03.4f "
+ // "orientation %03.4f", x, y, angle, delta, m_orientation);
}
// ----------------------------------------------------------------------------
@@ -511,7 +520,9 @@ void MultitouchDevice::updateOrientationFromGyroscope(float z)
m_orientation = -(M_PI / 2.0);
}
- //Log::warn("Gyro", "Z %03.4f angular_speed %03.4f delta %03.4f orientation %03.4f", z, angular_speed, angular_speed * timedelta, m_orientation);
+ //Log::warn("Gyro", "Z %03.4f angular_speed %03.4f delta %03.4f "
+ // "orientation %03.4f", z, angular_speed,
+ // angular_speed * timedelta, m_orientation);
}
// ----------------------------------------------------------------------------
diff --git a/src/input/multitouch_device.hpp b/src/input/multitouch_device.hpp
index b188ca588..e343fdd36 100644
--- a/src/input/multitouch_device.hpp
+++ b/src/input/multitouch_device.hpp
@@ -81,11 +81,15 @@ private:
/** The parameter that is used for steering button and determines dead area
* in a center of button */
- float m_deadzone_center;
+ float m_deadzone;
- /** The parameter that is used for steering button and determines dead area
- * at the edge of button */
- float m_deadzone_edge;
+ /** A parameter that determines the zone for x axis that is considered as
+ * max value in steering button. */
+ float m_sensitivity_x;
+
+ /** A parameter that determines the zone for y axis that is considered as
+ * max value in steering button. */
+ float m_sensitivity_y;
float m_orientation;
double m_gyro_time;
@@ -95,7 +99,7 @@ private:
CIrrDeviceAndroid* m_android_device;
#endif
- float getSteeringFactor(float value);
+ float getSteeringFactor(float value, float sensitivity);
void handleControls(MultitouchButton* button);
bool isGameRunning();
diff --git a/src/states_screens/dialogs/multitouch_settings_dialog.cpp b/src/states_screens/dialogs/multitouch_settings_dialog.cpp
index 688709ee3..5eb5f4985 100644
--- a/src/states_screens/dialogs/multitouch_settings_dialog.cpp
+++ b/src/states_screens/dialogs/multitouch_settings_dialog.cpp
@@ -95,15 +95,20 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
assert(scale != NULL);
UserConfigParams::m_multitouch_scale = (float)scale->getValue() / 100.0f;
- SpinnerWidget* deadzone_edge = getWidget("deadzone_edge");
- assert(deadzone_edge != NULL);
- UserConfigParams::m_multitouch_deadzone_edge =
- (float)deadzone_edge->getValue() / 100.0f;
+ SpinnerWidget* sensitivity_x = getWidget("sensitivity_x");
+ assert(sensitivity_x != NULL);
+ UserConfigParams::m_multitouch_sensitivity_x =
+ (float)sensitivity_x->getValue() / 100.0f;
+
+ SpinnerWidget* sensitivity_y = getWidget("sensitivity_y");
+ assert(sensitivity_y != NULL);
+ UserConfigParams::m_multitouch_sensitivity_y =
+ (float)sensitivity_y->getValue() / 100.0f;
- SpinnerWidget* deadzone_center = getWidget("deadzone_center");
- assert(deadzone_center != NULL);
- UserConfigParams::m_multitouch_deadzone_center =
- (float)deadzone_center->getValue() / 100.0f;
+ SpinnerWidget* deadzone = getWidget("deadzone");
+ assert(deadzone != NULL);
+ UserConfigParams::m_multitouch_deadzone =
+ (float)deadzone->getValue() / 100.0f;
CheckBoxWidget* buttons_en = getWidget("buttons_enabled");
assert(buttons_en != NULL);
@@ -146,8 +151,9 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
}
else if (eventSource == "restore")
{
- UserConfigParams::m_multitouch_deadzone_edge.revertToDefaults();
- UserConfigParams::m_multitouch_deadzone_center.revertToDefaults();
+ UserConfigParams::m_multitouch_sensitivity_x.revertToDefaults();
+ UserConfigParams::m_multitouch_sensitivity_y.revertToDefaults();
+ UserConfigParams::m_multitouch_deadzone.revertToDefaults();
UserConfigParams::m_multitouch_mode.revertToDefaults();
UserConfigParams::m_multitouch_inverted.revertToDefaults();
UserConfigParams::m_multitouch_controls.revertToDefaults();
@@ -204,15 +210,20 @@ void MultitouchSettingsDialog::updateValues()
assert(scale != NULL);
scale->setValue((int)(UserConfigParams::m_multitouch_scale * 100.0f));
- SpinnerWidget* deadzone_edge = getWidget("deadzone_edge");
- assert(deadzone_edge != NULL);
- deadzone_edge->setValue(
- (int)(UserConfigParams::m_multitouch_deadzone_edge * 100.0f));
+ SpinnerWidget* sensitivity_x = getWidget("sensitivity_x");
+ assert(sensitivity_x != NULL);
+ sensitivity_x->setValue(
+ (int)(UserConfigParams::m_multitouch_sensitivity_x * 100.0f));
+
+ SpinnerWidget* sensitivity_y = getWidget("sensitivity_y");
+ assert(sensitivity_y != NULL);
+ sensitivity_y->setValue(
+ (int)(UserConfigParams::m_multitouch_sensitivity_y * 100.0f));
- SpinnerWidget* deadzone_center = getWidget("deadzone_center");
- assert(deadzone_center != NULL);
- deadzone_center->setValue(
- (int)(UserConfigParams::m_multitouch_deadzone_center * 100.0f));
+ SpinnerWidget* deadzone = getWidget("deadzone");
+ assert(deadzone != NULL);
+ deadzone->setValue(
+ (int)(UserConfigParams::m_multitouch_deadzone * 100.0f));
CheckBoxWidget* buttons_en = getWidget("buttons_enabled");
assert(buttons_en != NULL);