Skip to content
Permalink
Browse files

Use higher sensitivity for y axis on touch device

  • Loading branch information...
deveee committed Nov 2, 2018
1 parent a7bbe54 commit f05172b93fbfd84d7c904a8901a654f07f47f1e1
@@ -53,15 +53,23 @@
<label proportion="1" align="center" text_align="right" I18N="In the multitouch settings screen" text="Deadzone"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
<spacer width="40" height="10" />
<gauge id="deadzone_center" proportion="1" min_value="0" max_value="50"/>
<gauge id="deadzone" proportion="1" min_value="0" max_value="50"/>
</div>
</div>

<div width="75%" layout="horizontal-row" proportion="1">
<label proportion="1" align="center" text_align="right" I18N="In the multitouch settings screen" text="Sensitivity"/>
<label proportion="1" align="center" text_align="right" I18N="In the multitouch settings screen" text="Sensitivity X"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
<spacer width="40" height="10" />
<gauge id="deadzone_edge" proportion="1" min_value="0" max_value="50"/>
<gauge id="sensitivity_x" proportion="1" min_value="0" max_value="50"/>
</div>
</div>

<div width="75%" layout="horizontal-row" proportion="1">
<label proportion="1" align="center" text_align="right" I18N="In the multitouch settings screen" text="Sensitivity Y"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
<spacer width="40" height="10" />
<gauge id="sensitivity_y" proportion="1" min_value="0" max_value="50"/>
</div>
</div>

@@ -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",
@@ -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,26 +411,28 @@ 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
{
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);
}

// ----------------------------------------------------------------------------
@@ -81,11 +81,15 @@ class MultitouchDevice : public InputDevice

/** 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 @@ class MultitouchDevice : public InputDevice
CIrrDeviceAndroid* m_android_device;
#endif

float getSteeringFactor(float value);
float getSteeringFactor(float value, float sensitivity);
void handleControls(MultitouchButton* button);
bool isGameRunning();

@@ -95,15 +95,20 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
assert(scale != NULL);
UserConfigParams::m_multitouch_scale = (float)scale->getValue() / 100.0f;

SpinnerWidget* deadzone_edge = getWidget<SpinnerWidget>("deadzone_edge");
assert(deadzone_edge != NULL);
UserConfigParams::m_multitouch_deadzone_edge =
(float)deadzone_edge->getValue() / 100.0f;

SpinnerWidget* deadzone_center = getWidget<SpinnerWidget>("deadzone_center");
assert(deadzone_center != NULL);
UserConfigParams::m_multitouch_deadzone_center =
(float)deadzone_center->getValue() / 100.0f;
SpinnerWidget* sensitivity_x = getWidget<SpinnerWidget>("sensitivity_x");
assert(sensitivity_x != NULL);
UserConfigParams::m_multitouch_sensitivity_x =
(float)sensitivity_x->getValue() / 100.0f;

SpinnerWidget* sensitivity_y = getWidget<SpinnerWidget>("sensitivity_y");
assert(sensitivity_y != NULL);
UserConfigParams::m_multitouch_sensitivity_y =
(float)sensitivity_y->getValue() / 100.0f;

SpinnerWidget* deadzone = getWidget<SpinnerWidget>("deadzone");
assert(deadzone != NULL);
UserConfigParams::m_multitouch_deadzone =
(float)deadzone->getValue() / 100.0f;

CheckBoxWidget* buttons_en = getWidget<CheckBoxWidget>("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<SpinnerWidget>("deadzone_edge");
assert(deadzone_edge != NULL);
deadzone_edge->setValue(
(int)(UserConfigParams::m_multitouch_deadzone_edge * 100.0f));

SpinnerWidget* deadzone_center = getWidget<SpinnerWidget>("deadzone_center");
assert(deadzone_center != NULL);
deadzone_center->setValue(
(int)(UserConfigParams::m_multitouch_deadzone_center * 100.0f));
SpinnerWidget* sensitivity_x = getWidget<SpinnerWidget>("sensitivity_x");
assert(sensitivity_x != NULL);
sensitivity_x->setValue(
(int)(UserConfigParams::m_multitouch_sensitivity_x * 100.0f));

SpinnerWidget* sensitivity_y = getWidget<SpinnerWidget>("sensitivity_y");
assert(sensitivity_y != NULL);
sensitivity_y->setValue(
(int)(UserConfigParams::m_multitouch_sensitivity_y * 100.0f));

SpinnerWidget* deadzone = getWidget<SpinnerWidget>("deadzone");
assert(deadzone != NULL);
deadzone->setValue(
(int)(UserConfigParams::m_multitouch_deadzone * 100.0f));

CheckBoxWidget* buttons_en = getWidget<CheckBoxWidget>("buttons_enabled");
assert(buttons_en != NULL);

0 comments on commit f05172b

Please sign in to comment.
You can’t perform that action at this time.