/*
* Tuxánci 2 - A first person shooter
* Copyright (C) 2025-2026 Connor Thomson
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include "ta_math.h"
#include "camera.h"
#include "mouse.h"
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, 2.0f, 3.0f, 0.0f, 0.6f, ta_camera_fov };
}
void ta_camera_update(void) {
const float pitch_limit = ta_rad(90.0f);
ta_camera_current.yaw -= ta_mouse_delta_x * ta_camera_sensitivity;
ta_camera_current.pitch += ta_mouse_delta_y * ta_camera_sensitivity;
if (ta_camera_current.pitch > pitch_limit) {
ta_camera_current.pitch = pitch_limit;
} else if (ta_camera_current.pitch < -pitch_limit) {
ta_camera_current.pitch = -pitch_limit;
}
}
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);
float pitch_cosine = cosf(ta_camera_current.pitch);
float pitch_sine = sinf(ta_camera_current.pitch);
matrix[0] = yaw_cosine;
matrix[1] = -pitch_sine * yaw_sine;
matrix[2] = pitch_cosine * yaw_sine;
matrix[3] = 0.0f;
matrix[4] = 0.0f;
matrix[5] = pitch_cosine;
matrix[6] = pitch_sine;
matrix[7] = 0.0f;
matrix[8] = -yaw_sine;
matrix[9] = -pitch_sine * yaw_cosine;
matrix[10] = pitch_cosine * yaw_cosine;
matrix[11] = 0.0f;
matrix[12] = -yaw_cosine * ta_camera_current.x + yaw_sine * ta_camera_current.z;
matrix[13] = pitch_sine * yaw_sine * ta_camera_current.x - pitch_cosine * ta_camera_current.y + pitch_sine * yaw_cosine * ta_camera_current.z;
matrix[14] = -pitch_cosine * yaw_sine * ta_camera_current.x - pitch_sine * ta_camera_current.y - pitch_cosine * yaw_cosine * ta_camera_current.z;
matrix[15] = 1.0f;
}