ft (wip): deserialization

This commit is contained in:
2026-04-25 14:46:03 +02:00
parent ef8da70436
commit 430bdf63bc
15 changed files with 421 additions and 158 deletions

View File

@@ -1,6 +1,7 @@
use std::f32::consts::PI;
use std::{f32::consts::PI, sync::Arc};
use log::info;
use serde::Deserialize;
use crate::{
objects::{hit::Hit, traits::Hittable},
@@ -42,21 +43,50 @@ fn deg_to_rad(deg: f32) -> f32 {
impl Camera {
pub fn new(image_width: u32, image_height: u32) -> Self {
Self {
image_width: image_width,
image_height: image_height,
image_width,
image_height,
anti_alias_rate: 1,
max_depth: 10,
dirty: true,
fov: 60.,
pixel00_loc: Vec3::nil(),
pixel_delta_u: Vec3::nil(),
pixel_delta_v: Vec3::nil(),
pixel00_loc: Vec3::default(),
pixel_delta_u: Vec3::default(),
pixel_delta_v: Vec3::default(),
look_from: Vec3::nil(),
look_at: Vec3::new(0., 0., -1.),
vup: Vec3::new(0., 1., 0.),
u: Vec3::nil(),
v: Vec3::nil(),
w: Vec3::nil(),
u: Vec3::default(),
v: Vec3::default(),
w: Vec3::default(),
}
}
pub fn new_full(
image_width: u32,
image_height: u32,
anti_alias_rate: u32,
max_depth: u32,
fov: f32,
look_from: Vec3,
look_at: Vec3,
vup: Vec3,
) -> Self {
Self {
image_width,
image_height,
anti_alias_rate,
max_depth,
pixel00_loc: Vec3::default(),
pixel_delta_u: Vec3::default(),
pixel_delta_v: Vec3::default(),
dirty: true,
fov,
look_from,
look_at,
vup,
u: Vec3::default(),
v: Vec3::default(),
w: Vec3::default(),
}
}
@@ -125,7 +155,7 @@ impl Camera {
}
}
pub fn render<T: Hittable>(&mut self, hittables: &Vec<T>) {
pub fn render(&mut self, hittables: &Vec<Arc<dyn Hittable>>) {
if self.dirty {
self.init()
}
@@ -139,7 +169,7 @@ impl Camera {
let pixel_tl =
self.pixel00_loc + (i * self.pixel_delta_u) + (j * self.pixel_delta_v);
let mut pixel_colour = Colour::nil();
let mut pixel_colour = Colour::default();
for y in 1..(self.anti_alias_rate + 1) {
for x in 1..(self.anti_alias_rate + 1) {
let pixel_loc = pixel_tl
@@ -161,9 +191,9 @@ impl Camera {
imgbuf.save("output.png").unwrap();
}
fn ray_colour<T: Hittable>(&self, hittables: &Vec<T>, r: &Ray, depth: u32) -> Colour {
fn ray_colour(&self, hittables: &Vec<Arc<dyn Hittable>>, r: &Ray, depth: u32) -> Colour {
if depth <= 0 {
return Colour::nil();
return Colour::default();
}
let closest = Hit::hit_list(hittables, r);
@@ -171,7 +201,7 @@ impl Camera {
if let Some((scattered, att)) = hit.mat().scatter(&hit, r) {
return att * self.ray_colour(hittables, &scattered, depth - 1);
}
return Colour::nil();
return Colour::default();
}
// background