vsVector2D
vsLayer::GetCorner(bool bottom, bool right)
{
	vsVector2D pos = vsVector2D::Zero;
	// okay.  First, let's start by grabbing the coordinate of our requested corner,
	// as though we had no camera.  Later on, we'll correct for the camera.
	
	float fov = GetFOV();			// fov is measured VERTICALLY.  So our height is FOV.
	float halfFov = 0.5f * fov;		// since we assume that '0,0' is in the middle, our coords vertically are [-halfFov .. halfFov]
	
	if ( bottom )
		pos.y = halfFov;
	else	// top
		pos.y = -halfFov;
	
	// now, to figure out where the edge is, we need to know our screen aspect ratio, which is the ratio of horizontal pixels to vertical pixels.
	float aspectRatio = vsScreen::Instance()->GetAspectRatio();
	
	if ( right )
		pos.x = halfFov * aspectRatio;
	else	// left
		pos.x = -halfFov * aspectRatio;
	
	
	// Okay!  Now we have the corner of our screen.  Now we just need to figure out where this camera-relative coordinate sits in world-space
	// to do this, we take the world-to-camera transform off the camera, and then apply its inverse to our position.
	
	vsTransform worldToCamera;
	worldToCamera.m_position = m_camera->GetPosition();
	worldToCamera.m_angle = m_camera->GetAngle();
	
	pos = worldToCamera.ApplyInverseTo(pos);
	
	return pos;
}
Exemple #2
0
void C_CFPlayer::CalcInEyeCamView(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 ( pTarget->ShouldForceThirdPerson() )
	{
		CalcChaseCamView( eyeOrigin, eyeAngles, fov );
		return;
	}

	fov = GetFOV();	// TODO use tragets FOV

	m_flObserverChaseDistance = 0.0;

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

	// Apply punch angle
	VectorAdd( eyeAngles, GetPunchAngle(), eyeAngles );

	engine->SetViewAngles( eyeAngles );
}
void CBasePlayer::CalcPlayerView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov )
{
#if defined( CLIENT_DLL )
	if ( !prediction->InPrediction() )
	{
		// FIXME: Move into prediction
		view->DriftPitch();
	}
#endif

	VectorCopy( EyePosition(), eyeOrigin );
#ifdef SIXENSE
	if ( g_pSixenseInput->IsEnabled() )
	{
		VectorCopy( EyeAngles() + GetEyeAngleOffset(), eyeAngles );
	}
	else
	{
		VectorCopy( EyeAngles(), eyeAngles );
	}
#else
	VectorCopy( EyeAngles(), eyeAngles );
#endif

#if defined( CLIENT_DLL )
	if ( !prediction->InPrediction() )
#endif
	{
		SmoothViewOnStairs( eyeOrigin );
	}

	// Snack off the origin before bob + water offset are applied
	Vector vecBaseEyePosition = eyeOrigin;

	CalcViewRoll( eyeAngles );

	// Apply punch angle
	VectorAdd( eyeAngles, m_Local.m_vecPunchAngle, eyeAngles );

#if defined( CLIENT_DLL )
	if ( !prediction->InPrediction() )
	{
		// Shake it up baby!
		vieweffects->CalcShake();
		vieweffects->ApplyShake( eyeOrigin, eyeAngles, 1.0 );
	}
#endif

#if defined( CLIENT_DLL )
	// Apply a smoothing offset to smooth out prediction errors.
	Vector vSmoothOffset;
	GetPredictionErrorSmoothingVector( vSmoothOffset );
	eyeOrigin += vSmoothOffset;
	m_flObserverChaseDistance = 0.0;
#endif

	// calc current FOV
	fov = GetFOV();
}
Exemple #4
0
void PerspectiveImpl::ComputeAngle (float width)
{
  float rview_fov = (float)GetFOV () * 0.5f;
  float disp_width = (float)width * 0.5f;
  float inv_disp_radius = csQisqrt (
      rview_fov * rview_fov + disp_width * disp_width);
  fov_angle = 2.0f * (float)acos (disp_width * inv_disp_radius)
  	* (360.0f / TWO_PI);
  Dirtify();
}
Exemple #5
0
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// GetCameraPlanePoints: return four points in camera space at given distance from camera
void CCamera::GetCameraPlanePoints(float dist,CVector3D pts[4]) const
{
	float aspect=float(m_ViewPort.m_Width)/float(m_ViewPort.m_Height);

	float x=dist*float(tan(GetFOV()*aspect*0.5));
	float y=dist*float(tan(GetFOV()*0.5));
	pts[0].X=-x;
	pts[0].Y=-y;
	pts[0].Z=dist;
	pts[1].X=x;
	pts[1].Y=-y;
	pts[1].Z=dist;
	pts[2].X=x;
	pts[2].Y=y;
	pts[2].Z=dist;
	pts[3].X=-x;
	pts[3].Y=y;
	pts[3].Z=dist;
}
Exemple #6
0
float CBasePlayer::GetFOVDistanceAdjustFactor()
{
	float defaultFOV	= (float)GetDefaultFOV();
	float localFOV		= (float)GetFOV();

	if ( localFOV == defaultFOV || defaultFOV < 0.001f )
	{
		return 1.0f;
	}

	// If FOV is lower, then we're "zoomed" in and this will give a factor < 1 so apparent LOD distances can be
	//  shorted accordingly
	return localFOV / defaultFOV;

}
Exemple #7
0
void C_PointCamera::GetToolRecordingState( KeyValues *msg )
{
    BaseClass::GetToolRecordingState( msg );

    unsigned char r, g, b;
    static MonitorRecordingState_t state;
    state.m_bActive = IsActive() && !IsDormant();
    state.m_flFOV = GetFOV();
    state.m_bFogEnabled = IsFogEnabled();
    state.m_flFogStart = GetFogStart();
    state.m_flFogEnd = GetFogEnd();
    GetFogColor( r, g, b );
    state.m_FogColor.SetColor( r, g, b, 255 );

    msg->SetPtr( "monitor", &state );
}
Exemple #8
0
//-----------------------------------------------------------------------------
// Purpose: Sets the FOV of the client, doing interpolation between old and new if requested
// Input  : FOV - New FOV
//			zoomRate - Amount of time (in seconds) to move between old and new FOV
//-----------------------------------------------------------------------------
bool CBasePlayer::SetFOV( CBaseEntity *pRequester, int FOV, float zoomRate, int iZoomStart /* = 0 */ )
{
	//NOTENOTE: You MUST specify who is requesting the zoom change
	assert( pRequester != NULL );
	if ( pRequester == NULL )
		return false;

	// If we already have an owner, we only allow requests from that owner
	if ( ( m_hZoomOwner.Get() != NULL ) && ( m_hZoomOwner.Get() != pRequester ) )
	{
#ifdef GAME_DLL
		if ( CanOverrideEnvZoomOwner( m_hZoomOwner.Get() ) == false )
#endif
			return false;
	}
	else
	{
		//FIXME: Maybe do this is as an accessor instead
		if ( FOV == 0 )
		{
			m_hZoomOwner = NULL;
		}
		else
		{
			m_hZoomOwner = pRequester;
		}
	}

	// Setup our FOV and our scaling time

	if ( iZoomStart > 0 )
	{
		m_iFOVStart = iZoomStart;
	}
	else
	{
		m_iFOVStart = GetFOV();
	}

	m_flFOVTime = gpGlobals->curtime;
	m_iFOV = FOV;

	m_Local.m_flFOVRate	= zoomRate;

	return true;
}
Exemple #9
0
//-----------------------------------------------------------------------------
// Purpose: The main view setup function for vehicles
//-----------------------------------------------------------------------------
void CBasePlayer::CalcVehicleView( 
#if defined( CLIENT_DLL )
	IClientVehicle *pVehicle, 
#else
	IServerVehicle *pVehicle,
#endif
	Vector& eyeOrigin, QAngle& eyeAngles,
	float& zNear, float& zFar, float& fov )
{
	Assert( pVehicle );

	// Start with our base origin and angles
	CacheVehicleView();
	eyeOrigin = m_vecVehicleViewOrigin;
	eyeAngles = m_vecVehicleViewAngles;

#if defined( CLIENT_DLL )

	fov = GetFOV();

	// Allows the vehicle to change the clip planes
	pVehicle->GetVehicleClipPlanes( zNear, zFar );
#endif

	// Snack off the origin before bob + water offset are applied
	Vector vecBaseEyePosition = eyeOrigin;

	CalcViewRoll( eyeAngles );

	// Apply punch angle
	VectorAdd( eyeAngles, m_Local.m_vecPunchAngle, eyeAngles );

#if defined( CLIENT_DLL )
	if ( !prediction->InPrediction() )
	{
		// Shake it up baby!
		vieweffects->CalcShake();
		vieweffects->ApplyShake( eyeOrigin, eyeAngles, 1.0 );
	}
#endif

}
Exemple #10
0
vsVector2D
vsScene::GetCorner(bool bottom, bool right)
{
    vsVector2D pos = vsVector2D::Zero;
    // okay.  First, let's start by grabbing the coordinate of our requested corner,
    // as though we had no camera.  Later on, we'll correct for the camera.

    float fov = GetFOV();			// fov is measured VERTICALLY.  So our height is FOV.
    float halfFov = 0.5f * fov;		// since we assume that '0,0' is in the middle, our coords vertically are [-halfFov .. halfFov]

    if ( bottom )
        pos.y = halfFov;
    else	// top
        pos.y = -halfFov;

    // now, to figure out where the edge is, we need to know our screen aspect
    // ratio, which is the ratio of horizontal pixels to vertical pixels.  Note
    // that we're going to use the CAMERA's recorded aspect ratio, not the ACTUAL
    // aspect ratio, since the two may differ.  When we tell people corner coordinates,
    // though, they're likely to want to use them for rendering from our current
    // camera, so let's return values in that coordinate space.
    float aspectRatio = m_camera->GetAspectRatio();

    if ( right )
        pos.x = halfFov * aspectRatio;
    else	// left
        pos.x = -halfFov * aspectRatio;


    // Okay!  Now we have the corner of our screen.  Now we just need to figure out where this camera-relative coordinate sits in world-space
    // to do this, we take the world-to-camera transform off the camera, and then apply its inverse to our position.

    vsTransform2D worldToCamera;
    worldToCamera.SetTranslation( m_camera->GetPosition() );
    worldToCamera.SetAngle( m_camera->GetAngle() );

    pos = worldToCamera.ApplyTo(pos);

    return pos;
}
Exemple #11
0
bool Client::IsInViewCone (const Vector &pos) const
{
   engine->BuildGlobalVectors (GetViewAngles ());

   return ((pos - GetHeadOrigin ()).Normalize () | g_pGlobals->v_forward) >= cosf (Math::DegreeToRadian ((GetFOV () > 0.0f ? GetFOV () : 90.0f) * 0.5f));
}
Exemple #12
0
// This is mostly copy paste from C_BasePlayer::CalcPlayerView
void C_NEOPlayer::CalcPlayerView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov )
{
	if ( !prediction->InPrediction() )
	{
		// FIXME: Move into prediction
		view->DriftPitch();
	}

	VectorCopy( EyePosition(), eyeOrigin );
	VectorCopy( EyeAngles(), eyeAngles );

	if ( !prediction->InPrediction() )
	{
		SmoothViewOnStairs( eyeOrigin );
	}

	// Snack off the origin before bob + water offset are applied
	Vector vecBaseEyePosition = eyeOrigin;

	CalcViewRoll( eyeAngles );

	// Apply punch angle
	VectorAdd( eyeAngles, m_Local.m_vecPunchAngle, eyeAngles );

	if ( !prediction->InPrediction() )
	{
		// Shake it up baby!
		vieweffects->CalcShake();
		vieweffects->ApplyShake( eyeOrigin, eyeAngles, 1.0 );
	}

	// Apply a smoothing offset to smooth out prediction errors.
	Vector vSmoothOffset;
	GetPredictionErrorSmoothingVector( vSmoothOffset );
	eyeOrigin += vSmoothOffset;
	m_flObserverChaseDistance = 0.0;

	// This is what they've added
	switch ( m_iUnknown )
	{
		case 0:
			eyeAngles.z = 0.f;
			break;

		case 1:
			eyeAngles.z = m_flUnknown3 * 20.f - 20.f;
			break;

		case 2:
			eyeAngles.z = -20.f;
			break;

		case 3:
			eyeAngles.z = -20.f * m_flUnknown3;
			break;

		case 4:
			eyeAngles.z = m_flUnknown3;
			break;

		case 5:
			eyeAngles.z = 20.f;
			break;

		case 6:
			eyeAngles.z = 20.f * m_flUnknown3;
			break;
	}

	// calc current FOV
	fov = GetFOV();
}
Exemple #13
0
bool ZCamera::CheckCollisionWall(float &fRealDist, rvector& pos, rvector& dir)
{
	RBSPPICKINFO bpi;
	float fNearZ = DEFAULT_NEAR_Z;
	rvector pos2 = pos;							// camera pos
	rvector tarpos = pos2 + (dir * fNearZ);		// near pos

	rvector up2, right2;
	up2 = rvector(0.0f, 0.0f, 1.0f);
	right2 = Normalized(CrossProduct(dir, up2));

	up2 = Normalized(CrossProduct(right2, dir));
	right2 = Normalized(CrossProduct(dir, up2));

	float fov = GetFOV();
	float e = 1 / (tanf(fov / 2));
	float fAspect = (float)RGetScreenWidth() / (float)RGetScreenHeight();
	float fPV = (fAspect * fNearZ / e);
	float fPH = (fNearZ / e);

	bool bCollisionWall = false;

	pos2 = pos;
	rvector tar = tarpos + (up2 * fPV);
	rvector dir2;
	dir2 = tar - pos2;
	Normalize(dir2);
	// NOTE: This was using dir as at??? Figure out why
	auto matView = ViewMatrix(pos2, Normalized(dir - pos2), up2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, up2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					D3DXVECTOR4 rV4;
					vv1 = Transform(vv1, matView);
					v2 = Transform(vv2, matView);

					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < PI_FLOAT)
					{
						bCollisionWall = true;

						float fX = fPV - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	pos2 = pos;
	tar = tarpos + (right2 * fPH);
	dir2 = Normalized(tar - pos2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, right2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < (PI_FLOAT / 2))
					{
						bCollisionWall = true;

						float fX = fPH - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	pos2 = pos;
	tar = tarpos - (up2 * fPV);
	dir2 = Normalized(tar - pos2);
	matView = ViewMatrix(pos2, Normalized(dir2 - pos2), up2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, -up2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					bCollisionWall = true;

					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					vv1 = Transform(vv1, matView);
					vv2 = Transform(vv2, matView);

					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < (PI_FLOAT / 2))
					{
						float fX = fPV - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	pos2 = pos;
	tar = tarpos - (right2 * fPH);
	dir2 = Normalized(tar - pos2);

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(pos2, dir2, &bpi))
	{
		if (Magnitude(tar - bpi.PickPos) < Magnitude(tar - pos2))
		{
			rvector v1, v2, v3;

			v1 = bpi.PickPos;
			v3 = tar;

			if (ZGetGame()->GetWorld()->GetBsp()->Pick(tarpos, -right2, &bpi))
			{
				v2 = bpi.PickPos;

				float fD = Magnitude(tarpos - v2);
				if (fD < fPH)
				{
					bCollisionWall = true;

					rvector vv1 = v1 - v2, vv2 = v2 - v3;
					float fAng = GetAngleOfVectors(vv1, vv2);
					if (fAng < 0.0f) fAng = -fAng;

					if (fAng < (PI_FLOAT / 2))
					{
						float fX = fPH - fD;
						float fY = fX * tanf(fAng);

						float fMyRealDist = fRealDist - fY;
						fRealDist = min(fMyRealDist, fRealDist);
					}
				}
			}
		}
	}

	if (fRealDist < 0) fRealDist = 0.0f;

	return bCollisionWall;
}
Exemple #14
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();
}