aboutsummaryrefslogtreecommitdiff
path: root/src/engine/camera.c
blob: 6898430a4869b748468a3399bd38e479af876c2c (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
#include "engine/camera.h"

#include "ppu/consts.h"


vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){
	//TODO: change floating point math to fix point math
	//TODO: remove magic number at y camera offset

	// new = vec_cen2cor(new,(vec2){.x=max.x/2,.y=max.y/2});
	new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=(max.x	- min.x)/2,.y=(max.y	- min.y)/2});
	// new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=max.x/2,.y=max.y/2});

	// new.x = new.x << HH_MATH_FIXED_POINT;
	// new.y = new.y << HH_MATH_FIXED_POINT;
	static vec_cor old;
	// old.x = old.x << HH_MATH_FIXED_POINT;
	// old.y = old.y << HH_MATH_FIXED_POINT;

	// int16_t some = 0;
	// some = some <<= HH_MATH_FIXED_POINT-1;

	// Camera smoothing
	new.x = (int)((float)new.x*0.1f + (float)old.x*0.9f);
	new.y = (int)((float)new.y*0.1f + (float)old.y*0.9f);

	// old.x = old.x >> HH_MATH_FIXED_POINT;
	// old.y = old.y >> HH_MATH_FIXED_POINT;


	old.x = CLAMP(new.x,min.x,max.x);
	old.y = CLAMP(new.y,min.y,max.y);

	//printf("camera new %d min %d max %d\n",new.y,min.y,max.y);
	return old;
}