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/game/player.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/game/player.cpp') diff --git a/src/game/player.cpp b/src/game/player.cpp index 87786df..993292c 100644 --- a/src/game/player.cpp +++ b/src/game/player.cpp @@ -34,18 +34,32 @@ void player_input( GAME_DATA* game, PLAYER* p ) { F32* yaw = &p->rot.y; VEC3* pos = &p->pos; - if( input.keys[(U8)'a'] ) - *yaw -= 360.f * TICK_INTERVAL * 0.5f; - if( input.keys[(U8)'d'] ) - *yaw += 360.f * TICK_INTERVAL * 0.5f; - - if( input.keys[SDL_SCANCODE_UP] ) { - if( p->rot.x < 89.f ) - p->rot.x += 360.f * TICK_INTERVAL * 0.5f; + if( input.keys[SDL_SCANCODE_F1] ) { + input_capture_mouse( false ); } - if( input.keys[SDL_SCANCODE_DOWN] ) { - if( p->rot.x > -89.f ) - p->rot.x -= 360.f * TICK_INTERVAL * 0.5f; + + if( input.mouse_captured ) { + *yaw += input.mouse.pos_delta.x * input.mouse_sensitivity; + p->rot.x -= input.mouse.pos_delta.y * input.mouse_sensitivity; + + if( p->rot.x > 89.f ) p->rot.x = 89.f; + if( p->rot.x < -89.f ) p->rot.x = -89.f; + } + + if( !input.mouse_captured ) { + if( input.keys[(U8)'a'] ) + *yaw -= 360.f * TICK_INTERVAL * 0.5f; + if( input.keys[(U8)'d'] ) + *yaw += 360.f * TICK_INTERVAL * 0.5f; + + if( input.keys[SDL_SCANCODE_UP] ) { + if( p->rot.x < 89.f ) + p->rot.x += 360.f * TICK_INTERVAL * 0.5f; + } + if( input.keys[SDL_SCANCODE_DOWN] ) { + if( p->rot.x > -89.f ) + p->rot.x -= 360.f * TICK_INTERVAL * 0.5f; + } } *yaw = remainderf( *yaw, 360.f ); -- cgit v1.2.3