Small Fixes™

This commit is contained in:
numzero 2024-04-20 17:53:46 +03:00
parent 7c74469324
commit 78689ba8c2

View File

@ -113,14 +113,14 @@ fn main() -> io::Result<()> {
let img_coords: Vec2 = vec2(x as f32, y as f32); let img_coords: Vec2 = vec2(x as f32, y as f32);
// perspective projection // perspective projection
let off = (img_coords - img_size * 0.5) / (img_size.y * 0.5); let off = (img_coords - img_size * 0.5) / img_size.y;
let base = vec3(0.0, 0.0, -10.0); let base = vec3(0.0, 0.0, -20.0);
let ray = vec3(off.x, off.y, 1.0); let ray = vec3(off.x, off.y, 1.0);
// orthographic projection // orthographic projection
let off = (img_coords - img_size * 0.5) / SCALE; // let off = (img_coords - img_size * 0.5) / SCALE;
let base = vec3(off.x, off.y, -10.0); // let base = vec3(off.x, off.y, -10.0);
let ray = vec3(0.0, 0.0, 1.0); // let ray = vec3(0.0, 0.0, 1.0);
let base = m_camera * base; let base = m_camera * base;
let ray = m_camera * normalize(ray); let ray = m_camera * normalize(ray);
@ -138,11 +138,10 @@ fn main() -> io::Result<()> {
let mut f = BufWriter::new(f); let mut f = BufWriter::new(f);
write!(f, "P6\n")?; write!(f, "P6\n")?;
write!(f, "{W} {H} 255\n")?; write!(f, "{W} {H} 255\n")?;
f.write(img.data()); f.write(img.data())?;
Ok(()) Ok(())
} }
fn edge_dist(a: Vec3, b: Vec3, base: Vec3, dir: Vec3) -> f32 { fn edge_dist(a: Vec3, b: Vec3, base: Vec3, dir: Vec3) -> f32 {
let edge = normalize(b - a); Mat3 { c0: b - a, c1: base - a, c2: dir }.determinant()
dot(edge, cross(base - a, base + dir - a))
} }