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 From 0db9c91742a6ab17c3d8a8b86a34392c1797740b Mon Sep 17 00:00:00 2001 From: navewindre Date: Sun, 28 Sep 2025 02:45:10 +0200 Subject: input bettr --- src/game/player.cpp | 126 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 33 deletions(-) (limited to 'src/game/player.cpp') diff --git a/src/game/player.cpp b/src/game/player.cpp index 993292c..26c03af 100644 --- a/src/game/player.cpp +++ b/src/game/player.cpp @@ -2,6 +2,7 @@ #include "SDL_scancode.h" #include "objlist.h" #include "world/trace.h" +#include #include "player.h" F32 PLAYER_HULL_HEIGHT = 50.f; @@ -30,64 +31,123 @@ PLAYER* player_create( VEC3 origin, F32 yaw ) { return p; } -void player_input( GAME_DATA* game, PLAYER* p ) { - F32* yaw = &p->rot.y; - VEC3* pos = &p->pos; - +void capture_mouse( PLAYER* p ) { + F32* yaw = &p->input.cam.pos.y; + F32* pitch = &p->input.cam.pos.x; if( input.keys[SDL_SCANCODE_F1] ) { input_capture_mouse( false ); } 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; - } + *pitch -= input.mouse.pos_delta.y * input.mouse_sensitivity; - 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( *pitch > 89.f ) *pitch = 89.f; + if( *pitch < -89.f ) *pitch = -89.f; - 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; - } + input_reset_mouse_accumulator(); } *yaw = remainderf( *yaw, 360.f ); + p->rot.x = *pitch; + p->rot.y = *yaw; +} +void capture_move_keys( PLAYER* p ) { + VEC2* move = &p->input.move; + if( input.keys[input.binds.fwd] ) { + if( !p->input.fwd_held ) + move->x = 1.f; + p->input.fwd_held = true; + } else { + if( p->input.fwd_held ) { + if( p->input.bk_held ) + move->x = -1.f; + else + move->x = 0.f; + } + p->input.fwd_held = false; + } + + if( input.keys[input.binds.back] ) { + if( !p->input.bk_held ) + move->x = -1.f; + p->input.bk_held = true; + } else { + if( p->input.bk_held ) { + if( p->input.fwd_held ) + move->x = 1.f; + else + move->x = 0.f; + } + p->input.bk_held = false; + } - VEC3 wishmove; - VEC3 dir = m_radial_offset( *yaw, 70.f ); - if( input.keys[(U8)'w'] ) { - wishmove = dir * TICK_INTERVAL; + if( input.keys[input.binds.left] ) { + if( !p->input.left_held ) + move->y = -1.f; + p->input.left_held = true; + } else { + if( p->input.left_held ) { + if( p->input.right_held ) + move->y = 1.f; + else + move->y = 0.f; + } + p->input.left_held = false; } - if( input.keys[(U8)'s'] ) { - wishmove = dir * -TICK_INTERVAL; + + if( input.keys[input.binds.right] ) { + if( !p->input.right_held ) + move->y = 1.f; + p->input.right_held = true; + } else { + if( p->input.right_held ) { + if( p->input.left_held ) + move->y = -1.f; + else + move->y = 0.f; + } + p->input.right_held = false; } +} + +void player_input( GAME_DATA* game, PLAYER* p ) { + if( !p ) + return; + + capture_mouse( p ); + capture_move_keys( p ); +} + +void player_move( GAME_DATA* game, PLAYER* p ) { + VEC2 move = p->input.move; + F32 yawrad = m_deg2rad( p->rot.y ); + + VEC3 wishdir = { + move.x * cosf( yawrad ) - move.y * sinf( yawrad ), + move.y * cosf( yawrad ) + move.x * sinf( yawrad ), + 0 + }; + VEC3 vel = wishdir * 70.f; + p->velocity = vel; + VEC3 wishmove = vel * TICK_INTERVAL; // todo : should never be false if( vec_len( wishmove ) > BSP_TRACE_EPSILON && game->state.map->bsp ) { BSP_TRACE tr{}; AABB aabb{}; - tr.in_start = *pos; - tr.in_end = *pos + wishmove * 2.f; + tr.in_start = p->pos; + tr.in_end = tr.in_start + wishmove; aabb.min = p->mins; aabb.max = p->maxs; bsp_trace( &tr, game->state.map->bsp, aabb ); if( !tr.hit ) - *pos += wishmove; - else - *pos += wishmove * tr.frac; + p->pos += wishmove; + else { + p->pos += wishmove * tr.frac; + } } } -- cgit v1.2.3 From 8f978c8bc5b9ab17316cdc01caaee9b9d62d683e Mon Sep 17 00:00:00 2001 From: navewindre Date: Thu, 2 Oct 2025 06:26:57 +0200 Subject: fix2 --- src/game/player.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/game/player.cpp') diff --git a/src/game/player.cpp b/src/game/player.cpp index 26c03af..c4b9c9a 100644 --- a/src/game/player.cpp +++ b/src/game/player.cpp @@ -147,6 +147,15 @@ void player_move( GAME_DATA* game, PLAYER* p ) { p->pos += wishmove; else { p->pos += wishmove * tr.frac; + + + // TODO: clipvelocity fixes this, clips velocity to 1 wall (should do 4) + VEC3 left = wishmove * (1.f - tr.frac); + F32 into = vec_dot( left, tr.normal ); + if( into < 0.f ) + left -= tr.normal * into; + + p->pos += left; } } } -- cgit v1.2.3 From e3de3ba5162f7ddd5005911124d4333e140fd984 Mon Sep 17 00:00:00 2001 From: navewindre Date: Thu, 27 Nov 2025 17:19:02 +0100 Subject: bunch o stuff --- src/game/player.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/game/player.cpp') diff --git a/src/game/player.cpp b/src/game/player.cpp index c4b9c9a..51d1cf8 100644 --- a/src/game/player.cpp +++ b/src/game/player.cpp @@ -38,9 +38,9 @@ void capture_mouse( PLAYER* p ) { input_capture_mouse( false ); } - if( input.mouse_captured ) { - *yaw += input.mouse.pos_delta.x * input.mouse_sensitivity; - *pitch -= input.mouse.pos_delta.y * input.mouse_sensitivity; + if( input.mouselock ) { + *yaw += input.mouse.pos_delta.x * input.msens; + *pitch -= input.mouse.pos_delta.y * input.msens; if( *pitch > 89.f ) *pitch = 89.f; if( *pitch < -89.f ) *pitch = -89.f; -- cgit v1.2.3