camera: instant follow on the first entity

isolation_bkp/dynres
Dominik Madarász 2021-07-27 15:01:17 +02:00
parent 934aaf565f
commit 6b2f049704
2 changed files with 10 additions and 0 deletions

View File

@ -11,6 +11,9 @@ typedef struct {
camera_mode mode;
uint64_t ent_id;
double x, y;
// HACK(zaklaus): Don't lerp if this is the first time we follow any entity.
bool first_time;
} camera;
void camera_reset(void);

View File

@ -10,6 +10,7 @@ static camera main_camera;
void camera_reset(void) {
zpl_zero_item(&main_camera);
main_camera.mode = CAMERA_MODE_STATIONARY;
main_camera.first_time = true;
}
void camera_update(void) {
@ -22,6 +23,12 @@ void camera_update(void) {
main_camera.x = zpl_lerp(main_camera.x, view->x, CAMERA_LERP_FACTOR);
main_camera.y = zpl_lerp(main_camera.y, view->y, CAMERA_LERP_FACTOR);
if (main_camera.first_time) {
main_camera.first_time = false;
main_camera.x = view->x;
main_camera.y = view->y;
}
}break;
default: {