#include "camera.h"
#include <glm/ext/matrix_transform.hpp>

Matrix4 get_camera_view_matrix(Camera *camera, Render_Data *render_data) {
  f32 azimuth_radians = glm::radians(render_data->view_azimuth);
  f32 elevation_radians = glm::radians(render_data->view_elevation);

  f32 sin_azimuth = glm::sin(azimuth_radians);
  f32 cos_azimuth = glm::cos(azimuth_radians);
  f32 sin_elevation = glm::sin(elevation_radians);
  f32 cos_elevation = glm::cos(elevation_radians);

  camera->view_direction = glm::normalize(Vector3(sin_azimuth * cos_elevation, sin_elevation, -cos_azimuth * cos_elevation));
  camera->right_direction = glm::normalize(glm::cross(camera->view_direction, camera->world_up_vector));
  camera->up_direction = glm::normalize(glm::cross(camera->right_direction, camera->view_direction));

  render_data->camera_world_position += render_data->move_forward * render_data->tick_diff * camera->view_direction + render_data->move_right * render_data->tick_diff * camera->right_direction + render_data->move_up * render_data->tick_diff * camera->up_direction;

  Matrix4 look_at = glm::lookAt(render_data->camera_world_position, render_data->camera_world_position + camera->view_direction, camera->world_up_vector);

  return look_at;
}
