#include "camera.h" struct camera camera_init(const int image_width, const int image_height, const float focal_length) { struct camera cam; float viewport_height, viewport_width; cam.centre.s[0] = 0.0f; cam.centre.s[1] = 0.0f; cam.centre.s[2] = 0.0f; viewport_height = 2.0f; viewport_width = viewport_height * ((float)image_width / (float)image_height); cam.pixel_delta_u.s[0] = viewport_width / (float)image_width; cam.pixel_delta_u.s[1] = 0.0f; cam.pixel_delta_u.s[2] = 0.0f; cam.pixel_delta_v.s[0] = 0.0f; cam.pixel_delta_v.s[1] = -viewport_height / (float)image_height; cam.pixel_delta_v.s[2] = 0.0f; cam.corner00.s[0] = cam.centre.s[0] - viewport_width / 2.0f + 0.5f * (cam.pixel_delta_u.s[0] + cam.pixel_delta_v.s[0]); cam.corner00.s[1] = cam.centre.s[1] + viewport_height / 2.0f + 0.5f * (cam.pixel_delta_u.s[1] + cam.pixel_delta_v.s[1]); cam.corner00.s[2] = cam.centre.s[2] - focal_length + 0.5f * (cam.pixel_delta_u.s[2] + cam.pixel_delta_v.s[2]); return cam; }