//----------------------------------------------------------------------------- // Purpose: ApplyMouse -- applies mouse deltas to CUserCmd // Input : viewangles - // *cmd - // mouse_x - // mouse_y - //----------------------------------------------------------------------------- void CASWInput::ApplyMouse( int nSlot, QAngle& viewangles, CUserCmd *cmd, float mouse_x, float mouse_y ) { int current_posx, current_posy; GetMousePos(current_posx, current_posy); if ( ASWInput()->ControllerModeActive() ) return; if ( asw_controls.GetBool() && !MarineControllingTurret() ) { TurnTowardMouse( viewangles, cmd ); // Re-center the mouse. // force the mouse to the center, so there's room to move ResetMouse(); SetMousePos( current_posx, current_posy ); // asw - swarm wants it unmoved (have to reset to stop buttons locking) } else { if ( MarineControllingTurret() ) { // accelerate up the mouse intertia static float mouse_x_accumulated = 0; static float mouse_y_accumulated = 0; // decay it mouse_x_accumulated *= 0.95f; mouse_y_accumulated *= 0.95f; mouse_x_accumulated += mouse_x * 0.04f; mouse_y_accumulated += mouse_y * 0.04f; // clamp it mouse_x_accumulated = clamp(mouse_x_accumulated, -500.0f,500.0f); mouse_y_accumulated = clamp(mouse_y_accumulated, -500.0f,500.0f); // move with our inertia style mouse_x = mouse_x_accumulated; mouse_y = mouse_y_accumulated; } if ( ( !ASWGameRules() || ASWGameRules()->GetMarineDeathCamInterp() <= 0.0f ) && ( !C_ASW_Marine::GetLocalMarine() || !C_ASW_Marine::GetLocalMarine()->IsUsingComputerOrButtonPanel() ) ) CInput::ApplyMouse( nSlot, viewangles, cmd, mouse_x, mouse_y ); // force the mouse to the center, so there's room to move ResetMouse(); } }
//----------------------------------------------------------------------------- // Purpose: AccumulateMouse //----------------------------------------------------------------------------- void CInput::AccumulateMouse( void ) { if( !cl_mouseenable.GetBool() ) { return; } if( !cl_mouselook.GetBool() ) { return; } if ( m_rawinput.GetBool() ) { return; } int w, h; engine->GetScreenSize( w, h ); // x,y = screen center int x = w >> 1; x; int y = h >> 1; y; //only accumulate mouse if we are not moving the camera with the mouse if ( !m_fCameraInterceptingMouse && vgui::surface()->IsCursorLocked() ) { //Assert( !vgui::surface()->IsCursorVisible() ); // By design, we follow the old mouse path even when using SDL for Windows, to retain old mouse behavior. #if defined( PLATFORM_WINDOWS ) int current_posx, current_posy; GetMousePos(current_posx, current_posy); m_flAccumulatedMouseXMovement += current_posx - x; m_flAccumulatedMouseYMovement += current_posy - y; #elif defined( USE_SDL ) int dx, dy; engine->GetMouseDelta( dx, dy ); m_flAccumulatedMouseXMovement += dx; m_flAccumulatedMouseYMovement += dy; #else #error #endif // force the mouse to the center, so there's room to move ResetMouse(); } else if ( m_fMouseActive ) { // Clamp int ox, oy; GetMousePos( ox, oy ); ox = clamp( ox, 0, w - 1 ); oy = clamp( oy, 0, h - 1 ); SetMousePos( ox, oy ); } }
//----------------------------------------------------------------------------- // Purpose: Hides cursor and starts accumulation/re-centering //----------------------------------------------------------------------------- void CInput::ActivateMouse (void) { if ( m_fMouseActive ) return; if ( m_fMouseInitialized ) { if ( m_fMouseParmsValid ) { #if defined( PLATFORM_WINDOWS ) m_fRestoreSPI = SystemParametersInfo (SPI_SETMOUSE, 0, m_rgNewMouseParms, 0) ? true : false; #endif } m_fMouseActive = true; ResetMouse(); #if !defined( PLATFORM_WINDOWS ) int dx, dy; engine->GetMouseDelta( dx, dy, true ); #endif // Clear accumulated error, too m_flAccumulatedMouseXMovement = 0; m_flAccumulatedMouseYMovement = 0; // clear raw mouse accumulated data int rawX, rawY; inputsystem->GetRawMouseAccumulators(rawX, rawY); } }
//----------------------------------------------------------------------------- // Purpose: Hides cursor and starts accumulation/re-centering //----------------------------------------------------------------------------- void CInput::ActivateMouse (void) { if ( m_fMouseActive ) return; if ( m_fMouseInitialized ) { if ( m_fMouseParmsValid ) { #ifdef WIN32 m_fRestoreSPI = SystemParametersInfo (SPI_SETMOUSE, 0, m_rgNewMouseParms, 0) ? true : false; #endif } m_fMouseActive = true; ResetMouse(); g_pInputStackSystem->SetCursorIcon( m_hInputContext, INPUT_CURSOR_HANDLE_INVALID ); // Clear accumulated error, too for ( int hh = 0; hh < MAX_SPLITSCREEN_PLAYERS; ++hh ) { GetPerUser( hh ).m_flAccumulatedMouseXMovement = 0; GetPerUser( hh ).m_flAccumulatedMouseYMovement = 0; } } }
//----------------------------------------------------------------------------- // Purpose: AccumulateMouse //----------------------------------------------------------------------------- void CInput::AccumulateMouse( void ) { if( !cl_mouseenable.GetBool() ) { return; } if( !cl_mouselook.GetBool() ) { return; } int x, y; GetWindowCenter( x, y ); //only accumulate mouse if we are not moving the camera with the mouse if ( !m_fCameraInterceptingMouse && vgui::surface()->IsCursorLocked() ) { //Assert( !vgui::surface()->IsCursorVisible() ); int current_posx, current_posy; GetMousePos(current_posx, current_posy); m_flAccumulatedMouseXMovement += current_posx - x; m_flAccumulatedMouseYMovement += current_posy - y; // force the mouse to the center, so there's room to move ResetMouse(); } }
//----------------------------------------------------------------------------- // Purpose: Gives back the cursor and stops centering of mouse //----------------------------------------------------------------------------- void CInput::DeactivateMouse (void) { // This gets called whenever the mouse should be inactive. We only respond to it if we had // previously activated the mouse. We'll show the cursor in here. if ( !m_fMouseActive ) return; if ( m_fMouseInitialized ) { if ( m_fRestoreSPI ) { #if defined( PLATFORM_WINDOWS ) SystemParametersInfo( SPI_SETMOUSE, 0, m_rgOrigMouseParms, 0 ); #endif } m_fMouseActive = false; vgui::surface()->SetCursor( vgui::dc_arrow ); #if !defined( PLATFORM_WINDOWS ) // now put the mouse back in the middle of the screen ResetMouse(); #endif // Clear accumulated error, too m_flAccumulatedMouseXMovement = 0; m_flAccumulatedMouseYMovement = 0; } }
//----------------------------------------------------------------------------- // Purpose: AccumulateMouse //----------------------------------------------------------------------------- void CInput::AccumulateMouse( int nSlot ) { if( !cl_mouseenable.GetBool() ) { return; } if( !UsingMouselook( nSlot ) ) { return; } int w, h; engine->GetScreenSize( w, h ); // x,y = screen center int x = w >> 1; int y = h >> 1; // Clamp if ( m_fMouseActive ) { int ox, oy; GetMousePos( ox, oy ); ox = clamp( ox, 0, w - 1 ); oy = clamp( oy, 0, h - 1 ); SetMousePos( ox, oy ); } //only accumulate mouse if we are not moving the camera with the mouse PerUserInput_t &user = GetPerUser( nSlot ); if ( !user.m_fCameraInterceptingMouse && vgui::surface()->IsCursorLocked() ) { //Assert( !vgui::surface()->IsCursorVisible() ); #ifdef WIN32 int current_posx, current_posy; GetMousePos(current_posx, current_posy); user.m_flAccumulatedMouseXMovement += current_posx - x; user.m_flAccumulatedMouseYMovement += current_posy - y; // force the mouse to the center, so there's room to move ResetMouse(); #elif defined(OSX) CGMouseDelta deltaX, deltaY; CGGetLastMouseDelta( &deltaX, &deltaY ); user.m_flAccumulatedMouseXMovement += deltaX; user.m_flAccumulatedMouseYMovement += deltaY; #else #error #endif } }
//----------------------------------------------------------------------------- // Purpose: ApplyMouse -- applies mouse deltas to CUserCmd // Input : viewangles - // *cmd - // mouse_x - // mouse_y - //----------------------------------------------------------------------------- void CASWInput::ApplyMouse( int nSlot, QAngle& viewangles, CUserCmd *cmd, float mouse_x, float mouse_y ) { int current_posx, current_posy; GetMousePos(current_posx, current_posy); if ( ASWInput()->ControllerModeActive() ) return; //by price if (MarineDidPrice() || !asw_controls.GetBool()) { TurnTowardMouse( viewangles, cmd ); // force the mouse to the center, so there's room to move ResetMouse(); SetMousePos( current_posx, current_posy ); // asw - swarm wants it unmoved (have to reset to stop buttons locking) } CInput::ApplyMouse( nSlot, viewangles, cmd, mouse_x, mouse_y ); // force the mouse to the center, so there's room to move ResetMouse(); }
//----------------------------------------------------------------------------- // Purpose: AccumulateMouse //----------------------------------------------------------------------------- void CInput::AccumulateMouse( void ) { if( !cl_mouseenable.GetBool() ) { return; } if( !cl_mouselook.GetBool() ) { return; } int w, h; engine->GetScreenSize( w, h ); // x,y = screen center int x = w >> 1; int y = h >> 1; // Clamp if ( m_fMouseActive ) { int ox, oy; GetMousePos( ox, oy ); ox = clamp( ox, 0, w - 1 ); oy = clamp( oy, 0, h - 1 ); SetMousePos( ox, oy ); } //only accumulate mouse if we are not moving the camera with the mouse if ( !m_fCameraInterceptingMouse && vgui::surface()->IsCursorLocked() ) { //Assert( !vgui::surface()->IsCursorVisible() ); int current_posx, current_posy; GetMousePos(current_posx, current_posy); m_flAccumulatedMouseXMovement += current_posx - x; m_flAccumulatedMouseYMovement += current_posy - y; // force the mouse to the center, so there's room to move ResetMouse(); } }
//----------------------------------------------------------------------------- // Purpose: Hides cursor and starts accumulation/re-centering //----------------------------------------------------------------------------- void CInput::ActivateMouse (void) { if ( m_fMouseActive ) return; if ( m_fMouseInitialized ) { if ( m_fMouseParmsValid ) { m_fRestoreSPI = SystemParametersInfo (SPI_SETMOUSE, 0, m_rgNewMouseParms, 0) ? true : false; } m_fMouseActive = true; ResetMouse(); // Clear accumulated error, too m_flAccumulatedMouseXMovement = 0; m_flAccumulatedMouseYMovement = 0; } }
/* ============================== CAM_Think ============================== */ void CInput::CAM_Think( void ) { VPROF("CAM_Think"); // if ( m_pCameraThirdData ) { return CAM_CameraThirdThink(); } Vector idealAngles; Vector camOffset; float flSensitivity; QAngle viewangles; switch( cam_command.GetInt() ) { case CAM_COMMAND_TOTHIRDPERSON: CAM_ToThirdPerson(); break; case CAM_COMMAND_TOFIRSTPERSON: CAM_ToFirstPerson(); break; case CAM_COMMAND_NONE: default: break; } //All this code after this comment has to do with thirdperson g_ThirdPersonManager.Update(); if( !m_fCameraInThirdPerson ) return; // In Maya-mode if ( Is_CAM_ThirdPerson_MayaMode() ) { // Unless explicitly moving the camera, don't move it m_fCameraInterceptingMouse = m_fCameraMovingWithMouse = vgui::input()->IsKeyDown( KEY_LALT ) || vgui::input()->IsKeyDown( KEY_RALT ); if ( !m_fCameraMovingWithMouse ) return; // Zero-out camera-control kbutton_t structures memset( &cam_pitchup, 0, sizeof( cam_pitchup ) ); memset( &cam_pitchdown, 0, sizeof( cam_pitchdown ) ); memset( &cam_yawleft, 0, sizeof( cam_yawleft ) ); memset( &cam_yawright, 0, sizeof( cam_yawright ) ); memset( &cam_in, 0, sizeof( cam_in ) ); memset( &cam_out, 0, sizeof( cam_out ) ); // Unless left or right mouse button is down, don't do anything #ifndef _XBOX if ( /* Left+Middle Button Down */ vgui::input()->IsMouseDown( MOUSE_LEFT ) && vgui::input()->IsMouseDown( MOUSE_MIDDLE ) ) { // Do only zoom in/out camera adjustment m_fCameraDistanceMove = true; } else if ( /* Left Button Down */ vgui::input()->IsMouseDown( MOUSE_LEFT ) ) { // Do only rotational camera movement m_fCameraDistanceMove = false; } else if ( /* Right Button Down */ vgui::input()->IsMouseDown( MOUSE_RIGHT ) ) { // Do only zoom in/out camera adjustment m_fCameraDistanceMove = true; } else { // Neither left or right buttons down, don't do anything ResetMouse(); return; } #endif } idealAngles[ PITCH ] = cam_idealpitch.GetFloat(); idealAngles[ YAW ] = cam_idealyaw.GetFloat(); idealAngles[ DIST ] = cam_idealdist.GetFloat(); // //movement of the camera with the mouse // if ( m_fCameraMovingWithMouse ) { int cpx, cpy; #ifndef _XBOX //get windows cursor position GetMousePos (cpx, cpy); #else //xboxfixme cpx = cpy = 0; #endif m_nCameraX = cpx; m_nCameraY = cpy; //check for X delta values and adjust accordingly //eventually adjust YAW based on amount of movement //don't do any movement of the cam using YAW/PITCH if we are zooming in/out the camera if (!m_fCameraDistanceMove) { int x, y; GetWindowCenter( x, y ); //keep the camera within certain limits around the player (ie avoid certain bad viewing angles) if (m_nCameraX>x) { //if ((idealAngles[YAW]>=225.0)||(idealAngles[YAW]<135.0)) if (idealAngles[YAW]<c_maxyaw.GetFloat()) { idealAngles[ YAW ] += (CAM_ANGLE_MOVE)*((m_nCameraX-x)/2); } if (idealAngles[YAW]>c_maxyaw.GetFloat()) { idealAngles[YAW]=c_maxyaw.GetFloat(); } } else if (m_nCameraX<x) { //if ((idealAngles[YAW]<=135.0)||(idealAngles[YAW]>225.0)) if (idealAngles[YAW]>c_minyaw.GetFloat()) { idealAngles[ YAW ] -= (CAM_ANGLE_MOVE)* ((x-m_nCameraX)/2); } if (idealAngles[YAW]<c_minyaw.GetFloat()) { idealAngles[YAW]=c_minyaw.GetFloat(); } } //check for y delta values and adjust accordingly //eventually adjust PITCH based on amount of movement //also make sure camera is within bounds if (m_nCameraY > y) { if(idealAngles[PITCH]<c_maxpitch.GetFloat()) { idealAngles[PITCH] +=(CAM_ANGLE_MOVE)* ((m_nCameraY-y)/2); } if (idealAngles[PITCH]>c_maxpitch.GetFloat()) { idealAngles[PITCH]=c_maxpitch.GetFloat(); } } else if (m_nCameraY<y) { if (idealAngles[PITCH]>c_minpitch.GetFloat()) { idealAngles[PITCH] -= (CAM_ANGLE_MOVE)*((y-m_nCameraY)/2); } if (idealAngles[PITCH]<c_minpitch.GetFloat()) { idealAngles[PITCH]=c_minpitch.GetFloat(); } } //set old mouse coordinates to current mouse coordinates //since we are done with the mouse if ( ( flSensitivity = gHUD.GetSensitivity() ) != 0 ) { m_nCameraOldX=m_nCameraX*flSensitivity; m_nCameraOldY=m_nCameraY*flSensitivity; } else { m_nCameraOldX=m_nCameraX; m_nCameraOldY=m_nCameraY; } #ifndef _XBOX ResetMouse(); #endif } } //Nathan code here if( input->KeyState( &cam_pitchup ) ) idealAngles[ PITCH ] += cam_idealdelta.GetFloat(); else if( input->KeyState( &cam_pitchdown ) ) idealAngles[ PITCH ] -= cam_idealdelta.GetFloat(); if( input->KeyState( &cam_yawleft ) ) idealAngles[ YAW ] -= cam_idealdelta.GetFloat(); else if( input->KeyState( &cam_yawright ) ) idealAngles[ YAW ] += cam_idealdelta.GetFloat(); if( input->KeyState( &cam_in ) ) { idealAngles[ DIST ] -= 2*cam_idealdelta.GetFloat(); if( idealAngles[ DIST ] < CAM_MIN_DIST ) { // If we go back into first person, reset the angle idealAngles[ PITCH ] = 0; idealAngles[ YAW ] = 0; idealAngles[ DIST ] = CAM_MIN_DIST; } } else if( input->KeyState( &cam_out ) ) idealAngles[ DIST ] += 2*cam_idealdelta.GetFloat(); if (m_fCameraDistanceMove) { int x, y; GetWindowCenter( x, y ); if (m_nCameraY>y) { if(idealAngles[ DIST ]<c_maxdistance.GetFloat()) { idealAngles[ DIST ] +=cam_idealdelta.GetFloat() * ((m_nCameraY-y)/2); } if (idealAngles[ DIST ]>c_maxdistance.GetFloat()) { idealAngles[ DIST ]=c_maxdistance.GetFloat(); } } else if (m_nCameraY<y) { if (idealAngles[ DIST ]>c_mindistance.GetFloat()) { idealAngles[ DIST ] -= (cam_idealdelta.GetFloat())*((y-m_nCameraY)/2); } if (idealAngles[ DIST ]<c_mindistance.GetFloat()) { idealAngles[ DIST ]=c_mindistance.GetFloat(); } } //set old mouse coordinates to current mouse coordinates //since we are done with the mouse m_nCameraOldX=m_nCameraX*gHUD.GetSensitivity(); m_nCameraOldY=m_nCameraY*gHUD.GetSensitivity(); #ifndef _XBOX ResetMouse(); #endif } // Obtain engine view angles and if they popped while the camera was static, // fix the camera angles as well engine->GetViewAngles( viewangles ); static QAngle s_oldAngles = viewangles; if ( Is_CAM_ThirdPerson_MayaMode() && ( s_oldAngles != viewangles ) ) { idealAngles[ PITCH ] += s_oldAngles[ PITCH ] - viewangles[ PITCH ]; idealAngles[ YAW ] += s_oldAngles[ YAW ] - viewangles[ YAW ]; s_oldAngles = viewangles; } // bring the pitch values back into a range that MoveToward can handle if ( idealAngles[ PITCH ] > 180 ) idealAngles[ PITCH ] -= 360; else if ( idealAngles[ PITCH ] < -180 ) idealAngles[ PITCH ] += 360; // bring the yaw values back into a range that MoveToward can handle // -- // Vitaliy: going with >= 180 and <= -180. // This introduces a potential discontinuity when looking directly at model face // as camera yaw will be jumping from +180 to -180 and back, but when working with // the camera allows smooth rotational transitions from left to right and back. // Otherwise one of the transitions that has ">"-comparison will be locked. // -- if ( idealAngles[ YAW ] >= 180 ) idealAngles[ YAW ] -= 360; else if ( idealAngles[ YAW ] <= -180 ) idealAngles[ YAW ] += 360; // clamp pitch, yaw and dist... idealAngles[ PITCH ] = clamp( idealAngles[ PITCH ], c_minpitch.GetFloat(), c_maxpitch.GetFloat() ); idealAngles[ YAW ] = clamp( idealAngles[ YAW ], c_minyaw.GetFloat(), c_maxyaw.GetFloat() ); idealAngles[ DIST ] = clamp( idealAngles[ DIST ], c_mindistance.GetFloat(), c_maxdistance.GetFloat() ); // update ideal angles cam_idealpitch.SetValue( idealAngles[ PITCH ] ); cam_idealyaw.SetValue( idealAngles[ YAW ] ); cam_idealdist.SetValue( idealAngles[ DIST ] ); // Move the CameraOffset "towards" the idealAngles // Note: CameraOffset = viewangle + idealAngle VectorCopy( g_ThirdPersonManager.GetCameraOffsetAngles(), camOffset ); if( cam_snapto.GetInt() ) { camOffset[ YAW ] = cam_idealyaw.GetFloat() + viewangles[ YAW ]; camOffset[ PITCH ] = cam_idealpitch.GetFloat() + viewangles[ PITCH ]; camOffset[ DIST ] = cam_idealdist.GetFloat(); } else { float lag = MAX( 1, 1 + cam_ideallag.GetFloat() ); if( camOffset[ YAW ] - viewangles[ YAW ] != cam_idealyaw.GetFloat() ) camOffset[ YAW ] = MoveToward( camOffset[ YAW ], cam_idealyaw.GetFloat() + viewangles[ YAW ], lag ); if( camOffset[ PITCH ] - viewangles[ PITCH ] != cam_idealpitch.GetFloat() ) camOffset[ PITCH ] = MoveToward( camOffset[ PITCH ], cam_idealpitch.GetFloat() + viewangles[ PITCH ], lag ); if( abs( camOffset[ DIST ] - cam_idealdist.GetFloat() ) < 2.0 ) camOffset[ DIST ] = cam_idealdist.GetFloat(); else camOffset[ DIST ] += ( cam_idealdist.GetFloat() - camOffset[ DIST ] ) / lag; } // move the camera closer to the player if it hit something if ( cam_collision.GetInt() ) { QAngle desiredCamAngles = QAngle( camOffset[ PITCH ], camOffset[ YAW ], camOffset[ DIST ] ); if ( g_ThirdPersonManager.IsOverridingThirdPerson() == false ) { desiredCamAngles = viewangles; } g_ThirdPersonManager.PositionCamera( C_BasePlayer::GetLocalPlayer(), desiredCamAngles ); } if ( cam_showangles.GetInt() ) { engine->Con_NPrintf( 4, "Pitch: %6.1f Yaw: %6.1f %38s", viewangles[ PITCH ], viewangles[ YAW ], "view angles" ); engine->Con_NPrintf( 6, "Pitch: %6.1f Yaw: %6.1f Dist: %6.1f %19s", cam_idealpitch.GetFloat(), cam_idealyaw.GetFloat(), cam_idealdist.GetFloat(), "ideal angles" ); engine->Con_NPrintf( 8, "Pitch: %6.1f Yaw: %6.1f Dist: %6.1f %16s", g_ThirdPersonManager.GetCameraOffsetAngles()[ PITCH ], g_ThirdPersonManager.GetCameraOffsetAngles()[ YAW ], g_ThirdPersonManager.GetCameraOffsetAngles()[ DIST ], "camera offset" ); } //g_ThirdPersonManager.SetCameraOffsetAngles( camOffset ); g_ThirdPersonManager.SetCameraOffsetAngles(camOffset); }
void CInput::CreateMove ( int sequence_number, float input_sample_frametime, bool active ) { CUserCmd *cmd = &m_pCommands[ sequence_number % MULTIPLAYER_BACKUP ]; CVerifiedUserCmd *pVerified = &m_pVerifiedCommands[ sequence_number % MULTIPLAYER_BACKUP ]; cmd->Reset(); cmd->command_number = sequence_number; cmd->tick_count = gpGlobals->tickcount; QAngle viewangles; engine->GetViewAngles( viewangles ); QAngle originalViewangles = viewangles; if ( active || sv_noclipduringpause.GetInt() ) { // Determine view angles AdjustAngles ( input_sample_frametime ); // Determine sideways movement ComputeSideMove( cmd ); // Determine vertical movement ComputeUpwardMove( cmd ); // Determine forward movement ComputeForwardMove( cmd ); // Scale based on holding speed key or having too fast of a velocity based on client maximum // speed. ScaleMovements( cmd ); // Allow mice and other controllers to add their inputs ControllerMove( input_sample_frametime, cmd ); #ifdef SIXENSE g_pSixenseInput->SixenseFrame( input_sample_frametime, cmd ); if( g_pSixenseInput->IsEnabled() ) { g_pSixenseInput->SetView( input_sample_frametime, cmd ); } #endif } else { // need to run and reset mouse input so that there is no view pop when unpausing if ( !m_fCameraInterceptingMouse && m_fMouseActive ) { float mx, my; GetAccumulatedMouseDeltasAndResetAccumulators( &mx, &my ); ResetMouse(); } } // Retreive view angles from engine ( could have been set in IN_AdjustAngles above ) engine->GetViewAngles( viewangles ); // Latch and clear impulse cmd->impulse = in_impulse; in_impulse = 0; // Latch and clear weapon selection if ( m_hSelectedWeapon != NULL ) { C_BaseCombatWeapon *weapon = m_hSelectedWeapon; cmd->weaponselect = weapon->entindex(); cmd->weaponsubtype = weapon->GetSubType(); // Always clear weapon selection m_hSelectedWeapon = NULL; } // Set button and flag bits #ifdef SIXENSE if( g_pSixenseInput->IsEnabled() ) { // Some buttons were set in SixenseUpdateKeys, so or in any real keypresses cmd->buttons |= GetButtonBits( 1 ); } else { cmd->buttons = GetButtonBits( 1 ); } #else // Set button and flag bits cmd->buttons = GetButtonBits( 1 ); #endif // Using joystick? #ifdef SIXENSE if ( in_joystick.GetInt() || g_pSixenseInput->IsEnabled() ) #else if ( in_joystick.GetInt() ) #endif { if ( cmd->forwardmove > 0 ) { cmd->buttons |= IN_FORWARD; } else if ( cmd->forwardmove < 0 ) { cmd->buttons |= IN_BACK; } } // Use new view angles if alive, otherwise user last angles we stored off. if ( g_iAlive ) { VectorCopy( viewangles, cmd->viewangles ); VectorCopy( viewangles, m_angPreviousViewAngles ); } else { VectorCopy( m_angPreviousViewAngles, cmd->viewangles ); } // Let the move manager override anything it wants to. if ( g_pClientMode->CreateMove( input_sample_frametime, cmd ) ) { // Get current view angles after the client mode tweaks with it #ifdef SIXENSE // Only set the engine angles if sixense is not enabled. It is done in SixenseInput::SetView otherwise. if( !g_pSixenseInput->IsEnabled() ) { engine->SetViewAngles( cmd->viewangles ); } #else engine->SetViewAngles( cmd->viewangles ); #endif if ( UseVR() ) { C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if( pPlayer && !pPlayer->GetVehicle() ) { QAngle curViewangles, newViewangles; Vector curMotion, newMotion; engine->GetViewAngles( curViewangles ); curMotion.Init ( cmd->forwardmove, cmd->sidemove, cmd->upmove ); g_ClientVirtualReality.OverridePlayerMotion ( input_sample_frametime, originalViewangles, curViewangles, curMotion, &newViewangles, &newMotion ); engine->SetViewAngles( newViewangles ); cmd->forwardmove = newMotion[0]; cmd->sidemove = newMotion[1]; cmd->upmove = newMotion[2]; cmd->viewangles = newViewangles; } else { Vector vPos; g_ClientVirtualReality.GetTorsoRelativeAim( &vPos, &cmd->viewangles ); engine->SetViewAngles( cmd->viewangles ); } } } m_flLastForwardMove = cmd->forwardmove; cmd->random_seed = MD5_PseudoRandom( sequence_number ) & 0x7fffffff; HLTVCamera()->CreateMove( cmd ); #if defined( REPLAY_ENABLED ) ReplayCamera()->CreateMove( cmd ); #endif #if defined( HL2_CLIENT_DLL ) // copy backchannel data int i; for (i = 0; i < m_EntityGroundContact.Count(); i++) { cmd->entitygroundcontact.AddToTail( m_EntityGroundContact[i] ); } m_EntityGroundContact.RemoveAll(); #endif pVerified->m_cmd = *cmd; pVerified->m_crc = cmd->GetChecksum(); }
void CInput::CreateMove ( int sequence_number, float input_sample_frametime, bool active ) { CUserCmd *cmd = &m_pCommands[ sequence_number % MULTIPLAYER_BACKUP ]; CVerifiedUserCmd *pVerified = &m_pVerifiedCommands[ sequence_number % MULTIPLAYER_BACKUP ]; cmd->Reset(); cmd->command_number = sequence_number; cmd->tick_count = gpGlobals->tickcount; QAngle viewangles; if ( active || sv_noclipduringpause.GetInt() ) { // Determine view angles AdjustAngles ( input_sample_frametime ); // Determine sideways movement ComputeSideMove( cmd ); // Determine vertical movement ComputeUpwardMove( cmd ); // Determine forward movement ComputeForwardMove( cmd ); // Scale based on holding speed key or having too fast of a velocity based on client maximum // speed. ScaleMovements( cmd ); // Allow mice and other controllers to add their inputs ControllerMove( input_sample_frametime, cmd ); } else { // need to run and reset mouse input so that there is no view pop when unpausing if ( !m_fCameraInterceptingMouse && m_fMouseActive ) { float mx, my; GetAccumulatedMouseDeltasAndResetAccumulators( &mx, &my ); ResetMouse(); } } // Retreive view angles from engine ( could have been set in IN_AdjustAngles above ) engine->GetViewAngles( viewangles ); // Latch and clear impulse cmd->impulse = in_impulse; in_impulse = 0; // Latch and clear weapon selection if ( m_hSelectedWeapon != NULL ) { C_BaseCombatWeapon *weapon = m_hSelectedWeapon; cmd->weaponselect = weapon->entindex(); cmd->weaponsubtype = weapon->GetSubType(); // Always clear weapon selection m_hSelectedWeapon = NULL; } // Set button and flag bits cmd->buttons = GetButtonBits( 1 ); // Using joystick? if ( in_joystick.GetInt() ) { if ( cmd->forwardmove > 0 ) { cmd->buttons |= IN_FORWARD; } else if ( cmd->forwardmove < 0 ) { cmd->buttons |= IN_BACK; } } // Use new view angles if alive, otherwise user last angles we stored off. if ( g_iAlive ) { VectorCopy( viewangles, cmd->viewangles ); VectorCopy( viewangles, m_angPreviousViewAngles ); } else { VectorCopy( m_angPreviousViewAngles, cmd->viewangles ); } // Let the move manager override anything it wants to. if ( g_pClientMode->CreateMove( input_sample_frametime, cmd ) ) { // Get current view angles after the client mode tweaks with it engine->SetViewAngles( cmd->viewangles ); } m_flLastForwardMove = cmd->forwardmove; cmd->random_seed = MD5_PseudoRandom( sequence_number ) & 0x7fffffff; HLTVCamera()->CreateMove( cmd ); #if defined( HL2_CLIENT_DLL ) // copy backchannel data int i; for (i = 0; i < m_EntityGroundContact.Count(); i++) { cmd->entitygroundcontact.AddToTail( m_EntityGroundContact[i] ); } m_EntityGroundContact.RemoveAll(); #endif pVerified->m_cmd = *cmd; pVerified->m_crc = cmd->GetChecksum(); }
int SDLShell::Run(int argc, char *argv[]) { printf("*** %s, V%s ***\n", GetAppName(), GetAppVersion()); int done; Uint8 *keys; if (SDL_Init(SDL_INIT_VIDEO)) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 0; } ProcessCommandLine(argc, argv); if (!InitApp()) { Exit(EXIT_INIT_APP); } SDL_Surface *screen; if (Verbose(VerboseAll)) { printf("Setting width = %d, height = %d, bpp = %d\n", ShellGet(SDLShell::SHELL_WIDTH), ShellGet(SDLShell::SHELL_HEIGHT), ShellGet(SDLShell::SHELL_BPP)); } screen = SDL_SetVideoMode(ShellGet(SDLShell::SHELL_WIDTH), ShellGet(SDLShell::SHELL_HEIGHT), ShellGet(SDLShell::SHELL_BPP), Flags()); if (!screen) { fprintf(stderr, "Couldn't set %dx%d GL video mode: %s\n", ShellGet(SDLShell::SHELL_WIDTH), ShellGet(SDLShell::SHELL_HEIGHT), SDL_GetError()); Exit(EXIT_NO_SCREEN); } char tempString[100]; sprintf(tempString, "%s V%s", GetAppName(), GetAppVersion()); SDL_WM_SetCaption(tempString, GetAppName()); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, ShellGet(SHELL_VSYNC)); if (RequiresOpenGL2()) { // Initialize GLEW and make sure OpenGL 2.0 is supported GLenum err = glewInit(); if(GLEW_OK != err) { fprintf(stderr, "[ Fail ] - Error: %s\n", glewGetErrorString(err)); Exit(EXIT_NO_GL2_SUPPORT); } if(!GLEW_VERSION_2_0 && !(GLEW_ARB_shading_language_100 && GLEW_ARB_shader_objects && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)) { fprintf(stderr, "[ Fail ] - Shaders not supported\n"); Exit(EXIT_NO_GL2_SUPPORT); } if(!GLEW_ARB_vertex_buffer_object) { fprintf(stderr, "[ Fail ] - VBO objects are not supported\n"); Exit(EXIT_NO_GL2_SUPPORT); } } if (RequiresTTF()) { if (TTF_Init() == -1) { printf("Unable to initialize SDL_ttf: %s \n", TTF_GetError()); Exit(EXIT_NO_FONT); } } CreatePointer(); if (!InitGL()) { Exit(EXIT_INIT_GL); } done = 0; while (!done) { pPointer->Input(); ResetPressed(); ResetMouse(); SDL_Event event; while ( SDL_PollEvent(&event) ) { switch(event.type) { case SDL_VIDEORESIZE: if (ShellGet(SDLShell::SHELL_RESIZABLE)) { screen = SDL_SetVideoMode(event.resize.w, event.resize.h, ShellGet(SDLShell::SHELL_BPP), Flags()); if (screen) { Reshape(screen->w, screen->h); } else { /* Uh oh, we couldn't set the new video mode?? */; } } break; case SDL_MOUSEMOTION: pPointer->UpdateMouseMotion(event.motion); /*if (Verbose(VerboseAll)) { printf("Mouse moved by %d,%d to (%d,%d)\n", event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y); }*/ break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_WHEELDOWN) { scrollDown = true; } pPointer->UpdateMouseButton(event.button); /*if (Verbose(VerboseAll)) { printf("Mouse button %d pressed at (%d,%d)\n", event.button.button, event.button.x, event.button.y); }*/ break; case SDL_MOUSEBUTTONUP: if (event.button.button == SDL_BUTTON_WHEELUP) { scrollUp = true; } if (event.button.button == SDL_BUTTON_LEFT) { leftClick = true; } if (event.button.button == SDL_BUTTON_RIGHT) { rightClick = true; } pPointer->UpdateMouseButton(event.button); /*if (Verbose(VerboseAll)) { printf("Mouse button %d released at (%d,%d)\n", event.button.button, event.button.x, event.button.y); }*/ break; case SDL_KEYUP: SetPressed(event.key.keysym.scancode, false); SetPressing(event.key.keysym.scancode, false); break; case SDL_KEYDOWN: if (Verbose(VerboseInfo)) { printf("Pressed key %d\n", (int)event.key.keysym.scancode); } if (!KeyPressing(event.key.keysym.scancode)) { SetPressed(event.key.keysym.scancode, true); } SetPressing(event.key.keysym.scancode, true); break; case SDL_QUIT: done = 1; break; } } keys = SDL_GetKeyState(NULL); if (keys[SDLK_ESCAPE]) { done = 1; } if (!Render()) break; SDL_GL_SwapBuffers(); shellFrame++; } ReleaseGL(); ReleaseApp(); SDL_Quit(); return 0; /* ANSI C requires main to return int. */ }
/* InputReset: * Remet à zéro les périphériques d'entrée. */ void to7_InputReset(int mask, int value) { ResetKeyboard(mask, value); ResetMouse(); }
//----------------------------------------------------------------------------- // Purpose: MouseMove -- main entry point for applying mouse // Input : *cmd - //----------------------------------------------------------------------------- void CInput::MouseMove( CUserCmd *cmd ) { float mouse_x, mouse_y; float mx, my; QAngle viewangles; // Get view angles from engine engine->GetViewAngles( viewangles ); // Validate mouse speed/acceleration settings CheckMouseAcclerationVars(); // Don't drift pitch at all while mouselooking. view->StopPitchDrift (); //jjb - this disables normal mouse control if the user is trying to // move the camera, or if the mouse cursor is visible if ( !m_fCameraInterceptingMouse && !vgui::surface()->IsCursorVisible() ) { // Sample mouse one more time AccumulateMouse(); // Latch accumulated mouse movements and reset accumulators GetAccumulatedMouseDeltasAndResetAccumulators( &mx, &my ); // Filter, etc. the delta values and place into mouse_x and mouse_y GetMouseDelta( mx, my, &mouse_x, &mouse_y ); // Apply scaling factor ScaleMouse( &mouse_x, &mouse_y ); // Let the client mode at the mouse input before it's used g_pClientMode->OverrideMouseInput( &mouse_x, &mouse_y ); // Add mouse X/Y movement to cmd ApplyMouse( viewangles, cmd, mouse_x, mouse_y ); // Re-center the mouse. ResetMouse(); } #ifdef ARGG // adnan // only set the new viewangles if we're not supposed to override them if( !(g_pClientMode->OverrideViewAngles()) ) { #endif // Store out the new viewangles. engine->SetViewAngles( viewangles ); #ifdef ARGG } // end adnan #endif }
//----------------------------------------------------------------------------- // Purpose: MouseMove -- main entry point for applying mouse // Input : *cmd - //----------------------------------------------------------------------------- void CInput::MouseMove( int nSlot, CUserCmd *cmd ) { float mouse_x, mouse_y; float mx, my; QAngle viewangles; // Get view angles from engine engine->GetViewAngles( viewangles ); // Validate mouse speed/acceleration settings CheckMouseAcclerationVars(); // Don't drift pitch at all while mouselooking. view->StopPitchDrift (); //jjb - this disables normal mouse control if the user is trying to // move the camera, or if the mouse cursor is visible if ( !GetPerUser( nSlot ).m_fCameraInterceptingMouse && g_pInputStackSystem->IsTopmostEnabledContext( m_hInputContext ) ) { // Sample mouse one more time AccumulateMouse( nSlot ); // Latch accumulated mouse movements and reset accumulators GetAccumulatedMouseDeltasAndResetAccumulators( nSlot, &mx, &my ); // Filter, etc. the delta values and place into mouse_x and mouse_y GetMouseDelta( nSlot, mx, my, &mouse_x, &mouse_y ); // Apply scaling factor ScaleMouse( nSlot, &mouse_x, &mouse_y ); // Let the client mode at the mouse input before it's used GetClientMode()->OverrideMouseInput( &mouse_x, &mouse_y ); // Add mouse X/Y movement to cmd ApplyMouse( nSlot, viewangles, cmd, mouse_x, mouse_y ); // Re-center the mouse. ResetMouse(); } // Store out the new viewangles. engine->SetViewAngles( viewangles ); }
//----------------------------------------------------------------------------- // Purpose: MouseMove -- main entry point for applying mouse // Input : *cmd - //----------------------------------------------------------------------------- void CInput::MouseMove( CUserCmd *cmd ) { float mouse_x, mouse_y; float mx, my; QAngle viewangles; C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if (pPlayer && (pPlayer->GetFlags() & (FL_FREECAM | FL_REMOTECONTROLLED) || pPlayer->m_nButtons & IN_WALK)) { viewangles = m_aCameraViewAngles; m_bWasFreeCam = true; } else { if (m_bWasFreeCam) { viewangles = m_aCameraViewAngles; m_bWasFreeCam = false; } else engine->GetViewAngles(viewangles); } // Validate mouse speed/acceleration settings CheckMouseAcclerationVars(); // Don't drift pitch at all while mouselooking. view->StopPitchDrift (); //jjb - this disables normal mouse control if the user is trying to // move the camera, or if the mouse cursor is visible if ( !m_fCameraInterceptingMouse && !vgui::surface()->IsCursorVisible() ) { // Sample mouse one more time AccumulateMouse(); // Latch accumulated mouse movements and reset accumulators GetAccumulatedMouseDeltasAndResetAccumulators( &mx, &my ); // Filter, etc. the delta values and place into mouse_x and mouse_y GetMouseDelta( mx, my, &mouse_x, &mouse_y ); // Apply scaling factor ScaleMouse( &mouse_x, &mouse_y ); // Let the client mode at the mouse input before it's used g_pClientMode->OverrideMouseInput( &mouse_x, &mouse_y ); // Add mouse X/Y movement to cmd ApplyMouse( viewangles, cmd, mouse_x, mouse_y ); // Re-center the mouse. ResetMouse(); } m_aCameraViewAngles = viewangles; if (!(pPlayer->GetFlags() & (FL_FREECAM | FL_REMOTECONTROLLED) || pPlayer->m_nButtons & IN_WALK)) engine->SetViewAngles( viewangles ); }