Przeglądaj źródła

Mouse support now works in emscripten

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 lat temu
rodzic
commit
1cd715e6ef
2 zmienionych plików z 18 dodań i 9 usunięć
  1. +14
    -5
      src/platform/sdl/sdlinput.cpp
  2. +4
    -4
      test/meshviewer.cpp

+ 14
- 5
src/platform/sdl/sdlinput.cpp Wyświetl plik

@@ -28,6 +28,11 @@
/* We force joystick polling because no events are received when
* there is no SDL display (eg. on the Raspberry Pi). */
#define SDL_FORCE_POLL_JOYSTICK 1
#if EMSCRIPTEN
#define MOUSE_SPEED_MOD 10.f
#else
#define MOUSE_SPEED_MOD 100.f
#endif

namespace lol
{
@@ -80,6 +85,9 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)

SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK);

m_data->m_keyboard = InputDeviceInternal::CreateStandardKeyboard();
m_data->m_mouse = InputDeviceInternal::CreateStandardMouse();

# if !EMSCRIPTEN
# if SDL_FORCE_POLL_JOYSTICK
SDL_JoystickEventState(SDL_QUERY);
@@ -87,9 +95,6 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)
SDL_JoystickEventState(SDL_ENABLE);
# endif //SDL_FORCE_POLL_JOYSTICK

m_data->m_keyboard = InputDeviceInternal::CreateStandardKeyboard();
m_data->m_mouse = InputDeviceInternal::CreateStandardMouse();

/* Register all the joysticks we can find, and let the input
* system decide what it wants to track. */
for (int i = 0; i < SDL_NumJoysticks(); i++)
@@ -228,14 +233,18 @@ void SdlInputData::Tick(float seconds)
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 / max_screen_size);
m_mouse->SetAxis(0, (mouse.x - vprevmouse.x) * MOUSE_SPEED_MOD / 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 / max_screen_size);
m_mouse->SetAxis(1,-(mouse.y - vprevmouse.y) * MOUSE_SPEED_MOD / max_screen_size);
}

//Mouse is focused, Validate the InScreen Key
//Hardcoded 3, not very nice.
# if !EMSCRIPTEN
m_mouse->SetKey(3, !!(SDL_GetAppState() & SDL_APPMOUSEFOCUS));
#else //Emscripten doesn't seem to handle SDL_APPMOUSEFOCUS
m_mouse->SetKey(3, true);
#endif

if (m_mousecapture)
{


+ 4
- 4
test/meshviewer.cpp Wyświetl plik

@@ -26,12 +26,12 @@ static int const TEXTURE_WIDTH = 256;

#define NO_NACL_EM (!__native_client__ && !EMSCRIPTEN)
#define NACL_EM (__native_client__ || EMSCRIPTEN)
#define NO_NACL_EM_INPUT (1 && !EMSCRIPTEN)
#define NO_NACL_EM_INPUT (1)

#define R_M 1.f
#if NACL_EM
#define DEFAULT_WIDTH (770.f * R_M)
#define DEFAULT_HEIGHT (200.f * R_M)
#define DEFAULT_WIDTH (800.f * R_M)
#define DEFAULT_HEIGHT (400.f * R_M)
#else
#define DEFAULT_WIDTH (1200.f * R_M)
#define DEFAULT_HEIGHT (400.f * R_M)
@@ -180,7 +180,7 @@ public:
m_zoom = -100.f;
m_zoom_mesh = 0.f;
m_zoom_speed = 0.f;
m_rot = vec2(45.f);
m_rot = vec2(45.f, -45.f);
m_rot_mesh = vec2::zero;
m_rot_speed = vec2::zero;
m_pos = vec2::zero;


Ładowanie…
Anuluj
Zapisz