tweaked camera based on canvas. workable, not great.

This commit is contained in:
Dustin Carlino 2019-01-22 16:52:29 -08:00
parent af7596f9a5
commit fb7a809892
6 changed files with 21 additions and 15 deletions

View File

@ -65,8 +65,8 @@
## Switch to OpenGL (for speed)
- get playground_gui running
- cant see anything
- get things running again
- simplify camera math drastically
- render text
- calling draw way too frequently

View File

@ -45,7 +45,7 @@ impl Plugin for Legend {
// TODO The negation and reasoning about the zoom is annoying. I want to say something like
// "Make top_left the origin, zoom 10."
let zoom = 10.0;
let old_ctx = g.fork(
g.fork(
Pt2D::new(-self.top_left.x / zoom, -self.top_left.y / zoom),
zoom,
);
@ -92,6 +92,6 @@ impl Plugin for Legend {
ScreenPt::new(self.top_left.x + 20.0, self.top_left.y + 110.0),
);
g.unfork(old_ctx);
g.unfork();
}
}

View File

@ -328,7 +328,7 @@ pub fn draw_signal_diagram(
let total_screen_width = (intersection_width * zoom) + label_length + 10.0;
let x1_screen = ctx.canvas.window_width - total_screen_width;
let old_ctx = g.fork_screenspace();
g.fork_screenspace();
g.draw_polygon(
ctx.cs
.get_def("signal editor panel", Color::BLACK.alpha(0.95)),
@ -377,7 +377,7 @@ pub fn draw_signal_diagram(
);
}
g.unfork(old_ctx);
g.unfork();
}
fn find_pts_between(pts: &Vec<Pt2D>, start: Pt2D, end: Pt2D) -> Option<Vec<Pt2D>> {

View File

@ -3,7 +3,7 @@ use std::f32;
pub struct CameraState {
aspect_ratio: f32,
position: (f32, f32, f32),
pub position: (f32, f32, f32),
direction: (f32, f32, f32),
moving_up: bool,

View File

@ -55,7 +55,12 @@ impl Event {
glutin::WindowEvent::CursorMoved { position, .. } => {
Some(Event::MouseMovedTo(ScreenPt::new(position.x, position.y)))
}
//glutin::WindowEvent::MouseWheel { delta, .. } => Event::MouseWheelScroll(),
glutin::WindowEvent::MouseWheel { delta, .. } => match delta {
glutin::MouseScrollDelta::LineDelta(_, dy) => {
Some(Event::MouseWheelScroll(dy as f64))
}
_ => None,
},
glutin::WindowEvent::Resized(size) => {
Some(Event::WindowResized(size.width, size.height))
}

View File

@ -124,7 +124,13 @@ impl<'a> GfxCtx<'a> {
};
let mut camera = CameraState::new();
// TODO setup camera based on canvas
// TODO that y inversion!
// TODO that arbitraryish Z position!
camera.position = (
canvas.cam_x as f32,
-canvas.cam_y as f32,
(500.0 / canvas.cam_zoom) as f32,
);
let uniforms = uniform! {
persp_matrix: camera.get_perspective(),
view_matrix: camera.get_view(),
@ -143,12 +149,7 @@ impl<'a> GfxCtx<'a> {
// TODO Canvas doesn't understand this change, so things like text drawing that use
// map_to_screen will just be confusing.
pub fn fork(&mut self, top_left: Pt2D, zoom: f64) {
let mut camera = CameraState::new();
// TODO setup camera based on values above
self.uniforms = uniform! {
persp_matrix: camera.get_perspective(),
view_matrix: camera.get_view(),
};
// TODO set uniforms based on values above
}
pub fn fork_screenspace(&mut self) {