blob: b4c2debb41a9ebb62230eb607dea9885b111c46a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/* (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. */
#include <engine/shared/config.h>
#include <base/math.h>
#include <game/collision.h>
#include <game/client/gameclient.h>
#include <game/client/component.h>
#include "camera.h"
#include "controls.h"
CCamera::CCamera()
{
m_WasSpectator = false;
}
void CCamera::OnRender()
{
//vec2 center;
m_Zoom = 1.0f;
// update camera center
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;
}
m_Center = m_pClient->m_pControls->m_MousePos;
}
else
{
if(m_WasSpectator)
{
m_pClient->m_pControls->ClampMousePos();
m_WasSpectator = false;
}
vec2 CameraOffset(0, 0);
float l = length(m_pClient->m_pControls->m_MousePos);
if(l > 0.0001f) // make sure that this isn't 0
{
float DeadZone = g_Config.m_ClMouseDeadzone;
float FollowFactor = g_Config.m_ClMouseFollowfactor/100.0f;
float OffsetAmount = max(l-DeadZone, 0.0f) * FollowFactor;
CameraOffset = normalize(m_pClient->m_pControls->m_MousePos)*OffsetAmount;
}
if(m_pClient->m_Snap.m_Spectate)
m_Center = m_pClient->m_Snap.m_SpectatorPos + CameraOffset;
else
m_Center = m_pClient->m_LocalCharacterPos + CameraOffset;
}
}
|