diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-03-13 20:04:54 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-03-13 20:04:54 +0100 |
commit | bec47edeefed4d9a545ad0bfa43d7edee6379b03 (patch) | |
tree | 87935cfc33ffe66c296db2f246a2bbc16019cf40 /src/engine/camera.c | |
parent | 74ec145c5e44a51789e9117b1ae93dfd7be24d86 (diff) | |
parent | 5a747929ed2099755fb03c930ea68c77fda805b3 (diff) |
merge `dev` into `ppu`
Diffstat (limited to 'src/engine/camera.c')
-rw-r--r-- | src/engine/camera.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/engine/camera.c b/src/engine/camera.c new file mode 100644 index 0000000..e756bd4 --- /dev/null +++ b/src/engine/camera.c @@ -0,0 +1,34 @@ +#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: fix buggy y-axis ?? + + // new = vec_cen2cor(new,(vec2){.x=max.x/2,.y=max.y/2}); + new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH/2),.y=(new.y+(HH_PPU_SPRITE_HEIGHT/2))*2},(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; + + 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); + + return old; +} + |