Example #1
0
void CBasePlayer::CalcObserverView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov )
{
#if defined( CLIENT_DLL )
	switch ( GetObserverMode() )
	{

		case OBS_MODE_DEATHCAM	:	CalcDeathCamView( eyeOrigin, eyeAngles, fov );
									break;

		case OBS_MODE_ROAMING	:	// just copy current position without view offset
		case OBS_MODE_FIXED		:	CalcRoamingView( eyeOrigin, eyeAngles, fov );
									break;

		case OBS_MODE_IN_EYE	:	CalcInEyeCamView( eyeOrigin, eyeAngles, fov );
									break;

		case OBS_MODE_CHASE		:	CalcChaseCamView( eyeOrigin, eyeAngles, fov  );
									break;

		case OBS_MODE_FREEZECAM	:	CalcFreezeCamView( eyeOrigin, eyeAngles, fov  );
									break;
	}
#else
	// on server just copy target postions, final view positions will be calculated on client
	VectorCopy( EyePosition(), eyeOrigin );
	VectorCopy( EyeAngles(), eyeAngles );
#endif
}
Example #2
0
void C_Camera::CalcView(Vector& eyeOrigin, QAngle& eyeAngles, float& fov)
{
	if (GetCamMode() == CAM_MODE_TVCAM)
	{
		CalcTVCamView(eyeOrigin, eyeAngles, fov);
		ResetAutoTransparentProps();
	}
	else if (GetCamMode() == CAM_MODE_FREE_CHASE || GetCamMode() == CAM_MODE_LOCKED_CHASE)
	{
		CalcChaseCamView(eyeOrigin, eyeAngles, fov);
		CheckAutoTransparentProps(eyeOrigin, eyeAngles);
	}
	else
	{
		CalcRoamingView(eyeOrigin, eyeAngles, fov);
		CheckAutoTransparentProps(eyeOrigin, eyeAngles);
	}

	// Save the last position and angle so when switching to roaming view it starts at the current position
	m_vCamOrigin = eyeOrigin;
	m_aCamAngle = eyeAngles;
}
Example #3
0
void C_HLTVCamera::CalcView(Vector& origin, QAngle& angles, float& fov)
{
	if ( m_bEntityPacketReceived )
	{
		// try to fixup movment pareents
		FixupMovmentParents();
		m_bEntityPacketReceived = false;
	}

	if ( m_iCameraMan > 0 )
	{
		C_BasePlayer *pCameraMan = UTIL_PlayerByIndex( m_iCameraMan );
		if ( pCameraMan )
		{
			float zNear,zFar;
			pCameraMan->CalcView( origin, angles, zNear, zFar, fov );
			pCameraMan->CalcViewModelView( origin, angles );
			return;
		}
	}

	switch ( m_nCameraMode )
	{
		case OBS_MODE_ROAMING	:	CalcRoamingView( origin, angles, fov );
									break;

		case OBS_MODE_FIXED		:	CalcFixedView( origin, angles, fov );
									break;

		case OBS_MODE_IN_EYE	:	CalcInEyeCamView( origin, angles, fov );
									break;

		case OBS_MODE_CHASE		:	CalcChaseCamView( origin, angles, fov  );
									break;
	}
}
Example #4
0
void C_Camera::CalcChaseCamView(Vector& eyeOrigin, QAngle& eyeAngles, float& fov)
{
	C_SDKPlayer *pLocal = C_SDKPlayer::GetLocalSDKPlayer();

	C_BaseEntity *pTarget = NULL;

	if ((pLocal->m_nButtons & IN_ZOOM)
		&& !pLocal->IsObserver()
		&& g_PR->GetTeamPosType(GetLocalPlayerIndex()) == POS_GK
		&& GetMatchBall()
		&& Sign(GetMatchBall()->GetLocalOrigin().y - SDKGameRules()->m_vKickOff.GetY()) == pLocal->GetTeam()->m_nForward)
	{
		CalcHawkEyeView(eyeOrigin, eyeAngles, fov);
		return;
	}

	if (pLocal->IsObserver())
		pTarget = GetTarget();
	else
		pTarget = pLocal;

	if (!pTarget || !pTarget->GetBaseAnimating() && !pTarget->GetModel())
	{
		CalcRoamingView( eyeOrigin, eyeAngles, fov );
		return;
	}

	eyeOrigin = pTarget->EyePosition();
	eyeAngles = pTarget->EyeAngles();

	const QAngle camAngles = ::input->GetCameraAngles();
	Vector &camOffset = ::input->GetCameraOffset();

	float dist = cl_cam_firstperson.GetBool() ? -10 : cl_cam_dist.GetFloat();
	float height = cl_cam_firstperson.GetBool() ? 8 : cl_cam_height.GetFloat();

	if (pLocal->IsObserver() && GetCamMode() == CAM_MODE_LOCKED_CHASE && !dynamic_cast<C_MatchBall *>(pTarget))
	{
		camOffset[PITCH] = eyeAngles[PITCH];
		camOffset[YAW] = eyeAngles[YAW];
	}
	else
	{
		camOffset[PITCH] = camAngles[PITCH];
		camOffset[YAW] = camAngles[YAW];
	}

	if (camOffset[PITCH] >= 0)
	{
		camOffset[ROLL] = dist;
	}
	else
	{
		float coeff = clamp(cos(DEG2RAD(camOffset[PITCH] + 90)), 0.001f, 1.0f);
		camOffset[ROLL] = min((VEC_VIEW.z + height - 5) / coeff, dist);
	}

	eyeAngles[PITCH] = camOffset[PITCH];
	eyeAngles[YAW] = camOffset[YAW];
	eyeAngles[ROLL] = 0;

	Vector camForward, camRight, camUp;
	AngleVectors(eyeAngles, &camForward, &camRight, &camUp);

	VectorMA(eyeOrigin, -camOffset[ROLL], camForward, eyeOrigin);

	eyeOrigin.z += height;

	if (!pLocal->IsObserver())
	{
		// Apply a smoothing offset to smooth out prediction errors.
		Vector vSmoothOffset;
		pLocal->GetPredictionErrorSmoothingVector( vSmoothOffset );
		eyeOrigin += Vector(vSmoothOffset.x, vSmoothOffset.y, 0);
	}
	
	fov = pLocal->GetFOV();
}
Example #5
0
void C_CFPlayer::CalcChaseCamView(Vector& eyeOrigin, QAngle& eyeAngles, float& fov)
{
	C_CFPlayer *pTarget = ToCFPlayer(GetObserverTarget());

	if ( !pTarget ) 
	{
		// just copy a save in-map position
		VectorCopy( EyePosition(), eyeOrigin );
		VectorCopy( EyeAngles(), eyeAngles );
		return;
	};

	// If our target isn't visible, we're at a camera point of some kind.
	// Instead of letting the player rotate around an invisible point, treat
	// the point as a fixed camera.
	if ( !pTarget->GetBaseAnimating() && !pTarget->GetModel() )
	{
		CalcRoamingView( eyeOrigin, eyeAngles, fov );
		return;
	}

	// The following code was ripped from CCFInput::CAM_ThirdPersonNormalThink.
	// Should probably delete it and move that code to C_CFPlayer so that it can be used here too.

	eyeAngles = pTarget->EyeAngles();

	Vector vecEngineForward, vecEngineRight, vecEngineUp;
	AngleVectors(eyeAngles, &vecEngineForward, &vecEngineRight, &vecEngineUp);

	Vector vecEngineForward2D;
	AngleVectors(QAngle(0, eyeAngles[YAW], 0), &vecEngineForward2D);

	// Don't use EyePosition() because that changes depending on the animation.
	Vector vecCameraCenter = pTarget->GetAbsOrigin() + VEC_VIEW;

	m_bThirdPositionMelee = true;
	if (pTarget->GetPrimaryWeapon() && !pTarget->GetPrimaryWeapon()->IsMeleeWeapon())
		m_bThirdPositionMelee = false;
	if (pTarget->GetSecondaryWeapon() && !pTarget->GetSecondaryWeapon()->IsMeleeWeapon())
		m_bThirdPositionMelee = false;

	Vector vecRearRightPosition = vecCameraCenter + vecEngineRight * cvar->FindVar("cam_right")->GetFloat() - vecEngineForward * cvar->FindVar("cam_back")->GetFloat();
	Vector vecRearMeleePosition = vecCameraCenter + vecEngineRight * cvar->FindVar("cam_right_melee")->GetFloat() - vecEngineForward * cvar->FindVar("cam_back_melee")->GetFloat();

	m_flThirdPositionMeleeWeight = Approach(m_bThirdPositionMelee?0:1, m_flThirdPositionMeleeWeight, gpGlobals->frametime * (1/cvar->FindVar("cam_switchtime")->GetFloat()));

	float flWeight = Gain(m_flThirdPositionMeleeWeight, 0.8f);

	eyeOrigin = vecRearMeleePosition * (1-flWeight) + vecRearRightPosition * flWeight;

	if ( pTarget )
	{
		trace_t trace;

		// Trace back to see if the camera is in a wall.
		CTraceFilterNoNPCsOrPlayer traceFilter( pTarget, COLLISION_GROUP_NONE );
		UTIL_TraceHull( vecCameraCenter, eyeOrigin,
			Vector(-9,-9,-9), Vector(9,9,9),
			MASK_SOLID, &traceFilter, &trace );

		if( trace.fraction < 1.0 )
			eyeOrigin = trace.endpos;
	}

	fov = GetFOV();
}