Rename binary + add homework sample
This commit is contained in:
parent
0000031053
commit
0000032041
9 changed files with 61 additions and 8 deletions
3
assignment-1b/.gitignore
vendored
3
assignment-1b/.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
/target
|
/target
|
||||||
/assignment-1
|
/assignment-1b
|
||||||
|
/raytracer1b
|
||||||
/examples/*.png
|
/examples/*.png
|
||||||
*.ppm
|
*.ppm
|
||||||
*.zip
|
*.zip
|
||||||
|
|
|
@ -4,6 +4,10 @@ authors = ["Michael Zhang <zhan4854@umn.edu>"]
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "raytracer1b"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.68"
|
anyhow = "1.0.68"
|
||||||
clap = { version = "4.1.4", features = ["derive"] }
|
clap = { version = "4.1.4", features = ["derive"] }
|
||||||
|
|
|
@ -8,7 +8,7 @@ PANDOC := pandoc
|
||||||
CONVERT := convert
|
CONVERT := convert
|
||||||
|
|
||||||
HANDIN := hw1b.michael.zhang.zip
|
HANDIN := hw1b.michael.zhang.zip
|
||||||
BINARY := ./assignment-1b
|
BINARY := ./raytracer1b
|
||||||
WRITEUP := writeup.pdf
|
WRITEUP := writeup.pdf
|
||||||
SOURCES := $(shell find -name "*.rs")
|
SOURCES := $(shell find -name "*.rs")
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ $(BINARY): $(SOURCES)
|
||||||
-w /usr/src/myapp \
|
-w /usr/src/myapp \
|
||||||
rust \
|
rust \
|
||||||
cargo build --release
|
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)
|
$(HANDIN): $(BINARY) $(WRITEUP) Makefile Cargo.toml Cargo.lock README.md $(EXAMPLES_PNG) $(EXAMPLES_PPM)
|
||||||
$(ZIP) -r $@ src examples $^
|
$(ZIP) -r $@ src examples $^
|
||||||
|
|
Binary file not shown.
14
assignment-1b/examples/Hw1bSample1.txt
Executable file
14
assignment-1b/examples/Hw1bSample1.txt
Executable 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
|
||||||
|
|
|
@ -15,6 +15,7 @@ use std::path::PathBuf;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
|
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
|
||||||
|
use scene::data::ObjectKind;
|
||||||
|
|
||||||
use crate::image::Image;
|
use crate::image::Image;
|
||||||
use crate::input_file::parse_input_file;
|
use crate::input_file::parse_input_file;
|
||||||
|
@ -82,8 +83,12 @@ fn main() -> Result<()> {
|
||||||
// Generate a parallel iterator for pixels
|
// Generate a parallel iterator for pixels
|
||||||
// The iterator preserves order and uses row-major order
|
// The iterator preserves order and uses row-major order
|
||||||
let pixels_iter = (0..scene.image_height)
|
let pixels_iter = (0..scene.image_height)
|
||||||
.into_par_iter()
|
// .into_par_iter()
|
||||||
.flat_map(|y| (0..scene.image_width).into_par_iter().map(move |x| (x, y)));
|
.flat_map(|y| {
|
||||||
|
(0..scene.image_width)
|
||||||
|
// .into_par_iter()
|
||||||
|
.map(move |x| (x, y))
|
||||||
|
});
|
||||||
|
|
||||||
// Loop through every single pixel of the output file
|
// Loop through every single pixel of the output file
|
||||||
let pixels = pixels_iter
|
let pixels = pixels_iter
|
||||||
|
|
|
@ -132,8 +132,7 @@ impl ObjectKind for Cylinder {
|
||||||
let c = rotated_cylinder_center;
|
let c = rotated_cylinder_center;
|
||||||
|
|
||||||
if r.z == 0.0 {
|
if r.z == 0.0 {
|
||||||
// No solutions here
|
Vec::new() // No solutions here
|
||||||
vec![]
|
|
||||||
} else {
|
} else {
|
||||||
vec![
|
vec![
|
||||||
(-o.z + c.z + self.length / 2.0) / r.z,
|
(-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))
|
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:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ pub struct Scene {
|
||||||
pub objects: Vec<Object>,
|
pub objects: Vec<Object>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Information about an intersection
|
||||||
#[derive(Derivative)]
|
#[derive(Derivative)]
|
||||||
#[derivative(Debug, PartialEq, PartialOrd, Ord)]
|
#[derivative(Debug, PartialEq, PartialOrd, Ord)]
|
||||||
pub struct IntersectionContext {
|
pub struct IntersectionContext {
|
||||||
|
|
|
@ -25,7 +25,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate the rotation matrix between the 2 given vectors
|
/// 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(
|
pub fn compute_rotation_matrix(
|
||||||
a: Vector3<f64>,
|
a: Vector3<f64>,
|
||||||
b: Vector3<f64>,
|
b: Vector3<f64>,
|
||||||
|
|
Loading…
Reference in a new issue