diff options
| author | Aiden Gall <aiden@aidengall.xyz> | 2024-02-06 11:23:46 +0000 | 
|---|---|---|
| committer | Aiden Gall <aiden@aidengall.xyz> | 2024-02-06 11:23:46 +0000 | 
| commit | 54d21d69838b394003d243bf21f2fb14d765307e (patch) | |
| tree | cf198688353d2042c990ccaf443931590c885d9d /src/camera.c | |
| parent | e77c9dc9354b715fc2d3894ee553caac3784b00c (diff) | |
Diffstat (limited to 'src/camera.c')
| -rw-r--r-- | src/camera.c | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/src/camera.c b/src/camera.c new file mode 100644 index 0000000..68376b8 --- /dev/null +++ b/src/camera.c @@ -0,0 +1,37 @@ +#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; +} | 
