moved tilt logic to separate unit and enabled tilt to control multiple input types

This commit is contained in:
bollu committed 2013-11-11 17:22:04 +05:30
1 parent 9afe69fa62
commit 9c219bc18b
9 files changed
+306 -12

No files matched your search

+83 -5
View File
@@ -68,6 +68,7 @@
#include "UI/OnScreenDisplay.h"
#include "UI/MiscScreens.h"
#include "UI/TiltEventProcessor.h"
// The new UI framework, for initialization
@@ -653,16 +654,93 @@ 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){
return;
}else{
//reset all tilt events every frame.
//ResetTiltEvents();
}
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;
}
//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;
}
/*
if (screenManager)
screenManager->axis(key);
*/
}
void NativeMessageReceived(const char *message, const char *value) {