mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: client: add gyroscope aiming support
refactor: standardize input functions to use (pitch, yaw) parameter order
This commit is contained in:
committed by
a1batross
parent
dbcf77c9a9
commit
f7e933aea1
@@ -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" ))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user