fixed a tilt bug

This commit is contained in:
bollu 2013-12-14 18:25:57 +05:30
parent b0c7e824be
commit ee5a9fb9b1
3 changed files with 22 additions and 13 deletions

View file

@ -33,6 +33,7 @@
#include "UI/TouchControlLayoutScreen.h"
#include "UI/TouchControlVisibilityScreen.h"
#include "UI/TiltAnalogSettingsScreen.h"
#include "UI/TiltEventProcessor.h"
#include "Core/Config.h"
#include "Core/Host.h"
@ -233,11 +234,11 @@ void GameSettingsScreen::CreateViews() {
#if defined(USING_GLES2)
controlsSettings->Add(new CheckBox(&g_Config.bHapticFeedback, c->T("HapticFeedback", "Haptic Feedback (vibration)")));
static const char *tiltTypes[] = { "None (Disabled)", "Analog Stick", "D-PAD", "PSP Action Buttons"};
controlsSettings->Add(new PopupMultiChoice(&g_Config.iTiltInputType, c->T("Tilt Input Type"), tiltTypes, 0, ARRAY_SIZE(tiltTypes), c, screenManager()));
controlsSettings->Add(new PopupMultiChoice(&g_Config.iTiltInputType, c->T("Tilt Input Type"), tiltTypes, 0, ARRAY_SIZE(tiltTypes), c, screenManager()))->OnClick.Handle(this, &GameSettingsScreen::OnTiltTypeChange);
Choice *tiltAnalog = controlsSettings->Add(new Choice(c->T("Customize tilt")));
tiltAnalog->OnClick.Handle(this, &GameSettingsScreen::OnTiltAnalogSettings);
tiltAnalog->SetEnabledPtr((bool *)&g_Config.iTiltInputType); //<- dirty int-to-bool cast
Choice *customizeTilt = controlsSettings->Add(new Choice(c->T("Customize tilt")));
customizeTilt->OnClick.Handle(this, &GameSettingsScreen::OnTiltCuztomize);
customizeTilt->SetEnabledPtr((bool *)&g_Config.iTiltInputType); //<- dirty int-to-bool cast
#endif
controlsSettings->Add(new ItemHeader(c->T("OnScreen", "On-Screen Touch Controls")));
controlsSettings->Add(new CheckBox(&g_Config.bShowTouchControls, c->T("OnScreen", "On-Screen Touch Controls")));
@ -502,7 +503,14 @@ UI::EventReturn GameSettingsScreen::OnTouchControlLayout(UI::EventParams &e) {
return UI::EVENT_DONE;
};
UI::EventReturn GameSettingsScreen::OnTiltAnalogSettings(UI::EventParams &e){
//when the tilt event type is modified, we need to reset all tilt settings.
//refer to the ResetTiltEvents() function for a detailed explanation.
UI::EventReturn GameSettingsScreen::OnTiltTypeChange(UI::EventParams &e){
TiltEventProcessor::ResetTiltEvents();
return UI::EVENT_DONE;
};
UI::EventReturn GameSettingsScreen::OnTiltCuztomize(UI::EventParams &e){
screenManager()->push(new TiltAnalogSettingsScreen());
return UI::EVENT_DONE;
};

View file

@ -54,7 +54,8 @@ private:
UI::EventReturn OnTouchControlLayout(UI::EventParams &e);
UI::EventReturn OnDumpNextFrameToLog(UI::EventParams &e);
UI::EventReturn OnReloadCheats(UI::EventParams &e);
UI::EventReturn OnTiltAnalogSettings(UI::EventParams &e);
UI::EventReturn OnTiltTypeChange(UI::EventParams &e);
UI::EventReturn OnTiltCuztomize(UI::EventParams &e);
// Global settings handlers
UI::EventReturn OnLanguage(UI::EventParams &e);

View file

@ -13,9 +13,9 @@ inline float tiltInputCurve (float x, float deadzone, float sensitivity) {
const float factor = sensitivity * 1.0f / (1.0f - deadzone);
if (x > deadzone) {
return (x - deadzone) * factor;
return (x - deadzone) * factor * factor;
} else if (x < -deadzone) {
return (x + deadzone) * factor;
return (x + deadzone) * factor * factor;
} else {
return 0.0f;
}
@ -23,7 +23,10 @@ inline float tiltInputCurve (float x, float deadzone, float sensitivity) {
//dampen the tilt according to the given deadzone amount.
inline Tilt dampTilt(const Tilt &tilt, float deadzone, float xSensitivity, float ySensitivity) {
return Tilt(tiltInputCurve(tilt.x_, deadzone, xSensitivity), tiltInputCurve(tilt.y_, deadzone, ySensitivity));
//multiply sensitivity by 2 so that "overshoot" is possible. I personally prefer a
//sensitivity >1 for kingdom hearts and < 1 for Gods Eater. so yes, overshoot is nice
//to have.
return Tilt(tiltInputCurve(tilt.x_, deadzone, 2.0 * xSensitivity), tiltInputCurve(tilt.y_, deadzone, 2.0 * ySensitivity));
}
inline float clamp(float f) {
@ -65,10 +68,7 @@ Tilt TiltEventProcessor::GenTilt(const Tilt &baseTilt, const Tilt &currentTilt,
//next, normalize the tilt values
transformedTilt = NormalizeTilt(transformedTilt);
ILOG("\n->->->->->->->->->->->->->->->->->->->->->");
ILOG("Tilt X: %f; Y: %f", transformedTilt.y_, transformedTilt.x_);
//finally, dampen the tilt according to our curve.
return dampTilt(transformedTilt, deadzone, xSensitivity, ySensitivity);
};