From f7e933aea1746275b625a69d8f245ff2e948451b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A1=D1=83=D1=85=D0=BE=D0=B2?= <22411953+Vladislav4KZ@users.noreply.github.com> Date: Tue, 7 Apr 2026 15:53:41 +0000 Subject: [PATCH] engine: client: add gyroscope aiming support refactor: standardize input functions to use (pitch, yaw) parameter order --- engine/client/in_joy.c | 27 ++++++++++++++++++++++++--- engine/client/in_touch.c | 4 ++-- engine/client/input.c | 4 ++-- engine/client/input.h | 4 ++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/engine/client/in_joy.c b/engine/client/in_joy.c index e76aff4d..ff098293 100644 --- a/engine/client/in_joy.c +++ b/engine/client/in_joy.c @@ -62,6 +62,12 @@ static CVAR_DEFINE_AUTO( joy_axis_binding, "sfpyrl", FCVAR_ARCHIVE | FCVAR_FILTE CVAR_DEFINE_AUTO( joy_enable, "1", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "enable joystick" ); static CVAR_DEFINE_AUTO( joy_have_gyro, "0", FCVAR_READ_ONLY, "tells whether current active gamepad has gyroscope or not" ); static CVAR_DEFINE_AUTO( joy_calibrated, "0", FCVAR_READ_ONLY, "tells whether current active gamepad gyroscope has been calibrated or not" ); +static CVAR_DEFINE_AUTO( joy_gyro_pitch, "1.0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "gyroscope sensitivity for looking up and down" ); +static CVAR_DEFINE_AUTO( joy_gyro_yaw, "1.0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "gyroscope sensitivity for turning left and right" ); +static CVAR_DEFINE_AUTO( joy_gyro_roll, "0.0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "gyroscope sensitivity when tilting the device sideways" ); + +// stores the latest instantaneous gyroscope rotation rates (in rad/s) from platform input +static vec3_t joy_gyro_speed; /* ============ @@ -278,7 +284,7 @@ Gyroscope events */ void Joy_GyroEvent( vec3_t data ) { - + VectorCopy( data, joy_gyro_speed ); } /* @@ -317,8 +323,19 @@ void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw ) *fw -= joy_forward.value * (float)joyaxis[JOY_AXIS_FWD ].val/(float)SHRT_MAX; // must be form -1.0 to 1.0 *side += joy_side.value * (float)joyaxis[JOY_AXIS_SIDE].val/(float)SHRT_MAX; - *dpitch -= joy_pitch.value * (float)joyaxis[JOY_AXIS_PITCH].val/(float)SHRT_MAX * host.realframetime; - *dyaw += joy_yaw.value * (float)joyaxis[JOY_AXIS_YAW ].val/(float)SHRT_MAX * host.realframetime; + *dpitch += joy_pitch.value * (float)joyaxis[JOY_AXIS_PITCH].val/(float)SHRT_MAX * host.realframetime; + *dyaw -= joy_yaw.value * (float)joyaxis[JOY_AXIS_YAW ].val/(float)SHRT_MAX * host.realframetime; + + if( joy_have_gyro.value ) + { + float pitch_speed = joy_gyro_speed[0] * ( 180.0f / M_PI ); + float yaw_speed = joy_gyro_speed[1] * ( 180.0f / M_PI ); + float roll_speed = joy_gyro_speed[2] * ( 180.0f / M_PI ); + + *dpitch -= joy_gyro_pitch.value * pitch_speed * host.realframetime; + *dyaw += joy_gyro_yaw.value * yaw_speed * host.realframetime; + *dyaw += joy_gyro_roll.value * roll_speed * host.realframetime; + } } static void Joy_CalibrateGyro_f( void ) @@ -367,6 +384,10 @@ void Joy_Init( void ) Cvar_RegisterVariable( &joy_calibrated ); Cvar_RegisterVariable( &joy_enable ); + Cvar_RegisterVariable( &joy_gyro_pitch ); + Cvar_RegisterVariable( &joy_gyro_yaw ); + Cvar_RegisterVariable( &joy_gyro_roll ); + // renamed from -nojoy to -noenginejoy to not conflict with // client.dll's joystick support if( Sys_CheckParm( "-noenginejoy" )) diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index 1dd584c4..bf9c2214 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -2189,12 +2189,12 @@ int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx return Touch_ControlsEvent( type, fingerID, x, y, dx, dy ); } -void Touch_GetMove( float *forward, float *side, float *yaw, float *pitch ) +void Touch_GetMove( float *forward, float *side, float *pitch, float *yaw ) { *forward += touch.forward; *side += touch.side; - *yaw += touch.yaw; *pitch += touch.pitch; + *yaw += touch.yaw; touch.yaw = touch.pitch = 0; } diff --git a/engine/client/input.c b/engine/client/input.c index 9eff8d7a..3f5d30ec 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -560,8 +560,8 @@ static void IN_CollectInput( float *forward, float *side, float *pitch, float *y #endif } - Joy_FinalizeMove( forward, side, yaw, pitch ); - Touch_GetMove( forward, side, yaw, pitch ); + Joy_FinalizeMove( forward, side, pitch, yaw ); + Touch_GetMove( forward, side, pitch, yaw ); if( look_filter.value ) { diff --git a/engine/client/input.h b/engine/client/input.h index 4cf83b4c..93d83081 100644 --- a/engine/client/input.h +++ b/engine/client/input.h @@ -71,7 +71,7 @@ static inline void Touch_AddDefaultButton( const char *name, const char *texture static inline void Touch_WriteConfig( void ) { } static inline void Touch_Init( void ) { } static inline void Touch_Shutdown( void ) { } -static inline void Touch_GetMove( float * forward, float *side, float *yaw, float *pitch ) { } +static inline void Touch_GetMove( float * forward, float *side, float *pitch, float *yaw ) { } static inline void Touch_ResetDefaultButtons( void ) { } static inline int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy ) { return 0; } static inline void Touch_KeyEvent( int key, int down ) { } @@ -87,7 +87,7 @@ void Touch_AddDefaultButton( const char *name, const char *texturefile, const ch void Touch_WriteConfig( void ); void Touch_Init( void ); void Touch_Shutdown( void ); -void Touch_GetMove( float * forward, float *side, float *yaw, float *pitch ); +void Touch_GetMove( float * forward, float *side, float *pitch, float *yaw ); void Touch_ResetDefaultButtons( void ); int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy ); void Touch_KeyEvent( int key, int down );