eoc: Updates to work with new Float abstraction.
This commit is contained in:
parent
1c06833658
commit
ecf7cd7bdc
@ -3,6 +3,7 @@ use anyhow::{bail, Result};
|
|||||||
use rtchallenge::{
|
use rtchallenge::{
|
||||||
canvas::Canvas,
|
canvas::Canvas,
|
||||||
tuples::{Color, Tuple},
|
tuples::{Color, Tuple},
|
||||||
|
Float,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -47,8 +48,8 @@ fn main() -> Result<()> {
|
|||||||
let bg = Color::new(0.2, 0.2, 0.2);
|
let bg = Color::new(0.2, 0.2, 0.2);
|
||||||
let mut c = Canvas::new(w, h, bg);
|
let mut c = Canvas::new(w, h, bg);
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let w = w as f32;
|
let w = w as Float;
|
||||||
let h = h as f32;
|
let h = h as Float;
|
||||||
while p.position.y > 0. {
|
while p.position.y > 0. {
|
||||||
p = tick(&e, &p);
|
p = tick(&e, &p);
|
||||||
println!("tick {}: proj {:?}", i, p);
|
println!("tick {}: proj {:?}", i, p);
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
use std::f32::consts::PI;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use rtchallenge::{
|
use rtchallenge::{
|
||||||
canvas::Canvas,
|
canvas::Canvas,
|
||||||
|
float::consts::PI,
|
||||||
matrices::Matrix4x4,
|
matrices::Matrix4x4,
|
||||||
tuples::{Color, Tuple},
|
tuples::{Color, Tuple},
|
||||||
|
Float,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn draw_dot(c: &mut Canvas, x: usize, y: usize) {
|
fn draw_dot(c: &mut Canvas, x: usize, y: usize) {
|
||||||
@ -30,13 +30,13 @@ fn main() -> Result<()> {
|
|||||||
let rot_hour = Matrix4x4::rotation_z(-PI / 6.);
|
let rot_hour = Matrix4x4::rotation_z(-PI / 6.);
|
||||||
|
|
||||||
let mut p = t * p;
|
let mut p = t * p;
|
||||||
let w = w as f32;
|
let w = w as Float;
|
||||||
let h = h as f32;
|
let h = h as Float;
|
||||||
// The 'world' exists between -0.5 - 0.5 in X-Y plane.
|
// The 'world' exists between -0.5 - 0.5 in X-Y plane.
|
||||||
// To convert to screen space, we translate by 0.5, scale to canvas size,
|
// To convert to screen space, we translate by 0.5, scale to canvas size,
|
||||||
// and invert the Y-axis.
|
// and invert the Y-axis.
|
||||||
let world_to_screen =
|
let world_to_screen =
|
||||||
Matrix4x4::scaling(w as f32, -h as f32, 1.0) * Matrix4x4::translation(0.5, -0.5, 0.);
|
Matrix4x4::scaling(w as Float, -h as Float, 1.0) * Matrix4x4::translation(0.5, -0.5, 0.);
|
||||||
for _ in 0..12 {
|
for _ in 0..12 {
|
||||||
let canvas_pixel = world_to_screen * p;
|
let canvas_pixel = world_to_screen * p;
|
||||||
draw_dot(&mut c, canvas_pixel.x as usize, canvas_pixel.y as usize);
|
draw_dot(&mut c, canvas_pixel.x as usize, canvas_pixel.y as usize);
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use rtchallenge::{
|
|||||||
rays::Ray,
|
rays::Ray,
|
||||||
spheres::{intersect, Sphere},
|
spheres::{intersect, Sphere},
|
||||||
tuples::{Color, Tuple},
|
tuples::{Color, Tuple},
|
||||||
|
Float,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
@ -16,7 +17,7 @@ fn main() -> Result<()> {
|
|||||||
let ray_origin = Tuple::point(0., 0., -5.);
|
let ray_origin = Tuple::point(0., 0., -5.);
|
||||||
let wall_z = 10.;
|
let wall_z = 10.;
|
||||||
let wall_size = 7.;
|
let wall_size = 7.;
|
||||||
let pixel_size = wall_size / w as f32;
|
let pixel_size = wall_size / w as Float;
|
||||||
let half = wall_size / 2.;
|
let half = wall_size / 2.;
|
||||||
let color = Color::new(1., 0., 0.);
|
let color = Color::new(1., 0., 0.);
|
||||||
let mut shape = Sphere::default();
|
let mut shape = Sphere::default();
|
||||||
@ -25,9 +26,9 @@ fn main() -> Result<()> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for y in 0..h {
|
for y in 0..h {
|
||||||
let world_y = half - pixel_size * y as f32;
|
let world_y = half - pixel_size * y as Float;
|
||||||
for x in 0..w {
|
for x in 0..w {
|
||||||
let world_x = -half + pixel_size * x as f32;
|
let world_x = -half + pixel_size * x as Float;
|
||||||
let position = Tuple::point(world_x, world_y, wall_z);
|
let position = Tuple::point(world_x, world_y, wall_z);
|
||||||
let r = Ray::new(ray_origin, (position - ray_origin).normalize());
|
let r = Ray::new(ray_origin, (position - ray_origin).normalize());
|
||||||
let xs = intersect(&shape, &r);
|
let xs = intersect(&shape, &r);
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use rtchallenge::{
|
|||||||
rays::Ray,
|
rays::Ray,
|
||||||
spheres::{intersect, Sphere},
|
spheres::{intersect, Sphere},
|
||||||
tuples::{Color, Tuple},
|
tuples::{Color, Tuple},
|
||||||
WHITE,
|
Float, WHITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
@ -18,7 +18,7 @@ fn main() -> Result<()> {
|
|||||||
let ray_origin = Tuple::point(0., 0., -5.);
|
let ray_origin = Tuple::point(0., 0., -5.);
|
||||||
let wall_z = 10.;
|
let wall_z = 10.;
|
||||||
let wall_size = 7.;
|
let wall_size = 7.;
|
||||||
let pixel_size = wall_size / w as f32;
|
let pixel_size = wall_size / w as Float;
|
||||||
let half = wall_size / 2.;
|
let half = wall_size / 2.;
|
||||||
let mut shape = Sphere::default();
|
let mut shape = Sphere::default();
|
||||||
shape.material = Material {
|
shape.material = Material {
|
||||||
@ -33,9 +33,9 @@ fn main() -> Result<()> {
|
|||||||
let light = PointLight::new(light_position, light_color);
|
let light = PointLight::new(light_position, light_color);
|
||||||
let in_shadow = false;
|
let in_shadow = false;
|
||||||
for y in 0..h {
|
for y in 0..h {
|
||||||
let world_y = half - pixel_size * y as f32;
|
let world_y = half - pixel_size * y as Float;
|
||||||
for x in 0..w {
|
for x in 0..w {
|
||||||
let world_x = -half + pixel_size * x as f32;
|
let world_x = -half + pixel_size * x as Float;
|
||||||
let position = Tuple::point(world_x, world_y, wall_z);
|
let position = Tuple::point(world_x, world_y, wall_z);
|
||||||
let direction = (position - ray_origin).normalize();
|
let direction = (position - ray_origin).normalize();
|
||||||
let r = Ray::new(ray_origin, direction);
|
let r = Ray::new(ray_origin, direction);
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
use std::{f32::consts::PI, time::Instant};
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use rtchallenge::{
|
use rtchallenge::{
|
||||||
camera::{Camera, RenderStrategy},
|
camera::{Camera, RenderStrategy},
|
||||||
|
float::consts::PI,
|
||||||
lights::PointLight,
|
lights::PointLight,
|
||||||
materials::Material,
|
materials::Material,
|
||||||
matrices::Matrix4x4,
|
matrices::Matrix4x4,
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
use std::{f32::consts::PI, time::Instant};
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use rtchallenge::{
|
use rtchallenge::{
|
||||||
camera::{Camera, RenderStrategy},
|
camera::{Camera, RenderStrategy},
|
||||||
|
float::consts::PI,
|
||||||
lights::PointLight,
|
lights::PointLight,
|
||||||
materials::Material,
|
materials::Material,
|
||||||
matrices::Matrix4x4,
|
matrices::Matrix4x4,
|
||||||
@ -31,7 +32,7 @@ fn main() -> Result<()> {
|
|||||||
let light_position = Tuple::point(-10., 10., -10.);
|
let light_position = Tuple::point(-10., 10., -10.);
|
||||||
let light_color = WHITE;
|
let light_color = WHITE;
|
||||||
let light = PointLight::new(light_position, light_color);
|
let light = PointLight::new(light_position, light_color);
|
||||||
let mut camera = Camera::new(width, height, PI / 4.);
|
let mut camera = Camera::new(width, height, PI / 2.);
|
||||||
let from = Tuple::point(0., 1.5, -5.);
|
let from = Tuple::point(0., 1.5, -5.);
|
||||||
let to = Tuple::point(0., 1., 0.);
|
let to = Tuple::point(0., 1., 0.);
|
||||||
let up = Tuple::point(0., 1., 0.);
|
let up = Tuple::point(0., 1., 0.);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user