From ae694bc0da98e45c5def20ac1d92f9d8aad65fd5 Mon Sep 17 00:00:00 2001 From: Kasullian Date: Wed, 10 Sep 2025 12:08:59 -0400 Subject: 3d view mouse control --- src/util/input.cpp | 9 +++++++++ src/util/input.h | 4 ++++ 2 files changed, 13 insertions(+) (limited to 'src/util') diff --git a/src/util/input.cpp b/src/util/input.cpp index 4a786aa..7e94c47 100644 --- a/src/util/input.cpp +++ b/src/util/input.cpp @@ -27,6 +27,8 @@ void input_on_event( SDL_Event* e ) { case SDL_MOUSEMOTION: { input.mouse.pos.x = (F32)e->motion.x; input.mouse.pos.y = (F32)e->motion.y; + input.mouse.pos_delta.x = (F32)e->motion.xrel; + input.mouse.pos_delta.y = (F32)e->motion.yrel; } break; case SDL_KEYDOWN: { input.keys[e->key.keysym.sym & 0xff] = 1; @@ -71,4 +73,11 @@ void input_on_mouse( I32 type, I32 x, I32 y ) { void input_frame_end() { input.mouse.wheel = 0; + input.mouse.pos_delta.x = 0; + input.mouse.pos_delta.y = 0; +} + +void input_capture_mouse( bool capture ) { + input.mouse_captured = capture; + SDL_SetRelativeMouseMode( capture ? SDL_TRUE : SDL_FALSE ); } diff --git a/src/util/input.h b/src/util/input.h index e174fe6..4885f0f 100644 --- a/src/util/input.h +++ b/src/util/input.h @@ -16,6 +16,7 @@ const U32 MOUSE_WHEEL = 0x4; struct MOUSE_DATA { VEC2 pos; + VEC2 pos_delta; U8 left; U8 right; U8 middle; @@ -27,6 +28,8 @@ using ON_INPUT_FN = std::function; struct INPUT_DATA { MOUSE_DATA mouse; U8 keys[0xff]; + bool mouse_captured; + F32 mouse_sensitivity = 1.0f; LIST on_input; }; @@ -37,5 +40,6 @@ extern void input_frame_end(); extern void input_on_event( SDL_Event* e ); extern void input_on_mouse( I32 type, I32 x, I32 y ); extern void input_is_key_down( U32 key ); +extern void input_capture_mouse( bool capture ); #define kb_down( key ) input_is_key_down( key ) -- cgit v1.2.3