diff --git a/src/bin/wireframe/main.rs b/src/bin/wireframe/main.rs index eac3a61..ab4d3f4 100644 --- a/src/bin/wireframe/main.rs +++ b/src/bin/wireframe/main.rs @@ -75,6 +75,7 @@ fn main() { let vertex_buffer = VertexBuffer::new(&display, &shape).unwrap(); let mut cur_pos = vec2(0., 0.); + let mut cam_pos = DragCtl::new(Vec3::ZERO); let mut cam_rot = DragCtl::new(Quat::IDENTITY); #[allow(deprecated)] @@ -87,7 +88,8 @@ fn main() { * std::f32::consts::SQRT_2; let proj = make_proj_matrix(vec3(size.x, size.y, 2.), (0.125, 1024.125)); - let view = Mat4::from_quat(cam_rot.state()); + let view = + Mat4::from_quat(cam_rot.state()) * Mat4::from_translation(cam_pos.state()); let mut target = display.draw(); target.clear_color(0.0, 0.0, 0.2, 1.0); @@ -114,7 +116,8 @@ fn main() { state, button, } => match button { - winit::event::MouseButton::Left => cam_rot.on_button(cur_pos, state), + winit::event::MouseButton::Left => cam_pos.on_button(cur_pos, state), + winit::event::MouseButton::Right => cam_rot.on_button(cur_pos, state), _ => {} }, @@ -124,10 +127,14 @@ fn main() { } => { let size = window.inner_size(); let size = vec2(size.width as f32, size.height as f32); - cur_pos = vec2(position.x as f32, position.y as f32) / size; + cur_pos = vec2(position.x as f32, position.y as f32) / size.length(); + cam_pos.on_move(cur_pos, |init, off| { + window.request_redraw(); + init + 4. * (cam_rot.state().inverse() * vec3(off.x, -off.y, 0.)) + }); cam_rot.on_move(cur_pos, |init, off| { window.request_redraw(); - Quat::from_euler(glam::EulerRot::YXZ, off.x, off.y, 0.) * init + Quat::from_euler(glam::EulerRot::YXZ, 5. * off.x, 5. * off.y, 0.) * init }); }