Merge pull request #4515 from bollu/improvedTilControls

Redid the tilt controls in a nicer way
This commit is contained in:
Henrik Rydgård committed 2013-12-22 02:13:28 -08:00
commit b0bfda6333
13 files changed
+329 -18

No files matched your search

+82 -7
View File
@@ -73,6 +73,7 @@
#include "UI/OnScreenDisplay.h"
#include "UI/MiscScreens.h"
#include "UI/TiltEventProcessor.h"
// The new UI framework, for initialization
@@ -669,16 +670,90 @@ void NativeKey(const KeyInput &key) {
}
void NativeAxis(const AxisInput &key) {
// ILOG("Axis id: %i value: %f", (int)key.axisId, key.value);
if (key.axisId >= JOYSTICK_AXIS_ACCELEROMETER_X && key.axisId <= JOYSTICK_AXIS_ACCELEROMETER_Z) {
// Disable accelerometer as an axis for now.
using namespace TiltEventProcessor;
//only handle tilt events if tilt is enabled.
if (g_Config.iTiltInputType == TILT_NULL){
//if tilt events are disabled, then run it through the usual way.
if (screenManager) {
screenManager->axis(key);
}
return;
}
if (isOuya && key.axisId >= JOYSTICK_AXIS_OUYA_UNKNOWN1 && key.axisId <= JOYSTICK_AXIS_OUYA_UNKNOWN4) {
return;
//create the base coordinate tilt system from the calibration data.
//This is static for no particular reason, can be un-static'ed
static Tilt baseTilt;
baseTilt.x_ = g_Config.fTiltBaseX; baseTilt.y_ = g_Config.fTiltBaseY;
//figure out what the current tilt orientation is by checking the axis event
//This is static, since we need to remember where we last were (in terms of orientation)
static Tilt currentTilt;
switch (key.axisId) {
case JOYSTICK_AXIS_ACCELEROMETER_X:
//x and y are flipped due to landscape orientation. The events are
//sent with respect to the portrait coordinate system, while we
//take all events in landscape.
//see [http://developer.android.com/guide/topics/sensors/sensors_overview.html] for details
currentTilt.y_ = key.value;
break;
case JOYSTICK_AXIS_ACCELEROMETER_Y:
currentTilt.x_ = key.value;
break;
case JOYSTICK_AXIS_ACCELEROMETER_Z:
//don't handle this now as only landscape is enabled.
//TODO: make this generic.
return;
case JOYSTICK_AXIS_OUYA_UNKNOWN1:
case JOYSTICK_AXIS_OUYA_UNKNOWN2:
case JOYSTICK_AXIS_OUYA_UNKNOWN3:
case JOYSTICK_AXIS_OUYA_UNKNOWN4:
//Don't know how to handle these. Someone should figure it out.
//Does the Ouya even have an accelerometer / gyro? I can't find any reference to these
//in the Ouya docs...
return;
default:
return;
}
if (screenManager)
screenManager->axis(key);
//figure out the sensitivity of the tilt. (sensitivity is originally 0 - 100)
//We divide by 50, so that the rest of the 50 units can be used to overshoot the
//target. If you want control, you'd keep the sensitivity ~50.
//For games that don't need much control but need fast reactions,
//then a value of 70-80 is the way to go.
float xSensitivity = g_Config.iTiltSensitivityX / 50.0;
float ySensitivity = g_Config.iTiltSensitivityY / 50.0;
//now transform out current tilt to the calibrated coordinate system
Tilt trueTilt = GenTilt(baseTilt, currentTilt, g_Config.bInvertTiltX, g_Config.bInvertTiltY, g_Config.fDeadzoneRadius, xSensitivity, ySensitivity);
//now send the appropriate tilt event
switch (g_Config.iTiltInputType) {
case TILT_ANALOG:
GenerateAnalogStickEvent(trueTilt);
break;
case TILT_DPAD:
GenerateDPadEvent(trueTilt);
break;
case TILT_ACTION_BUTTON:
GenerateActionButtonEvent(trueTilt);
break;
}
}
void NativeMessageReceived(const char *message, const char *value) {