Ejemplo n.º 1
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();
	}
}
void CameraController::Update(float pElapsedTime)
{
	float dt = pElapsedTime;
	GetCursorPos(&mCurrentMousePos);
	int dy = mCurrentMousePos.y - mPreviousMousePos.y;
	int dx = mCurrentMousePos.x - mPreviousMousePos.x;
	if (dy != 0)
	{
		Camera::GetInstance()->Tilt(-dy * 0.0087266f );
		float AngleAfter = AglVector3::dotProduct(Camera::GetInstance()->LocalYAxis(), AglVector3(0,1,0));
		if (AngleAfter < 0.0f)
		{
			Camera::GetInstance()->Tilt(dy * 0.0087266f );
		}

	}
	if (dx != 0)
		Camera::GetInstance()->ArbitraryRotatation(dx * 0.0087266f, AglVector3(0,1,0));

	AglVector3 prevCameraPos = Camera::GetInstance()->Position();
	if(GetAsyncKeyState('A') & 0x8000)	Camera::GetInstance()->MoveLeft(6*dt);
	if(GetAsyncKeyState('D') & 0x8000)	Camera::GetInstance()->MoveRight(6*dt);
	if(GetAsyncKeyState('W') & 0x8000)	Camera::GetInstance()->MoveForwards(6*dt);
	if(GetAsyncKeyState('S') & 0x8000)	Camera::GetInstance()->MoveBackwards(6*dt);

	mPreviousMousePos = GetWindowCenter();
	SetCursorPos(mPreviousMousePos.x, mPreviousMousePos.y);
}
CameraController::CameraController(HWND pWindowHandle)
{
    mWindowHandle = pWindowHandle;
    mPreviousMousePos = mCurrentMousePos = GetWindowCenter();
    SetCursorPos(mPreviousMousePos.x, mPreviousMousePos.y);
    mActive = false;
    mPivot = AglVector3(0, 0, 0);
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
// Purpose: Don't allow recentering the mouse
//-----------------------------------------------------------------------------
void CASWInput::ResetMouse( void )
{
	HACK_GETLOCALPLAYER_GUARD( "Mouse behavior is tied to a specific player's status - splitscreen player would depend on which player (if any) is using mouse control" );
	if ( MarineControllingTurret() || ( !asw_controls.GetBool() && ( !ASWGameRules() || ASWGameRules()->GetMarineDeathCamInterp() <= 0.0f ) && ( !C_ASW_Marine::GetLocalMarine() || !C_ASW_Marine::GetLocalMarine()->IsUsingComputerOrButtonPanel() ) ) )
	{
		int x, y;
		GetWindowCenter( x, y );
		SetMousePos( x, y );
	}
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
// Purpose: Don't allow recentering the mouse
//-----------------------------------------------------------------------------
void CASWInput::ResetMouse( void )
{
		int x, y;
 
	if (MarineDidPrice() || !asw_controls.GetBool())
	{		
		GetMousePos( x, y );	// asw instead of GetWindowCenter, so mouse doesn't move 
		SetMousePos( x, y );   //asw by price
	}
	else
	{
	GetWindowCenter( x,  y );
	SetMousePos( x, y );
	}
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *mx - 
//			*my - 
//			*unclampedx - 
//			*unclampedy - 
//-----------------------------------------------------------------------------
void CInput::GetFullscreenMousePos( int *mx, int *my, int *unclampedx /*=NULL*/, int *unclampedy /*=NULL*/ )
{
	Assert( mx );
	Assert( my );

	if ( !vgui::surface()->IsCursorVisible() )
	{
		return;
	}

	int x, y;
	GetWindowCenter( x,  y );

	int		current_posx, current_posy;

	GetMousePos(current_posx, current_posy);

	current_posx -= x;
	current_posy -= y;

	// Now need to add back in mid point of viewport
	//

	int w, h;
	vgui::surface()->GetScreenSize( w, h );
	current_posx += w  / 2;
	current_posy += h / 2;

	if ( unclampedx )
	{
		*unclampedx = current_posx;
	}

	if ( unclampedy )
	{
		*unclampedy = current_posy;
	}

	// Clamp
	current_posx = MAX( 0, current_posx );
	current_posx = MIN( ScreenWidth(), current_posx );

	current_posy = MAX( 0, current_posy );
	current_posy = MIN( ScreenHeight(), current_posy );

	*mx = current_posx;
	*my = current_posy;
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *mx - 
//			*my - 
//			*unclampedx - 
//			*unclampedy - 
//-----------------------------------------------------------------------------
void CInput::GetFullscreenMousePos( int *mx, int *my, int *unclampedx /*=NULL*/, int *unclampedy /*=NULL*/ )
{
	Assert( mx );
	Assert( my );

#if !(INFESTED_DLL)
	if ( g_pInputStackSystem->IsTopmostEnabledContext( m_hInputContext ) )
		return;
#endif

	int x, y;
	GetWindowCenter( x,  y );

	int		current_posx, current_posy;

	GetMousePos(current_posx, current_posy);

	current_posx -= x;
	current_posy -= y;

	// Now need to add back in mid point of viewport
	//

	int w, h;
	vgui::surface()->GetScreenSize( w, h );
	current_posx += w  / 2;
	current_posy += h / 2;

	if ( unclampedx )
	{
		*unclampedx = current_posx;
	}

	if ( unclampedy )
	{
		*unclampedy = current_posy;
	}

	// Clamp
	current_posx = MAX( 0, current_posx );
	current_posx = MIN( ScreenWidth(), current_posx );

	current_posy = MAX( 0, current_posy );
	current_posy = MIN( ScreenHeight(), current_posy );

	*mx = current_posx;
	*my = current_posy;
}
Ejemplo n.º 8
0
void CallAppRender( bool bInvalidRect )
{
	static DWORD lastTime = 0;
	static POINT lastMousePos = {0xFFFF, 0xFFFF};

	// Sample time and mouse position and tell the app to render.
	DWORD curTime = GetTickCount();
	float frametime = (curTime - lastTime) / 1000.0f;
	if( frametime > 0.1f )
		frametime = 0.1f;

	lastTime = curTime;

	// Get the cursor delta.
	POINT curMousePos;
	GetCursorPos(&curMousePos);

	int deltaX, deltaY;
	
	if( lastMousePos.x == 0xFFFF )
	{
		deltaX = deltaY = 0;
	}
	else
	{
		deltaX = curMousePos.x - lastMousePos.x;
		deltaY = curMousePos.y - lastMousePos.y;
	}

	// Recenter the cursor.
	if( g_nCapture )
	{
		lastMousePos = GetWindowCenter();
		SetCursorPos( lastMousePos.x, lastMousePos.y );
	}
	else
	{
		lastMousePos = curMousePos;
	}
	
	AppRender( frametime, (float)deltaX, (float)deltaY, bInvalidRect );
}
Ejemplo n.º 9
0
//-----------------------------------------------------------------------------
// Purpose: Recenter the mouse
//-----------------------------------------------------------------------------
void CInput::ResetMouse( void )
{
	int x, y;
	GetWindowCenter( x,  y );
	SetMousePos( x, y );	
}
Ejemplo n.º 10
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);
}
CameraController::CameraController(HWND pWindowHandle)
{
	mWindowHandle = pWindowHandle;
	mPreviousMousePos = mCurrentMousePos = GetWindowCenter();
	SetCursorPos(mPreviousMousePos.x, mPreviousMousePos.y);
}
void CameraController::Update(float pElapsedTime)
{
    float dt = pElapsedTime;
    float length = (Camera::GetInstance()->GetPosition()-mPivot).length();

    float factor = min(length / 2.25f, 1.0f);

    Camera::GetInstance()->MoveForwards((MOUSEWHEELDELTA)*dt*0.3f);
    if(GetAsyncKeyState(VK_MBUTTON) & 0x8000)
    {
        GetCursorPos(&mCurrentMousePos);
        int dy = mCurrentMousePos.y - mPreviousMousePos.y;
        int dx = mCurrentMousePos.x - mPreviousMousePos.x;

        if (mActive)
        {
            if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
            {
                Camera::GetInstance()->MoveRight(dx*dt);
                Camera::GetInstance()->MoveUp(-dy*dt);
            }
            else
            {
                AglVector3 target = Camera::GetInstance()->GetTarget();
                AglVector3 dir = Camera::GetInstance()->GetPosition() - target;
                dir.normalize();
                target = Camera::GetInstance()->GetPosition() - dir * length;

                if (dx != 0)
                {
                    AglQuaternion rot = AglQuaternion::constructFromAxisAndAngle(Camera::GetInstance()->LocalYAxis(), dt*dx);
                    rot.transformVector(dir);
                }
                if (dy != 0)
                {
                    AglQuaternion rot = AglQuaternion::constructFromAxisAndAngle(Camera::GetInstance()->LocalXAxis(), dt*dy);
                    rot.transformVector(dir);
                }
                dir.normalize();

                Camera::GetInstance()->Init(target + dir*length, target, Camera::GetInstance()->LocalYAxis(), 1280, 720);
            }
            mPivot = Camera::GetInstance()->GetTarget();
        }

        mPreviousMousePos = GetWindowCenter();
        SetCursorPos(mPreviousMousePos.x, mPreviousMousePos.y);
        mActive = true;
    }
    else if(GetAsyncKeyState(VK_RBUTTON) & 0x8000)
    {
        GetCursorPos(&mCurrentMousePos);
        int dy = mCurrentMousePos.y - mPreviousMousePos.y;
        int dx = mCurrentMousePos.x - mPreviousMousePos.x;

        if (mActive)
        {
            Camera::GetInstance()->Roll(dx * dt);
        }

        mPreviousMousePos = GetWindowCenter();
        SetCursorPos(mPreviousMousePos.x, mPreviousMousePos.y);
        mActive = true;
    }
    else
    {
        mActive = false;
    }

    if(GetAsyncKeyState(VK_SPACE) & 0x8000)
    {
        AglVector3 c = Scene::GetInstance()->GetCenter();
        Camera::GetInstance()->Init(c - AglVector3(0, 0.0f, 2.25f), c, AglVector3(0, 1, 0), 1280, 720);
        mPivot = c;
    }

    //ShowCursor(!mActive);
}