More complicated model, rotating

This commit is contained in:
Dane Johnson 2022-04-08 10:24:24 -05:00
parent 3b0292dbc7
commit c8a030de46
3 changed files with 21 additions and 6 deletions

BIN
Lantern.glb Normal file

Binary file not shown.

View File

@ -44,8 +44,9 @@ fn main() {
let mut device_manager = crate::device::DeviceManager::new(); let mut device_manager = crate::device::DeviceManager::new();
let mut offset = 0.0; 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| { events_loop.run(move |ev, _, control_flow| {
if device_manager.is_pressed(&device::Key::W) { if device_manager.is_pressed(&device::Key::W) {
@ -53,17 +54,31 @@ fn main() {
} else if device_manager.is_pressed(&device::Key::S) { } else if device_manager.is_pressed(&device::Key::S) {
offset -= 0.001; offset -= 0.001;
} }
let mvp = glm::perspective::<f32>(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::<f32>(4.0/3.0, 45.0_f32.to_radians(), 0.2, 100.0);
let mvp = glm::translate::<f32>(&mvp, &glm::vec3(0.0, 0.0, -10.0 + offset)); let mvp = glm::translate::<f32>(&mvp, &glm::vec3(0.0, 0.0, -10.0 + offset));
let mvp = glm::rotate::<f32>(&mvp, 15.0_f32.to_radians(), &glm::vec3(1.0, 0.0, 0.0)); let mvp = glm::rotate::<f32>(&mvp, 15.0_f32.to_radians() + rotate, &glm::vec3(1.0, 0.0, 0.0));
let uniforms = uniform! { let uniforms = uniform! {
MVP: *mvp.as_ref(), MVP: *mvp.as_ref(),
}; };
let mut target = display.draw(); 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.clear_color(0.0, 0.0, 0.0, 1.0);
target.draw(&vertex_buffer, &indices, &flat_program, &uniforms, target.draw(&vertex_buffer, &indices, &flat_program, &uniforms, &params).unwrap();
&Default::default()).unwrap();
model.draw(&mut target, &cube_program, &uniforms); model.draw(&mut target, &cube_program, &uniforms);
target.finish().unwrap(); target.finish().unwrap();

View File

@ -1,6 +1,6 @@
extern crate gltf; extern crate gltf;
use glium::{ VertexBuffer, IndexBuffer }; use glium::{ VertexBuffer, IndexBuffer, Program };
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Vertex { struct Vertex {