diff --git a/Lantern.glb b/Lantern.glb new file mode 100644 index 0000000..37c2e39 Binary files /dev/null and b/Lantern.glb differ diff --git a/src/main.rs b/src/main.rs index 9e3f4ca..dc9b289 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,8 +44,9 @@ fn main() { let mut device_manager = crate::device::DeviceManager::new(); let mut offset = 0.0; + let mut rotate = 0.0; - let model = Model::new(&display, "Box.glb"); + let model = Model::new(&display, "Lantern.glb"); events_loop.run(move |ev, _, control_flow| { if device_manager.is_pressed(&device::Key::W) { @@ -53,17 +54,31 @@ fn main() { } else if device_manager.is_pressed(&device::Key::S) { offset -= 0.001; } - let mvp = glm::perspective::(1.0, 45.0_f32.to_radians(), 0.2, 100.0); + if device_manager.is_pressed(&device::Key::A) { + rotate += 0.01; + } else if device_manager.is_pressed(&device::Key::D) { + rotate -= 0.01; + } + + let mvp = glm::perspective::(4.0/3.0, 45.0_f32.to_radians(), 0.2, 100.0); let mvp = glm::translate::(&mvp, &glm::vec3(0.0, 0.0, -10.0 + offset)); - let mvp = glm::rotate::(&mvp, 15.0_f32.to_radians(), &glm::vec3(1.0, 0.0, 0.0)); + let mvp = glm::rotate::(&mvp, 15.0_f32.to_radians() + rotate, &glm::vec3(1.0, 0.0, 0.0)); let uniforms = uniform! { MVP: *mvp.as_ref(), }; let mut target = display.draw(); + let params = glium::DrawParameters { + depth: glium::Depth { + test: glium::DepthTest::IfLess, + write: true, + .. Default::default() + }, + backface_culling: glium::draw_parameters::BackfaceCullingMode::CullClockwise, + .. Default::default() + }; target.clear_color(0.0, 0.0, 0.0, 1.0); - target.draw(&vertex_buffer, &indices, &flat_program, &uniforms, - &Default::default()).unwrap(); + target.draw(&vertex_buffer, &indices, &flat_program, &uniforms, ¶ms).unwrap(); model.draw(&mut target, &cube_program, &uniforms); target.finish().unwrap(); diff --git a/src/model.rs b/src/model.rs index 0a85ac7..0a18d0e 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,6 +1,6 @@ extern crate gltf; -use glium::{ VertexBuffer, IndexBuffer }; +use glium::{ VertexBuffer, IndexBuffer, Program }; #[derive(Copy, Clone)] struct Vertex {