Merge pull request #3522 from pelya/gyroscope
Gyroscope support for Android
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
<ribbon id="control_type" proportion="1" width="100%" align="center">
|
||||
<icon-button id="accelerometer" width="fit" height="fit" icon="gui/icons/difficulty_medium.png"
|
||||
I18N="Control type" text="Accelerometer"/>
|
||||
<icon-button id="gyroscope" width="fit" height="fit" icon="gui/icons/difficulty_best.png"
|
||||
I18N="Control type" text="Gyroscope"/>
|
||||
<icon-button id="steering_wheel" width="fit" height="fit" icon="gui/icons/difficulty_hard.png"
|
||||
I18N="Control type" text="Steering wheel"/>
|
||||
</ribbon>
|
||||
|
||||
@@ -39,6 +39,14 @@
|
||||
</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="Gyroscope"/>
|
||||
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
|
||||
<spacer width="40" height="10" />
|
||||
<checkbox id="gyroscope"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label width="100%" I18N="In the multitouch settings screen" text="Advanced"/>
|
||||
|
||||
<div width="75%" layout="horizontal-row" proportion="1">
|
||||
|
||||
@@ -168,6 +168,13 @@ msgstr ""
|
||||
msgid "Accelerometer"
|
||||
msgstr ""
|
||||
|
||||
#. I18N: ./data/gui/dialogs/android/init_android.stkgui
|
||||
#. I18N: Control type
|
||||
#. I18N: ./data/gui/dialogs/android/multitouch_settings.stkgui
|
||||
#. I18N: In the multitouch settings screen
|
||||
msgid "Gyroscope"
|
||||
msgstr ""
|
||||
|
||||
#. I18N: ./data/gui/dialogs/android/init_android.stkgui
|
||||
#. I18N: Control type
|
||||
msgid "Steering wheel"
|
||||
|
||||
@@ -352,6 +352,14 @@ enum GeometryLevel
|
||||
GEOLEVEL_2 = 2
|
||||
};
|
||||
|
||||
enum MultitouchControls
|
||||
{
|
||||
MULTITOUCH_CONTROLS_UNDEFINED = 0,
|
||||
MULTITOUCH_CONTROLS_STEERING_WHEEL = 1,
|
||||
MULTITOUCH_CONTROLS_ACCELEROMETER = 2,
|
||||
MULTITOUCH_CONTROLS_GYROSCOPE = 3,
|
||||
};
|
||||
|
||||
/** Using X-macros for setting-possible values is not very pretty, but it's a
|
||||
* no-maintenance case :
|
||||
* when you want to add a new parameter, just add one signle line below and
|
||||
@@ -488,7 +496,7 @@ namespace UserConfigParams
|
||||
PARAM_PREFIX IntUserConfigParam m_multitouch_controls
|
||||
PARAM_DEFAULT( IntUserConfigParam(0, "multitouch_controls",
|
||||
&m_multitouch_group,
|
||||
"Multitouch mode: 0 = undefined, 1 = steering wheel, 2 = accelerometer"));
|
||||
"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",
|
||||
|
||||
@@ -135,7 +135,7 @@ void CameraEnd::update(float dt)
|
||||
|
||||
positionCamera(dt, /*above_kart*/0.75f,
|
||||
cam_angle, /*side_way*/0,
|
||||
2.0f*getDistanceToKart(), /*smoothing*/false);
|
||||
2.0f*getDistanceToKart(), /*smoothing*/false, 0.0f);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
#include "graphics/camera_normal.hpp"
|
||||
|
||||
#include "config/stk_config.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "input/multitouch_device.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "karts/explosion_animation.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
@@ -175,10 +179,11 @@ void CameraNormal::snapToPosition()
|
||||
* \param cam_angle Angle above the kart plane for the camera.
|
||||
* \param sideway Sideway movement of the camera.
|
||||
* \param distance Distance from kart.
|
||||
* \param cam_roll_angle Roll camera for gyroscope steering effect.
|
||||
*/
|
||||
void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
|
||||
float *sideway, float *distance,
|
||||
bool *smoothing)
|
||||
bool *smoothing, float *cam_roll_angle)
|
||||
{
|
||||
const KartProperties *kp = m_kart->getKartProperties();
|
||||
|
||||
@@ -197,6 +202,15 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
|
||||
float dampened_steer = fabsf(steering) * steering;
|
||||
*sideway = -m_rotation_range*dampened_steer*0.5f;
|
||||
*smoothing = true;
|
||||
*cam_roll_angle = 0.0f;
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
MultitouchDevice* device = input_manager->getDeviceManager()->getMultitouchDevice();
|
||||
if (device)
|
||||
{
|
||||
*cam_roll_angle = -device->getOrientation();
|
||||
}
|
||||
}
|
||||
break;
|
||||
} // CM_FALLING
|
||||
case CM_REVERSE: // Same as CM_NORMAL except it looks backwards
|
||||
@@ -206,6 +220,15 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
|
||||
*sideway = 0;
|
||||
*distance = 2.0f*m_distance;
|
||||
*smoothing = false;
|
||||
*cam_roll_angle = 0.0f;
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
MultitouchDevice* device = input_manager->getDeviceManager()->getMultitouchDevice();
|
||||
if (device)
|
||||
{
|
||||
*cam_roll_angle = device->getOrientation();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CM_CLOSEUP: // Lower to the ground and closer to the kart
|
||||
@@ -217,6 +240,15 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
|
||||
* m_kart->getSkidding()->getSkidFactor();
|
||||
*distance = -0.5f*m_distance;
|
||||
*smoothing = false;
|
||||
*cam_roll_angle = 0.0f;
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
MultitouchDevice* device = input_manager->getDeviceManager()->getMultitouchDevice();
|
||||
if (device)
|
||||
{
|
||||
*cam_roll_angle = -device->getOrientation();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CM_LEADER_MODE:
|
||||
@@ -226,6 +258,7 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
|
||||
*sideway = 0;
|
||||
*distance = 2.0f*m_distance;
|
||||
*smoothing = true;
|
||||
*cam_roll_angle = 0.0f;
|
||||
break;
|
||||
}
|
||||
case CM_SIMPLE_REPLAY:
|
||||
@@ -252,10 +285,10 @@ void CameraNormal::update(float dt)
|
||||
dynamic_cast<ExplosionAnimation*>(m_kart->getKartAnimation());
|
||||
if (ea && !ea->hasResetAlready())
|
||||
{
|
||||
float above_kart, cam_angle, side_way, distance;
|
||||
float above_kart, cam_angle, side_way, distance, cam_roll_angle;
|
||||
bool smoothing;
|
||||
|
||||
getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing);
|
||||
getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing, &cam_roll_angle);
|
||||
// The camera target needs to be 'smooth moved', otherwise
|
||||
// there will be a noticable jump in the first frame
|
||||
|
||||
@@ -269,10 +302,10 @@ void CameraNormal::update(float dt)
|
||||
}
|
||||
else // no kart animation
|
||||
{
|
||||
float above_kart, cam_angle, side_way, distance;
|
||||
float above_kart, cam_angle, side_way, distance, cam_roll_angle;
|
||||
bool smoothing;
|
||||
getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing);
|
||||
positionCamera(dt, above_kart, cam_angle, side_way, distance, smoothing);
|
||||
getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing, &cam_roll_angle);
|
||||
positionCamera(dt, above_kart, cam_angle, side_way, distance, smoothing, cam_roll_angle);
|
||||
}
|
||||
} // update
|
||||
|
||||
@@ -283,9 +316,11 @@ void CameraNormal::update(float dt)
|
||||
* \param cam_angle Angle above the kart plane for the camera.
|
||||
* \param sideway Sideway movement of the camera.
|
||||
* \param distance Distance from kart.
|
||||
* \param cam_roll_angle Roll camera for gyroscope steering effect.
|
||||
*/
|
||||
void CameraNormal::positionCamera(float dt, float above_kart, float cam_angle,
|
||||
float side_way, float distance, float smoothing)
|
||||
float side_way, float distance, float smoothing,
|
||||
float cam_roll_angle)
|
||||
{
|
||||
Vec3 wanted_position;
|
||||
Vec3 wanted_target = m_kart->getSmoothedTrans()(Vec3(0, above_kart, 0));
|
||||
@@ -334,4 +369,11 @@ void CameraNormal::positionCamera(float dt, float above_kart, float cam_angle,
|
||||
} // kart && !flying
|
||||
else
|
||||
m_camera->setUpVector(core::vector3df(0, 1, 0));
|
||||
|
||||
if (cam_roll_angle != 0.0f)
|
||||
{
|
||||
irr::core::vector3df up(0, 1, 0);
|
||||
up.rotateXYBy(cam_roll_angle * (180.0f / M_PI));
|
||||
m_camera->setUpVector(up);
|
||||
}
|
||||
} // positionCamera
|
||||
|
||||
@@ -55,10 +55,11 @@ private:
|
||||
void handleEndCamera(float dt);
|
||||
void getCameraSettings(float *above_kart, float *cam_angle,
|
||||
float *side_way, float *distance,
|
||||
bool *smoothing);
|
||||
bool *smoothing, float *cam_roll_angle);
|
||||
|
||||
void positionCamera(float dt, float above_kart, float cam_angle,
|
||||
float side_way, float distance, float smoothing);
|
||||
float side_way, float distance, float smoothing,
|
||||
float cam_roll_angle);
|
||||
|
||||
btVector3 m_kart_position;
|
||||
btQuaternion m_kart_rotation;
|
||||
|
||||
@@ -202,7 +202,8 @@ bool EventHandler::OnEvent (const SEvent &event)
|
||||
event.EventType == EET_TOUCH_INPUT_EVENT ||
|
||||
event.EventType == EET_KEY_INPUT_EVENT ||
|
||||
event.EventType == EET_JOYSTICK_INPUT_EVENT ||
|
||||
event.EventType == EET_ACCELEROMETER_EVENT)
|
||||
event.EventType == EET_ACCELEROMETER_EVENT ||
|
||||
event.EventType == EET_GYROSCOPE_EVENT)
|
||||
{
|
||||
// Remember the mouse position
|
||||
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
|
||||
|
||||
@@ -937,6 +937,7 @@ bool InputManager::masterPlayerOnly() const
|
||||
*/
|
||||
EventPropagation InputManager::input(const SEvent& event)
|
||||
{
|
||||
const float ORIENTATION_MULTIPLIER = 10.0f;
|
||||
if (event.EventType == EET_JOYSTICK_INPUT_EVENT)
|
||||
{
|
||||
// Axes - FIXME, instead of checking all of them, ask the bindings
|
||||
@@ -1238,7 +1239,29 @@ EventPropagation InputManager::input(const SEvent& event)
|
||||
|
||||
float factor = UserConfigParams::m_multitouch_tilt_factor;
|
||||
factor = std::max(factor, 0.1f);
|
||||
device->updateAxisX(float(event.AccelerometerEvent.Y) / factor);
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
device->updateOrientationFromAccelerometer(event.AccelerometerEvent.X, event.AccelerometerEvent.Y);
|
||||
device->updateAxisX(device->getOrientation() * ORIENTATION_MULTIPLIER / factor);
|
||||
}
|
||||
else
|
||||
{
|
||||
device->updateAxisX(float(event.AccelerometerEvent.Y) / factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.EventType == EET_GYROSCOPE_EVENT)
|
||||
{
|
||||
MultitouchDevice* device = m_device_manager->getMultitouchDevice();
|
||||
|
||||
if (device && device->isGyroscopeActive())
|
||||
{
|
||||
m_device_manager->updateMultitouchDevice();
|
||||
|
||||
float factor = UserConfigParams::m_multitouch_tilt_factor;
|
||||
factor = std::max(factor, 0.1f);
|
||||
device->updateOrientationFromGyroscope(event.GyroscopeEvent.Z);
|
||||
device->updateAxisX(device->getOrientation() * ORIENTATION_MULTIPLIER / factor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +171,9 @@ void MultitouchDevice::reset()
|
||||
event.x = 0;
|
||||
event.y = 0;
|
||||
}
|
||||
|
||||
m_orientation = 0.0f;
|
||||
m_gyro_time = 0.0;
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -212,6 +215,45 @@ bool MultitouchDevice::isAccelerometerActive()
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Activates gyroscope
|
||||
*/
|
||||
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
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Deativates gyroscope
|
||||
*/
|
||||
void MultitouchDevice::deactivateGyroscope()
|
||||
{
|
||||
#ifdef ANDROID
|
||||
if (m_android_device->isGyroscopeActive())
|
||||
{
|
||||
m_android_device->deactivateGyroscope();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Get gyroscope state
|
||||
* \return true if gyroscope is active
|
||||
*/
|
||||
bool MultitouchDevice::isGyroscopeActive()
|
||||
{
|
||||
#ifdef ANDROID
|
||||
return m_android_device->isGyroscopeActive();
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** The function that is executed when touch event occurs. It updates the
|
||||
* buttons state when it's needed.
|
||||
@@ -382,6 +424,98 @@ void MultitouchDevice::updateAxisY(float value)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Returns device orientation Z angle, in radians, where 0 is landscape orientation parallel to the floor.
|
||||
*/
|
||||
float MultitouchDevice::getOrientation()
|
||||
{
|
||||
return m_orientation;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Update device orientation from the accelerometer measurements.
|
||||
* Accelerometer is shaky, so it adjusts the orientation angle slowly.
|
||||
* \param x Accelerometer X axis
|
||||
* \param y Accelerometer Y axis
|
||||
*/
|
||||
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_CHANGE_THRESHOLD = 0.01f; // ~0.5 degrees
|
||||
|
||||
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))
|
||||
{
|
||||
angle = (M_PI / 2.0);
|
||||
}
|
||||
if (angle < -(M_PI / 2.0))
|
||||
{
|
||||
angle = -(M_PI / 2.0);
|
||||
}
|
||||
|
||||
float delta = angle - m_orientation;
|
||||
delta *= ACCEL_MULTIPLIER;
|
||||
if (delta > ACCEL_CHANGE_THRESHOLD)
|
||||
{
|
||||
delta = ACCEL_CHANGE_THRESHOLD;
|
||||
}
|
||||
if (delta < -ACCEL_CHANGE_THRESHOLD)
|
||||
{
|
||||
delta = -ACCEL_CHANGE_THRESHOLD;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Update device orientation from the gyroscope measurements.
|
||||
* Gyroscope is not shaky and very sensitive, but drifts over time.
|
||||
* \param x Gyroscope Z axis
|
||||
*/
|
||||
void MultitouchDevice::updateOrientationFromGyroscope(float z)
|
||||
{
|
||||
const float GYRO_SPEED_THRESHOLD = 0.005f;
|
||||
|
||||
double now = StkTime::getRealTime();
|
||||
float timedelta = now - m_gyro_time;
|
||||
m_gyro_time = now;
|
||||
if (timedelta > 0.5f)
|
||||
{
|
||||
timedelta = 0.1f;
|
||||
}
|
||||
|
||||
float angular_speed = -z;
|
||||
|
||||
if (fabsf(angular_speed) < GYRO_SPEED_THRESHOLD)
|
||||
{
|
||||
angular_speed = 0.0f;
|
||||
}
|
||||
|
||||
m_orientation += angular_speed * timedelta;
|
||||
if (m_orientation > (M_PI / 2.0))
|
||||
{
|
||||
m_orientation = (M_PI / 2.0);
|
||||
}
|
||||
if (m_orientation < -(M_PI / 2.0))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Sends proper action for player controller depending on the button type
|
||||
* and state.
|
||||
* \param button The button that should be handled.
|
||||
|
||||
@@ -87,6 +87,9 @@ private:
|
||||
* at the edge of button */
|
||||
float m_deadzone_edge;
|
||||
|
||||
float m_orientation;
|
||||
double m_gyro_time;
|
||||
|
||||
#ifdef ANDROID
|
||||
/** Pointer to the Android irrlicht device */
|
||||
CIrrDeviceAndroid* m_android_device;
|
||||
@@ -125,9 +128,16 @@ public:
|
||||
void activateAccelerometer();
|
||||
void deactivateAccelerometer();
|
||||
bool isAccelerometerActive();
|
||||
|
||||
|
||||
void activateGyroscope();
|
||||
void deactivateGyroscope();
|
||||
bool isGyroscopeActive();
|
||||
|
||||
void updateAxisX(float value);
|
||||
void updateAxisY(float value);
|
||||
float getOrientation();
|
||||
void updateOrientationFromAccelerometer(float x, float y);
|
||||
void updateOrientationFromGyroscope(float z);
|
||||
void updateDeviceState(unsigned int event_id);
|
||||
void updateController();
|
||||
void updateConfigParams();
|
||||
|
||||
@@ -2083,7 +2083,7 @@ int main(int argc, char *argv[] )
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
if (UserConfigParams::m_multitouch_controls == 0)
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_UNDEFINED)
|
||||
{
|
||||
int32_t touch = AConfiguration_getTouchscreen(
|
||||
global_android_app->config);
|
||||
|
||||
@@ -64,12 +64,14 @@ void InitAndroidDialog::load()
|
||||
void InitAndroidDialog::beforeAddingWidgets()
|
||||
{
|
||||
bool accelerometer_available = false;
|
||||
bool gyroscope_available = false;
|
||||
|
||||
#ifdef ANDROID
|
||||
CIrrDeviceAndroid* android_device = dynamic_cast<CIrrDeviceAndroid*>(
|
||||
irr_driver->getDevice());
|
||||
assert(android_device != NULL);
|
||||
accelerometer_available = android_device->isAccelerometerAvailable();
|
||||
gyroscope_available = android_device->isGyroscopeAvailable() && accelerometer_available;
|
||||
#endif
|
||||
|
||||
if (!accelerometer_available)
|
||||
@@ -81,9 +83,24 @@ void InitAndroidDialog::beforeAddingWidgets()
|
||||
Widget* accelerometer = &control_type->getChildren()[index];
|
||||
accelerometer->setActive(false);
|
||||
|
||||
if (UserConfigParams::m_multitouch_controls == 2)
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER)
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = 1;
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gyroscope_available)
|
||||
{
|
||||
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
|
||||
assert(control_type != NULL);
|
||||
|
||||
int index = control_type->findItemNamed("gyroscope");
|
||||
Widget* gyroscope = &control_type->getChildren()[index];
|
||||
gyroscope->setActive(false);
|
||||
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,11 +127,15 @@ GUIEngine::EventPropagation InitAndroidDialog::processEvent(
|
||||
|
||||
if (selected == "steering_wheel")
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = 1;
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
}
|
||||
else if (selected == "accelerometer")
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = 2;
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_ACCELEROMETER;
|
||||
}
|
||||
else if (selected == "gyroscope")
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_GYROSCOPE;
|
||||
}
|
||||
|
||||
user_config->saveConfig();
|
||||
@@ -133,11 +154,16 @@ void InitAndroidDialog::updateValues()
|
||||
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
|
||||
assert(control_type != NULL);
|
||||
|
||||
if (UserConfigParams::m_multitouch_controls == 2)
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER)
|
||||
{
|
||||
int id = control_type->findItemNamed("accelerometer");
|
||||
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
|
||||
}
|
||||
else if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
int id = control_type->findItemNamed("gyroscope");
|
||||
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
|
||||
}
|
||||
else
|
||||
{
|
||||
int id = control_type->findItemNamed("steering_wheel");
|
||||
@@ -149,7 +175,7 @@ void InitAndroidDialog::updateValues()
|
||||
|
||||
bool InitAndroidDialog::onEscapePressed()
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = 1;
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
user_config->saveConfig();
|
||||
ModalDialog::dismiss();
|
||||
return true;
|
||||
|
||||
@@ -57,12 +57,14 @@ MultitouchSettingsDialog::~MultitouchSettingsDialog()
|
||||
void MultitouchSettingsDialog::beforeAddingWidgets()
|
||||
{
|
||||
bool accelerometer_available = false;
|
||||
bool gyroscope_available = false;
|
||||
|
||||
#ifdef ANDROID
|
||||
CIrrDeviceAndroid* android_device = dynamic_cast<CIrrDeviceAndroid*>(
|
||||
irr_driver->getDevice());
|
||||
assert(android_device != NULL);
|
||||
accelerometer_available = android_device->isAccelerometerAvailable();
|
||||
gyroscope_available = android_device->isGyroscopeAvailable() && accelerometer_available;
|
||||
#endif
|
||||
|
||||
if (!accelerometer_available)
|
||||
@@ -72,6 +74,13 @@ void MultitouchSettingsDialog::beforeAddingWidgets()
|
||||
accelerometer->setActive(false);
|
||||
}
|
||||
|
||||
if (!gyroscope_available)
|
||||
{
|
||||
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
|
||||
assert(gyroscope != NULL);
|
||||
gyroscope->setActive(false);
|
||||
}
|
||||
|
||||
updateValues();
|
||||
}
|
||||
|
||||
@@ -107,8 +116,20 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
|
||||
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
|
||||
assert(accelerometer != NULL);
|
||||
|
||||
UserConfigParams::m_multitouch_controls = accelerometer->
|
||||
getState() ? 2 : 1;
|
||||
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
|
||||
assert(gyroscope != NULL);
|
||||
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
|
||||
if (accelerometer->getState())
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_ACCELEROMETER;
|
||||
}
|
||||
|
||||
if (gyroscope->getState())
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_GYROSCOPE;
|
||||
}
|
||||
|
||||
MultitouchDevice* touch_device = input_manager->getDeviceManager()->
|
||||
getMultitouchDevice();
|
||||
@@ -159,6 +180,18 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
|
||||
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (eventSource == "accelerometer")
|
||||
{
|
||||
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
|
||||
assert(gyroscope != NULL);
|
||||
gyroscope->setState(false);
|
||||
}
|
||||
else if (eventSource == "gyroscope")
|
||||
{
|
||||
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
|
||||
assert(accelerometer != NULL);
|
||||
accelerometer->setState(false);
|
||||
}
|
||||
|
||||
return GUIEngine::EVENT_LET;
|
||||
} // processEvent
|
||||
@@ -191,7 +224,11 @@ void MultitouchSettingsDialog::updateValues()
|
||||
|
||||
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
|
||||
assert(accelerometer != NULL);
|
||||
accelerometer->setState(UserConfigParams::m_multitouch_controls == 2);
|
||||
accelerometer->setState(UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER);
|
||||
|
||||
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
|
||||
assert(gyroscope != NULL);
|
||||
gyroscope->setState(UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -104,6 +104,11 @@ void RaceGUIMultitouch::close()
|
||||
{
|
||||
m_device->deactivateAccelerometer();
|
||||
}
|
||||
|
||||
if (m_device->isGyroscopeActive())
|
||||
{
|
||||
m_device->deactivateGyroscope();
|
||||
}
|
||||
} // close
|
||||
|
||||
|
||||
@@ -116,10 +121,15 @@ void RaceGUIMultitouch::init()
|
||||
if (m_device == NULL)
|
||||
return;
|
||||
|
||||
if (UserConfigParams::m_multitouch_controls == 2)
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER)
|
||||
{
|
||||
m_device->activateAccelerometer();
|
||||
}
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
m_device->activateAccelerometer();
|
||||
m_device->activateGyroscope();
|
||||
}
|
||||
|
||||
const float scale = UserConfigParams::m_multitouch_scale;
|
||||
|
||||
@@ -155,7 +165,7 @@ void RaceGUIMultitouch::init()
|
||||
|
||||
m_height = (unsigned int)(2 * col_size + margin / 2);
|
||||
|
||||
if (m_device->isAccelerometerActive())
|
||||
if (m_device->isAccelerometerActive() || m_device->isGyroscopeActive())
|
||||
{
|
||||
m_device->addButton(BUTTON_UP_DOWN,
|
||||
int(steering_accel_x), int(steering_accel_y),
|
||||
|
||||
Reference in New Issue
Block a user