Press enter to log the camera position

This commit is contained in:
Thomas Forgione 2018-07-10 17:43:37 +02:00
parent 98d5b3c5e4
commit 3172a0c58e
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 41 additions and 4 deletions

View File

@ -14,9 +14,12 @@ use glium::Display;
use glium::glutin;
use glium::glutin::{EventsLoop, WindowBuilder};
use glium::glutin::Event;
use glium::glutin::WindowEvent;
use glium::glutin::VirtualKeyCode;
use glium::glutin::{
Event,
WindowEvent,
VirtualKeyCode,
ElementState,
};
use model_converter::scene::Scene;
use model_converter::math::bounding_box::BoundingBox3;
@ -78,6 +81,10 @@ fn main() {
}
}
let center = (bbox.min() + bbox.max()) / 2.0;
let center = Vector3::new(center.x() as f32, center.y() as f32, center.z() as f32);
let size = (bbox.max() - bbox.min()).norm() as f32;
let mut events_loop = EventsLoop::new();
let window = WindowBuilder::new().with_visibility(false);
let context = glutin::ContextBuilder::new().with_depth_buffer(24);
@ -151,11 +158,41 @@ fn main() {
Event::WindowEvent {
event: WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape), ..
virtual_keycode: Some(VirtualKeyCode::Escape),
state: ElementState::Pressed, ..
}, ..
}, ..
} => closed = true,
// Enter key
Event::WindowEvent {
event: WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Return),
state: ElementState::Pressed, ..
}, ..
}, ..
} => {
// Go back in world coordinates
let position = camera.position * size as f32;
let position = position + center;
let target = camera.target * size as f32;
let target = target + center;
let up = camera.up;
println!("Camera:");
println!("\tPosition: ({}, {}, {})",
position.x(), position.y(), position.z());
println!("\tTarget: ({}, {}, {})",
target.x(), target.y(), target.z());
println!("\tUp: ({}, {}, {})",
up.x(), up.y(), up.z());
}
_ => (),
}
});