ft (wip): deserialization
This commit is contained in:
@@ -45,7 +45,7 @@ impl Hit {
|
||||
self.front_face
|
||||
}
|
||||
|
||||
pub fn hit_list<T: Hittable>(hittables: &Vec<T>, r: &Ray) -> Option<Hit> {
|
||||
pub fn hit_list(hittables: &Vec<Arc<dyn Hittable>>, r: &Ray) -> Option<Hit> {
|
||||
let mut closest: Option<Hit> = None;
|
||||
for hittable in hittables {
|
||||
if let Some(hit) = hittable.hit(r) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use core::f32::math::sqrt;
|
||||
|
||||
use rand::RngExt;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
objects::{hit::Hit, materials::traits::Material},
|
||||
@@ -8,6 +9,7 @@ use crate::{
|
||||
vec3::{Colour, Vec3},
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Dielectric {
|
||||
refraction_index: f32,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use rand::RngExt;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
objects::{hit::Hit, materials::traits::Material},
|
||||
@@ -6,6 +7,7 @@ use crate::{
|
||||
vec3::{Colour, Vec3},
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Lambertian {
|
||||
albedo: Colour,
|
||||
prob: f32,
|
||||
@@ -42,6 +44,7 @@ impl Material for Lambertian {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Metal {
|
||||
albedo: Colour,
|
||||
prob: f32,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{objects::hit::Hit, ray::Ray, vec3::Colour};
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub trait Material {
|
||||
pub trait Material: Debug {
|
||||
fn scatter(&self, hit: &Hit, ray: &Ray) -> Option<(Ray, Colour)>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use core::f32::math::sqrt;
|
||||
use std::fmt::{self, Debug};
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::objects::hit::Hit;
|
||||
use crate::objects::materials::traits::Material;
|
||||
use crate::objects::traits::Hittable;
|
||||
@@ -13,6 +16,16 @@ pub struct Sphere {
|
||||
material: Arc<dyn Material>,
|
||||
}
|
||||
|
||||
impl Debug for Sphere {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Sphere")
|
||||
.field("center", &self.center)
|
||||
.field("radius", &self.radius)
|
||||
.field("material", &self.material)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Sphere {
|
||||
pub fn new(center: Vec3, r: f32, mat: Arc<dyn Material>) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::objects::hit::Hit;
|
||||
use crate::Ray;
|
||||
use crate::Vec3;
|
||||
|
||||
pub trait Hittable {
|
||||
pub trait Hittable: Debug {
|
||||
fn hit(&self, r: &Ray) -> Option<Hit>;
|
||||
fn normal_at(&self, p: &Vec3) -> Vec3;
|
||||
// fn intersect<H: Hittable>(&self, o: &H) -> bool;
|
||||
|
||||
Reference in New Issue
Block a user