about summary refs log tree commit diff
path: root/src/game/client/components/camera.cpp
blob: ba9aed46690ce1fd6565b6409b14bbf871d1fb3e (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
extern "C" {
	#include <engine/e_config.h>
	#include <engine/e_client_interface.h>
}

#include <base/math.hpp>
#include <game/collision.hpp>
#include <game/client/gameclient.hpp>
#include <game/client/component.hpp>

#include "camera.hpp"
#include "controls.hpp"

CAMERA::CAMERA()
{
}

void CAMERA::on_render()
{
	//vec2 center;
	zoom = 1.0f;
	
	if(gameclient.snap.spectate)
		center = gameclient.controls->mouse_pos;
	else
	{

		float l = length(gameclient.controls->mouse_pos);
		float deadzone = config.cl_mouse_deadzone;
		float follow_factor = config.cl_mouse_followfactor/100.0f;
		vec2 camera_offset(0, 0);

		float offset_amount = max(l-deadzone, 0.0f) * follow_factor;
		if(l > 0.0001f) // make sure that this isn't 0
			camera_offset = normalize(gameclient.controls->mouse_pos)*offset_amount;
		
		center = gameclient.local_character_pos + camera_offset;
	}
}