Refactor for more flexible coordinates
This commit is contained in:
parent
1c040ef55c
commit
8d15e67882
5 changed files with 22 additions and 17 deletions
|
@ -33,7 +33,7 @@ struct Model {
|
||||||
egui: Egui,
|
egui: Egui,
|
||||||
// socket for receiving points
|
// socket for receiving points
|
||||||
zmq: Socket,
|
zmq: Socket,
|
||||||
current_points: LaserPoints, // a copy for the drawing renderer
|
current_lines: RenderableLines, // a copy for the drawing renderer
|
||||||
last_update: Instant,
|
last_update: Instant,
|
||||||
// dimming_factor: f32,
|
// dimming_factor: f32,
|
||||||
}
|
}
|
||||||
|
@ -128,14 +128,14 @@ fn zmq_receive(model: &mut Model) {
|
||||||
|
|
||||||
for laser_stream in (&model.laser_streams).into_iter() {
|
for laser_stream in (&model.laser_streams).into_iter() {
|
||||||
// let lines = get_laser_lines(version);
|
// let lines = get_laser_lines(version);
|
||||||
let points: LaserPoints = (&lines).into();
|
let lines: RenderableLines = lines.clone();
|
||||||
laser_stream.send(|laser| {
|
laser_stream.send(|laser| {
|
||||||
let laser_points: LaserPoints = points;
|
let laser_lines: RenderableLines = lines;
|
||||||
laser.current_points = laser_points;
|
laser.current_lines = laser_lines;
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
model.current_points = (&lines).into();
|
model.current_lines = lines;
|
||||||
model.last_update = Instant::now();
|
model.last_update = Instant::now();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ fn model(app: &App) -> Model {
|
||||||
// egui.ctx().set_fonts(fonts());
|
// egui.ctx().set_fonts(fonts());
|
||||||
egui.ctx().set_style(style());
|
egui.ctx().set_style(style());
|
||||||
|
|
||||||
let current_points = Vec::new();
|
let current_lines = RenderableLines::new(); //Vec::new();
|
||||||
|
|
||||||
Model {
|
Model {
|
||||||
laser_api,
|
laser_api,
|
||||||
|
@ -227,7 +227,7 @@ fn model(app: &App) -> Model {
|
||||||
dac_rx,
|
dac_rx,
|
||||||
egui,
|
egui,
|
||||||
zmq,
|
zmq,
|
||||||
current_points,
|
current_lines: current_lines,
|
||||||
last_update: Instant::now(),
|
last_update: Instant::now(),
|
||||||
// dimming_factor: 1.,
|
// 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){
|
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 pointno = points.len();
|
||||||
|
|
||||||
let mut new_points = Vec::new();
|
let mut new_points = Vec::new();
|
||||||
|
@ -374,7 +374,7 @@ fn update(_app: &App, model: &mut Model, update: Update) {
|
||||||
|
|
||||||
ui.separator();
|
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");
|
ui.heading("Laser Settings");
|
||||||
|
|
||||||
|
@ -513,7 +513,10 @@ fn view_line_canvas(app: &App, model: &Model, frame: Frame) {
|
||||||
let thickness = 2.0;
|
let thickness = 2.0;
|
||||||
// let hz = ((app.mouse.x + win.right()) / win.w()).powi(4) * 1000.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 color = srgba(p.color[0], p.color[1], p.color[2], 1.0);
|
||||||
|
|
||||||
let pos = [p.position[0] * scale, p.position[1] * -scale];
|
let pos = [p.position[0] * scale, p.position[1] * -scale];
|
||||||
|
|
|
@ -133,7 +133,7 @@ fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){
|
||||||
// false => trap::shapes::ARE_YOU_SURE,
|
// false => trap::shapes::ARE_YOU_SURE,
|
||||||
// };
|
// };
|
||||||
|
|
||||||
let points = model.current_points.clone();
|
let points = model.current_lines.clone();
|
||||||
|
|
||||||
let mut new_points = Vec::new();
|
let mut new_points = Vec::new();
|
||||||
for point in points.into_iter() {
|
for point in points.into_iter() {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use bevy::prelude::*;
|
||||||
use nannou_laser as laser;
|
use nannou_laser as laser;
|
||||||
use std::time::Instant;
|
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],
|
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],
|
[ 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)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct LaserModel{
|
pub struct LaserModel{
|
||||||
pub t: Instant, // register start time, so that animations can be moving
|
pub t: Instant, // register start time, so that animations can be moving
|
||||||
pub current_points: LaserPoints,
|
pub current_lines: RenderableLines,
|
||||||
pub dimming: f32,
|
pub dimming: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ impl LaserModel{
|
||||||
pub fn new() -> Self{
|
pub fn new() -> Self{
|
||||||
Self{
|
Self{
|
||||||
t: Instant::now(),
|
t: Instant::now(),
|
||||||
current_points: Vec::new(),
|
current_lines: RenderableLines::new(),
|
||||||
dimming: 0.3
|
dimming: 0.3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ pub struct Track {
|
||||||
}
|
}
|
||||||
|
|
||||||
// coordinates in world space. To be converted to laser::Point or a drawable point
|
// coordinates in world space. To be converted to laser::Point or a drawable point
|
||||||
|
// TODO migrate to euclid::Point2D<f32, WorldSpace>
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct RenderablePoint{
|
pub struct RenderablePoint{
|
||||||
pub position: Vec2,
|
pub position: Vec2,
|
||||||
|
@ -97,6 +98,7 @@ impl From<&Track> for RenderableLines{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO migrate to euclid::Point2D<f32, LaserSpace>
|
||||||
pub type LaserPoints = Vec<laser::Point>;
|
pub type LaserPoints = Vec<laser::Point>;
|
||||||
|
|
||||||
impl From<&RenderableLines> for LaserPoints {
|
impl From<&RenderableLines> for LaserPoints {
|
||||||
|
|
|
@ -77,10 +77,10 @@ fn receive_zmq_lines(
|
||||||
for (laser_api, mut laser_timer) in lasers.iter_mut() {
|
for (laser_api, mut laser_timer) in lasers.iter_mut() {
|
||||||
laser_timer.timer.tick(time.delta());
|
laser_timer.timer.tick(time.delta());
|
||||||
// let lines = get_laser_lines(version);
|
// let lines = get_laser_lines(version);
|
||||||
let points: LaserPoints = (&lines).into();
|
let lines: RenderableLines = lines.clone();
|
||||||
laser_api.laser_stream.send(|laser| {
|
laser_api.laser_stream.send(|laser| {
|
||||||
let laser_points: LaserPoints = points;
|
let laser_lines: RenderableLines = lines;
|
||||||
laser.current_points = laser_points;
|
laser.current_lines = laser_lines;
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue