summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/camera.h2
-rw-r--r--src/camera.c13
-rw-r--r--src/model.c3
3 files changed, 16 insertions, 2 deletions
diff --git a/include/camera.h b/include/camera.h
index 9bb0d38..a3c6b66 100644
--- a/include/camera.h
+++ b/include/camera.h
@@ -22,12 +22,14 @@
typedef struct ta_camera {
float x, y, z;
float yaw, pitch;
+ float fov;
} ta_camera;
extern ta_camera ta_camera_current;
void ta_camera_init(void);
void ta_camera_update(void);
+void ta_camera_set_fov(float delta_degrees);
void ta_camera_get_view_matrix(float *matrix);
#endif // TA_CAMERA_H \ No newline at end of file
diff --git a/src/camera.c b/src/camera.c
index 2d3c468..8aafd14 100644
--- a/src/camera.c
+++ b/src/camera.c
@@ -24,9 +24,10 @@
ta_camera ta_camera_current;
float ta_camera_sensitivity = 0.0025f;
+float ta_camera_fov = 60.0f;
void ta_camera_init(void) {
- ta_camera_current = (ta_camera){ 0.0f, 0.0f, 5.0f, 0.0f, 0.0f };
+ ta_camera_current = (ta_camera){ 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, ta_camera_fov };
}
void ta_camera_update(void) {
@@ -42,6 +43,16 @@ void ta_camera_update(void) {
}
}
+void ta_camera_set_fov(float delta_degrees) {
+ ta_camera_current.fov += delta_degrees;
+
+ if (ta_camera_current.fov < 20.0f) {
+ ta_camera_current.fov = 20.0f;
+ } else if (ta_camera_current.fov > 120.0f) {
+ ta_camera_current.fov = 120.0f;
+ }
+}
+
void ta_camera_get_view_matrix(float *matrix) {
float yaw_cosine = cosf(ta_camera_current.yaw);
float yaw_sine = sinf(ta_camera_current.yaw);
diff --git a/src/model.c b/src/model.c
index 15b3c97..7902f7a 100644
--- a/src/model.c
+++ b/src/model.c
@@ -22,6 +22,7 @@
#include "model.h"
#include "camera.h"
#include "files.h"
+#include "ta_math.h"
static bool ta_model_push_vertex(ta_model_mesh *mesh, size_t *capacity, const ta_model_vertex *vertex) {
if (mesh->vertex_count == *capacity) {
@@ -329,7 +330,7 @@ void ta_model_render(const ta_model *model, SDL_GPUCommandBuffer *command_buffer
uniforms.model[13] = model->position[1];
uniforms.model[14] = model->position[2];
float aspect = (float)window_width / (float)window_height;
- float focal_length = 1.0f / tanf(22.5f * 0.01745329252f);
+ float focal_length = 1.0f / tanf(ta_rad(ta_camera_current.fov * 0.5f));
float near_plane = 0.1f;
float far_plane = 100.0f;
ta_camera_get_view_matrix(view);