diff --git a/src/main.rs b/src/main.rs index b102f18..42c356f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,12 +54,14 @@ fn ypr_to_mat(ypr: Vec3) -> Mat3 { m_roll * m_pitch * m_yaw } +type Mesh = [Face]; + struct TraceResult { distance: f32, normal: Vec3, } -fn trace_to_mesh(mesh: &[Face], base: Vec3, ray: Vec3) -> Option { +fn trace_to_mesh(mesh: &Mesh, base: Vec3, ray: Vec3) -> Option { let mut ret: Option = None; let mut dist = f32::INFINITY; for f in mesh { @@ -84,7 +86,7 @@ fn trace_to_mesh(mesh: &[Face], base: Vec3, ray: Vec3) -> Option { ret } -fn render(mesh: &[Face], camera: impl Fn(Vec2) -> (Vec3, Vec3)) -> Image { +fn render(mesh: &Mesh, camera: impl Fn(Vec2) -> (Vec3, Vec3)) -> Image { let bkg = vec3(0.0, 0.0, 0.0); let mut img = Image { w: W, @@ -102,7 +104,7 @@ fn render(mesh: &[Face], camera: impl Fn(Vec2) -> (Vec3, Vec3)) -> Image { } else { bkg }; - let color = clamp(to_ivec3(color * 255.0), ivec3(0, 0, 0), ivec3(255, 255, 255)); + let color = clamp_s(to_ivec3(color * 255.0), 0, 255); img.put_pixel(x, y, Color(color.x as u8, color.y as u8, color.z as u8)); } }