Files
SimpleRayTracing/source/Rendering/Camera.c
2025-04-15 11:29:46 +09:00

20 lines
675 B
C

#include "Rendering/Camera.h"
camera_t camera_create(vec3s position, vec3s forward, vec3s up, float focal_length, float size_x, float aspect_ratio)
{
camera_t camera =
{
.position = position,
.forward = glms_vec3_normalize(forward),
.up = glms_vec3_normalize(up),
.right = glms_vec3_cross(forward, up), // Assuming forward and up are not parallel
.focal_length = focal_length,
.size_x = size_x,
.size_y = size_x / aspect_ratio,
.fov_x = 2.0f * (float)atan(size_x / (2.0f * focal_length)),
.fov_y = 2.0f * (float)atan(size_x / (2.0f * focal_length * aspect_ratio)),
};
return camera;
}