diff --git a/src/bin/render_lines_gui.rs b/src/bin/render_lines_gui.rs index 8464df0..abdcaed 100644 --- a/src/bin/render_lines_gui.rs +++ b/src/bin/render_lines_gui.rs @@ -33,7 +33,7 @@ struct Model { egui: Egui, // socket for receiving points zmq: Socket, - current_points: LaserPoints, // a copy for the drawing renderer + current_lines: RenderableLines, // a copy for the drawing renderer last_update: Instant, // dimming_factor: f32, } @@ -128,14 +128,14 @@ fn zmq_receive(model: &mut Model) { for laser_stream in (&model.laser_streams).into_iter() { // let lines = get_laser_lines(version); - let points: LaserPoints = (&lines).into(); + let lines: RenderableLines = lines.clone(); laser_stream.send(|laser| { - let laser_points: LaserPoints = points; - laser.current_points = laser_points; + let laser_lines: RenderableLines = lines; + laser.current_lines = laser_lines; }).unwrap(); } - model.current_points = (&lines).into(); + model.current_lines = lines; model.last_update = Instant::now(); } @@ -217,7 +217,7 @@ fn model(app: &App) -> Model { // egui.ctx().set_fonts(fonts()); egui.ctx().set_style(style()); - let current_points = Vec::new(); + let current_lines = RenderableLines::new(); //Vec::new(); Model { laser_api, @@ -227,7 +227,7 @@ fn model(app: &App) -> Model { dac_rx, egui, zmq, - current_points, + current_lines: current_lines, last_update: Instant::now(), // dimming_factor: 1., } @@ -252,7 +252,7 @@ const LASER_H: Mat3 = python_cv_h_into_mat3(TMP_PYTHON_LASER_H); fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){ - let points = model.current_points.clone(); + let points: LaserPoints = (&model.current_lines).into(); let pointno = points.len(); let mut new_points = Vec::new(); @@ -374,7 +374,7 @@ fn update(_app: &App, model: &mut Model, update: Update) { ui.separator(); - ui.add(egui::Label::new(format!("Laser {}", model.current_points.len()))); + ui.add(egui::Label::new(format!("Lines {}", model.current_lines.lines.len()))); ui.heading("Laser Settings"); @@ -513,7 +513,10 @@ fn view_line_canvas(app: &App, model: &Model, frame: Frame) { let thickness = 2.0; // let hz = ((app.mouse.x + win.right()) / win.w()).powi(4) * 1000.0; - let vertices = model.current_points.iter().map(|p| { + // TODO draw distinct lines, using euclid for scale + let points: LaserPoints = (&model.current_lines).into(); + + let vertices = points.iter().map(|p| { let color = srgba(p.color[0], p.color[1], p.color[2], 1.0); let pos = [p.position[0] * scale, p.position[1] * -scale]; diff --git a/src/bin/render_tracks.rs b/src/bin/render_tracks.rs index 72eb70c..598e334 100644 --- a/src/bin/render_tracks.rs +++ b/src/bin/render_tracks.rs @@ -133,7 +133,7 @@ fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){ // false => trap::shapes::ARE_YOU_SURE, // }; - let points = model.current_points.clone(); + let points = model.current_lines.clone(); let mut new_points = Vec::new(); for point in points.into_iter() { diff --git a/src/trap/laser.rs b/src/trap/laser.rs index 7cd2eb6..f851308 100644 --- a/src/trap/laser.rs +++ b/src/trap/laser.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use nannou_laser as laser; use std::time::Instant; -use super::tracks::LaserPoints; +use super::tracks::{LaserPoints, RenderableLines}; pub const TMP_PYTHON_LASER_H: [[f32;3];3] = [[ 2.47442963e+02, -7.01714050e+01, -9.71749119e+01], [ 1.02328119e+01, 1.47185254e+02, 1.96295638e+02], @@ -32,7 +32,7 @@ pub fn apply_homography_matrix(h: Mat3, p: &[f32; 2]) -> [f32; 2]{ #[derive(Resource, Clone)] pub struct LaserModel{ pub t: Instant, // register start time, so that animations can be moving - pub current_points: LaserPoints, + pub current_lines: RenderableLines, pub dimming: f32, } @@ -40,7 +40,7 @@ impl LaserModel{ pub fn new() -> Self{ Self{ t: Instant::now(), - current_points: Vec::new(), + current_lines: RenderableLines::new(), dimming: 0.3 } } diff --git a/src/trap/tracks.rs b/src/trap/tracks.rs index b209424..58215cc 100644 --- a/src/trap/tracks.rs +++ b/src/trap/tracks.rs @@ -40,6 +40,7 @@ pub struct Track { } // coordinates in world space. To be converted to laser::Point or a drawable point +// TODO migrate to euclid::Point2D #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RenderablePoint{ pub position: Vec2, @@ -97,6 +98,7 @@ impl From<&Track> for RenderableLines{ } } +// TODO migrate to euclid::Point2D pub type LaserPoints = Vec; impl From<&RenderableLines> for LaserPoints { diff --git a/src/trap/zmqplugin.rs b/src/trap/zmqplugin.rs index ab3a88c..adfa4b1 100644 --- a/src/trap/zmqplugin.rs +++ b/src/trap/zmqplugin.rs @@ -77,10 +77,10 @@ fn receive_zmq_lines( for (laser_api, mut laser_timer) in lasers.iter_mut() { laser_timer.timer.tick(time.delta()); // let lines = get_laser_lines(version); - let points: LaserPoints = (&lines).into(); + let lines: RenderableLines = lines.clone(); laser_api.laser_stream.send(|laser| { - let laser_points: LaserPoints = points; - laser.current_points = laser_points; + let laser_lines: RenderableLines = lines; + laser.current_lines = laser_lines; }).unwrap(); } }