Skip to content

Commit

Permalink
Improve jump to satellite functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Mar 26, 2023
1 parent f3ce1c4 commit 16d32e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/gfx/camera.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Wojciech Graj
* Copyright (c) 2022-2023 Wojciech Graj
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -37,7 +37,7 @@ void camera_mvp_generate(struct Camera *camera, mat4 *model, mat4 mvp)

void camera_zoom(struct Camera *camera, float offset)
{
float rad = glm_clamp(camera->rad - offset, 1.1f, 10.f);
float rad = glm_clamp(camera->rad - offset, CAMERA_MIN_RAD, CAMERA_MAX_RAD);
float d_rad = rad - camera->rad;
float d_rad_pct = (camera->rad + d_rad) / (camera->rad);
camera->rad = rad;
Expand Down
5 changes: 4 additions & 1 deletion src/gfx/camera.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Wojciech Graj
* Copyright (c) 2022-2023 Wojciech Graj
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -21,6 +21,9 @@
#undef near
#undef far

#define CAMERA_MIN_RAD 1.1f
#define CAMERA_MAX_RAD 10.f

struct Camera {
vec3 pos;
vec3 target;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void on_info_jump_to_clicked(GtkButton *button, gpointer user_data)
vec3 pos;
glm_mat4_mulv3(e_phys.teme_to_world, (vec3){ r[0], r[1], r[2] }, 1.f, pos);
float rad = glm_vec3_norm(pos);
e_camera.rad = glm_clamp(rad, 1.1f, 10.f);
e_camera.rad = glm_clamp(rad + .1f, CAMERA_MIN_RAD, CAMERA_MAX_RAD);
glm_vec3_scale(pos, e_camera.rad / rad, e_camera.pos);
camera_view_update(&e_camera);
}
Expand Down

0 comments on commit 16d32e0

Please sign in to comment.