From 328116927487124cf84a1ff6177ba4317c90a90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?= Date: Mon, 7 Oct 2013 18:25:27 +0000 Subject: [PATCH] Input : Fixed mouse speed calculation in sdl & android. --- src/easymesh/easymesh.cpp | 18 +++++++++--------- src/platform/android/androidapp.cpp | 8 +++++--- src/platform/sdl/sdlinput.cpp | 6 ++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/easymesh/easymesh.cpp b/src/easymesh/easymesh.cpp index 68d6acb7..c0748424 100644 --- a/src/easymesh/easymesh.cpp +++ b/src/easymesh/easymesh.cpp @@ -139,7 +139,7 @@ void DefaultShaderData::SetupDefaultData(bool with_UV) { UNUSED(with_UV); for (int i = 0; i < 7; i++) - AddUniform(DefaultUniforms[i].C()); + AddUniform(DefaultUniforms[i]); } //----------------------------------------------------------------------------- @@ -163,14 +163,14 @@ void DefaultShaderData::SetupShaderDatas(mat4 const &model) light_data << vec4::zero << vec4::zero; int i = 0; - m_shader->SetUniform(*GetUniform(DefaultUniforms[i++].C()), light_data); - - m_shader->SetUniform(*GetUniform(DefaultUniforms[i++].C()), modelview); - m_shader->SetUniform(*GetUniform(DefaultUniforms[i++].C()), view); - m_shader->SetUniform(*GetUniform(DefaultUniforms[i++].C()), inverse(view)); - m_shader->SetUniform(*GetUniform(DefaultUniforms[i++].C()), proj); - m_shader->SetUniform(*GetUniform(DefaultUniforms[i++].C()), normalmat); - m_shader->SetUniform(*GetUniform(DefaultUniforms[i++].C()), f); + m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), light_data); + + m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), modelview); + m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), view); + m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), inverse(view)); + m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), proj); + m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), normalmat); + m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), f); } //----------------------------------------------------------------------------- diff --git a/src/platform/android/androidapp.cpp b/src/platform/android/androidapp.cpp index c80e8f86..fb56a266 100644 --- a/src/platform/android/androidapp.cpp +++ b/src/platform/android/androidapp.cpp @@ -210,6 +210,8 @@ int32_t lol::AndroidAppData::HandleInput(AInputEvent* event) switch (AInputEvent_getType(event)) { case AINPUT_EVENT_TYPE_MOTION: + //We need the max if we want coherent mouse speed between axis + float max_screen_size = lol::max(m_wanted_resolution.x, m_wanted_resolution.y); /* FIXME: we flip the Y axis here, but is it the right place? */ ivec2 pos(AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0)); @@ -217,9 +219,9 @@ int32_t lol::AndroidAppData::HandleInput(AInputEvent* event) pos.y = m_wanted_resolution.y - 1 - pos.y; m_mouse->SetCursor(0, vec2(pos) / vec2(m_wanted_resolution), pos); // Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick - m_mouse->SetAxis(0, (pos.x - m_prev_pos.x) / m_wanted_resolution.x * 100.f); - // Y Axis is also negated to match the usual joystick Y axis (negatives values are for the upper direction) - m_mouse->SetAxis(1, (pos.y - m_prev_pos.y) / m_wanted_resolution.y * -100.f); + m_mouse->SetAxis(0, (pos.x - m_prev_pos.x) / max_screen_size * 100.f); + // Unlike SDL, no need to negate Y axis + m_mouse->SetAxis(1, (pos.y - m_prev_pos.y) / max_screen_size * -100.f); m_prev_pos = pos; switch (AKeyEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK) { diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index 969c5609..79c149a4 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -220,13 +220,15 @@ void SdlInputData::Tick(float seconds) if (mouse.x >= 0 && mouse.x < m_app.x && mouse.y >= 0 && mouse.y < m_app.y) { + //We need the max if we want coherent mouse speed between axis + float max_screen_size = lol::max(m_screen.x, m_screen.y); vec2 vmouse = vec2(mouse); vec2 vprevmouse = vec2(m_prevmouse); m_mouse->SetCursor(0, vmouse / m_app, mouse); // Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick - m_mouse->SetAxis(0, (mouse.x - vprevmouse.x) * 100.0f / m_screen.x); + m_mouse->SetAxis(0, (mouse.x - vprevmouse.x) * 100.0f / max_screen_size); // Y Axis is also negated to match the usual joystick Y axis (negatives values are for the upper direction) - m_mouse->SetAxis(1,-(mouse.y - vprevmouse.y) * 100.0f / m_screen.y); + m_mouse->SetAxis(1,-(mouse.y - vprevmouse.y) * 100.0f / max_screen_size); } if (m_mousecapture)