More complicated model, rotating
This commit is contained in:
parent
3b0292dbc7
commit
c8a030de46
BIN
Lantern.glb
Normal file
BIN
Lantern.glb
Normal file
Binary file not shown.
25
src/main.rs
25
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::<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::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! {
|
||||
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();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
extern crate gltf;
|
||||
|
||||
use glium::{ VertexBuffer, IndexBuffer };
|
||||
use glium::{ VertexBuffer, IndexBuffer, Program };
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Vertex {
|
||||
|
Loading…
Reference in New Issue
Block a user