ddnet/src/game/client/components/camera.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#include <engine/shared/config.h>
2010-05-29 07:25:38 +00:00
#include <base/math.h>
#include <game/collision.h>
#include <game/client/gameclient.h>
#include <game/client/component.h>
2010-05-29 07:25:38 +00:00
#include "camera.h"
#include "controls.h"
2010-05-29 07:25:38 +00:00
CCamera::CCamera()
{
m_WasSpectator = false;
}
2010-05-29 07:25:38 +00:00
void CCamera::OnRender()
{
//vec2 center;
2010-05-29 07:25:38 +00:00
m_Zoom = 1.0f;
2008-10-14 12:11:42 +00:00
// update camera center
2011-03-10 16:57:15 +00:00
if(m_pClient->m_Snap.m_Spectate && (!m_pClient->m_Snap.m_pSpectatorInfo || m_pClient->m_Snap.m_pSpectatorInfo->m_SpectatorID == SPEC_FREEVIEW))
{
if(!m_WasSpectator)
{
m_pClient->m_pControls->ClampMousePos();
m_WasSpectator = true;
}
2010-05-29 07:25:38 +00:00
m_Center = m_pClient->m_pControls->m_MousePos;
}
else
{
if(m_WasSpectator)
{
m_pClient->m_pControls->ClampMousePos();
m_WasSpectator = false;
}
2011-03-10 16:57:15 +00:00
2010-05-29 07:25:38 +00:00
vec2 CameraOffset(0, 0);
2011-03-10 16:57:15 +00:00
float l = length(m_pClient->m_pControls->m_MousePos);
if(l > 0.0001f) // make sure that this isn't 0
2011-03-10 16:57:15 +00:00
{
float DeadZone = g_Config.m_ClMouseDeadzone;
float FollowFactor = g_Config.m_ClMouseFollowfactor/100.0f;
float OffsetAmount = max(l-DeadZone, 0.0f) * FollowFactor;
2010-05-29 07:25:38 +00:00
CameraOffset = normalize(m_pClient->m_pControls->m_MousePos)*OffsetAmount;
2011-03-10 16:57:15 +00:00
}
2011-03-10 16:57:15 +00:00
if(m_pClient->m_Snap.m_Spectate)
m_Center = m_pClient->m_Snap.m_SpectatorPos + CameraOffset;
else
m_Center = m_pClient->m_LocalCharacterPos + CameraOffset;
}
}