Compare commits

..
0 Commits
8 changed files with 35 additions and 16 deletions

No files matched your search

+2 -2
View File
@@ -2,10 +2,10 @@
"camera": {
"image_width": 1920,
"image_height": 1080,
"anti_alias_rate": 23,
"anti_alias_rate": 1,
"max_depth": 50,
"fov": 90.0,
"look_from": [15, 4, 15],
"look_from": [0, 4, 15],
"look_at": [0.0, 0.0, 0.0],
"vup": [0.0, 1.0, 0.0],
"defocus_angle": 0,
+1 -1
View File
@@ -1,6 +1,6 @@
use std::{f32::consts::PI, sync::Arc};
use log::info;
use log::{info, warn};
use crate::{
objects::{hit::Hit, traits::Hittable},
+1 -1
View File
@@ -43,7 +43,7 @@ impl Hittable for Cube {
Hit::hit_list(&self.faces, r)
}
fn normal_at(&self, _p: &Vec3) -> Vec3 {
fn normal_at(&self, p: &Vec3) -> Vec3 {
// TODO: normal calc for cube
todo!()
}
+1 -1
View File
@@ -6,7 +6,7 @@ use serde::Deserialize;
use crate::{
objects::{hit::Hit, materials::traits::Material},
ray::Ray,
vec3::Colour,
vec3::{Colour, Vec3},
};
#[derive(Debug, Deserialize)]
+10 -8
View File
@@ -4,6 +4,7 @@ use crate::objects::traits::Hittable;
use crate::objects::triangle::Triangle;
use crate::ray::Ray;
use crate::{objects::materials::traits::Material, vec3::Vec3};
use log::{info, warn};
use std::fmt::Debug;
use std::sync::Arc;
@@ -18,6 +19,7 @@ pub struct Quad {
impl Quad {
pub fn new(p1: Vec3, p2: Vec3, p3: Vec3, p4: Vec3, material: Arc<dyn Material>) -> Self {
warn!("quad normal {}", (p2 - p1).cross(&(p4 - p1)).get_unit());
Self {
p1,
p2,
@@ -28,12 +30,12 @@ impl Quad {
}
}
pub fn corner_spheres(&self) -> Vec<Sphere> {
vec![
Sphere::new(self.p1, 1., self.material.clone()),
Sphere::new(self.p2, 1., self.material.clone()),
Sphere::new(self.p3, 1., self.material.clone()),
Sphere::new(self.p4, 1., self.material.clone()),
]
let mut out: Vec<Sphere> = vec![];
out.push(Sphere::new(self.p1, 1., self.material.clone()));
out.push(Sphere::new(self.p2, 1., self.material.clone()));
out.push(Sphere::new(self.p3, 1., self.material.clone()));
out.push(Sphere::new(self.p4, 1., self.material.clone()));
return out;
}
pub fn hit(
@@ -50,7 +52,7 @@ impl Quad {
if isct1.is_some() {
return isct1;
}
isct2
return isct2;
}
}
@@ -81,6 +83,6 @@ impl Hittable for Quad {
fn normal_at(&self, _p: &Vec3) -> Vec3 {
// FIXME: might cause ownership issues
self.normal
return self.normal;
}
}
+3 -3
View File
@@ -54,9 +54,9 @@ impl Triangle {
let diff = (a4 - a1 - a2 - a3).abs();
if diff < 0.001 {
Some(Hit::new(t, p, normal, material, normal.dot(&-r.dir()) > 0.))
return Some(Hit::new(t, p, normal, material, normal.dot(&-r.dir()) > 0.));
} else {
None
return None;
}
}
}
@@ -86,6 +86,6 @@ impl Hittable for Triangle {
fn normal_at(&self, _p: &Vec3) -> Vec3 {
// FIXME: might cause ownership issues
self.normal
return self.normal;
}
}
+16
View File
@@ -40,6 +40,22 @@ impl Debug for Scene {
}
impl Scene {
pub fn new(image_width: u32, image_height: u32) -> Self {
Self {
camera: Camera::new(image_width, image_height),
materials: vec![],
objects: vec![],
}
}
pub fn camera(&mut self) -> &mut Camera {
&mut self.camera
}
pub fn add_hittable(&mut self, hittable: Arc<dyn Hittable>) {
self.objects.push(hittable);
}
pub fn render(&mut self) {
self.camera.render(&self.objects);
}
+1
View File
@@ -1,5 +1,6 @@
use core::f32::math::sqrt;
use is_close::default;
use log::warn;
use rand::RngExt;
use serde::{Deserialize, Serialize, Serializer};
use std::{
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.