Reduce
This commit is contained in:
parent
1c30605855
commit
48cf277b08
30
src/main.rs
30
src/main.rs
|
|
@ -158,7 +158,6 @@ fn main() -> io::Result<()> {
|
|||
let mut f = BufReader::new(f);
|
||||
ObjMesh::read(&mut f)?
|
||||
};
|
||||
dbg!(&mesh);
|
||||
let mut img = Image {
|
||||
w: W,
|
||||
h: H,
|
||||
|
|
@ -179,38 +178,17 @@ fn main() -> io::Result<()> {
|
|||
1.0, 0.0, 0.0,
|
||||
0.0, pitch.cos(), -pitch.sin(),
|
||||
0.0, pitch.sin(), pitch.cos());
|
||||
let m1 = m_roll * m_pitch * m_yaw;
|
||||
let m_camera = m_roll * m_pitch * m_yaw;
|
||||
for f in mesh.faces {
|
||||
let vs = f.vertices
|
||||
.map(|v| m1 * mesh.vertices[v.vertex])
|
||||
.map(|v| mesh.vertices[v.vertex]);
|
||||
let vs = vs
|
||||
.map(|v| m_camera * v)
|
||||
.map(|v| vec2(W as f32 * 0.5 + v.x * SCALE, H as f32 * 0.5 + v.y * SCALE));
|
||||
let n = mesh.normals[f.vertices[0].normal];
|
||||
if (m1 * mesh.normals[f.vertices[0].normal]).z < 0.0 {
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
let r: u8 = rand::thread_rng().gen_range(0..255);
|
||||
let g: u8 = rand::thread_rng().gen_range(0..255);
|
||||
let b: u8 = rand::thread_rng().gen_range(0..255);
|
||||
|
||||
*/
|
||||
let color = glm::clamp(to_ivec3(n * 120.0 + 128.0), ivec3(0, 0, 0), ivec3(255, 255, 255));
|
||||
img.draw_tri(vs[0], vs[1], vs[2], Color(color.x as u8, color.y as u8, color.z as u8));
|
||||
}
|
||||
/*
|
||||
for v in mesh.vertices {
|
||||
img.put_pixel(W / 2 + (v.x * SCALE) as i32, H / 2 + (v.z * SCALE) as i32, Color(255, 255, 255));
|
||||
}
|
||||
|
||||
for y in 0..H {
|
||||
for x in 0..W {
|
||||
let r = (x * 256 / W).clamp(0, 255) as u8;
|
||||
let g = (y * 256 / H).clamp(0, 255) as u8;
|
||||
let b = rand::thread_rng().gen_range(128 - 16..128 + 16);
|
||||
img.put_pixel(x, y, Color(r, g, b));
|
||||
}
|
||||
}
|
||||
*/
|
||||
let f = File::create("1.ppm")?;
|
||||
let mut f = BufWriter::new(f);
|
||||
write!(f, "P6\n")?;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user