Rename binary + add homework sample

This commit is contained in:
Michael Zhang 2023-02-12 23:46:54 -06:00
parent 0000031053
commit 0000032041
9 changed files with 61 additions and 8 deletions

View file

@ -1,5 +1,6 @@
/target
/assignment-1
/assignment-1b
/raytracer1b
/examples/*.png
*.ppm
*.zip

View file

@ -4,6 +4,10 @@ authors = ["Michael Zhang <zhan4854@umn.edu>"]
version = "0.1.0"
edition = "2021"
[[bin]]
name = "raytracer1b"
path = "src/main.rs"
[dependencies]
anyhow = "1.0.68"
clap = { version = "4.1.4", features = ["derive"] }

View file

@ -8,7 +8,7 @@ PANDOC := pandoc
CONVERT := convert
HANDIN := hw1b.michael.zhang.zip
BINARY := ./assignment-1b
BINARY := ./raytracer1b
WRITEUP := writeup.pdf
SOURCES := $(shell find -name "*.rs")
@ -27,7 +27,7 @@ $(BINARY): $(SOURCES)
-w /usr/src/myapp \
rust \
cargo build --release
mv target/release/assignment-1b $@
mv target/release/raytracer1b $@
$(HANDIN): $(BINARY) $(WRITEUP) Makefile Cargo.toml Cargo.lock README.md $(EXAMPLES_PNG) $(EXAMPLES_PPM)
$(ZIP) -r $@ src examples $^

Binary file not shown.

View file

@ -0,0 +1,14 @@
imsize 512 512
eye 0 0 0
viewdir 0 0.1 -1
hfov 90
updir 0 1 0
bkgcolor 0.1 0.1 0.1
light -1 -1 -1 0 0.9 0.5 0.05
mtlcolor 0 1 0 1 1 1 0.6 0.2 0.2 10
sphere 0 1.5 -4 1
mtlcolor 0 1 0 1 1 1 0.1 0.8 0.2 10
sphere -1.275 -0.75 -4 1
mtlcolor 0 1 0 1 1 1 0.1 0.2 0.8 10
sphere 1.275 -0.75 -4 1

View file

@ -15,6 +15,7 @@ use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use scene::data::ObjectKind;
use crate::image::Image;
use crate::input_file::parse_input_file;
@ -82,8 +83,12 @@ fn main() -> Result<()> {
// Generate a parallel iterator for pixels
// The iterator preserves order and uses row-major order
let pixels_iter = (0..scene.image_height)
.into_par_iter()
.flat_map(|y| (0..scene.image_width).into_par_iter().map(move |x| (x, y)));
// .into_par_iter()
.flat_map(|y| {
(0..scene.image_width)
// .into_par_iter()
.map(move |x| (x, y))
});
// Loop through every single pixel of the output file
let pixels = pixels_iter

View file

@ -132,8 +132,7 @@ impl ObjectKind for Cylinder {
let c = rotated_cylinder_center;
if r.z == 0.0 {
// No solutions here
vec![]
Vec::new() // No solutions here
} else {
vec![
(-o.z + c.z + self.length / 2.0) / r.z,
@ -177,3 +176,29 @@ impl ObjectKind for Cylinder {
Ok(solutions.min_by_key(|ctx| ctx.time))
}
}
#[cfg(test)]
mod tests {
use nalgebra::Vector3;
use crate::{ray::Ray, scene::data::ObjectKind};
use super::Cylinder;
#[test]
fn test_cylinder() {
let cylinder = Cylinder {
center: Vector3::new(0.0, 0.0, 0.0),
direction: Vector3::new(0.0, 1.0, 0.0),
radius: 3.0,
length: 4.0,
};
let eye = Vector3::new(0.0, 3.0, 3.0);
let end = Vector3::new(0.0, 2.0, 2.0);
let ray = Ray::from_endpoints(eye, end);
let res = cylinder.intersects_ray_at(&ray);
panic!("Result: {res:?}");
}
}

View file

@ -84,6 +84,7 @@ pub struct Scene {
pub objects: Vec<Object>,
}
/// Information about an intersection
#[derive(Derivative)]
#[derivative(Debug, PartialEq, PartialOrd, Ord)]
pub struct IntersectionContext {

View file

@ -25,7 +25,10 @@ where
}
/// Calculate the rotation matrix between the 2 given vectors
/// Based on the method here: https://math.stackexchange.com/a/897677
///
/// Based on the method given [here][1].
///
/// [1]: https://math.stackexchange.com/a/897677
pub fn compute_rotation_matrix(
a: Vector3<f64>,
b: Vector3<f64>,