Changing text
This commit is contained in:
parent
f20025c513
commit
9cc11bd1d3
3 changed files with 56 additions and 27 deletions
77
src/main.rs
77
src/main.rs
|
@ -1,3 +1,4 @@
|
||||||
|
use bevy::ecs::system::SystemState;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::render::view::RenderLayers;
|
use bevy::render::view::RenderLayers;
|
||||||
use bevy::window::WindowResolution;
|
use bevy::window::WindowResolution;
|
||||||
|
@ -5,6 +6,8 @@ use bevy_nannou::prelude::properties::spatial::position;
|
||||||
use bevy_nannou::prelude::*;
|
use bevy_nannou::prelude::*;
|
||||||
use bevy_nannou::NannouPlugin;
|
use bevy_nannou::NannouPlugin;
|
||||||
use iyes_perf_ui::prelude::*;
|
use iyes_perf_ui::prelude::*;
|
||||||
|
use nannou_laser::point::Rgb;
|
||||||
|
use trap::shapes::PositionAndIntensity;
|
||||||
use trap::zmqplugin::ZmqPlugin;
|
use trap::zmqplugin::ZmqPlugin;
|
||||||
// use iyes_perf_ui::PerfUiPlugin;
|
// use iyes_perf_ui::PerfUiPlugin;
|
||||||
|
|
||||||
|
@ -24,6 +27,7 @@ fn main() {
|
||||||
// .add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin)
|
// .add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin)
|
||||||
// .add_plugins(PerfUiPlugin)
|
// .add_plugins(PerfUiPlugin)
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
|
.add_systems(Startup, setup_laser)
|
||||||
.add_systems(Update, update)
|
.add_systems(Update, update)
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +43,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LaserModel{
|
struct LaserModel{
|
||||||
t: Instant
|
t: Instant, // register start time, so that animations can be moving
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
@ -48,25 +52,12 @@ struct LaserApi{
|
||||||
laser_stream: laser::FrameStream<LaserModel>,
|
laser_stream: laser::FrameStream<LaserModel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Because of world.insert_non_send_resource, this is an exclusive system
|
||||||
|
// see: https://bevy-cheatbook.github.io/programming/exclusive.html
|
||||||
|
fn setup_laser(mut commands: Commands) {
|
||||||
|
|
||||||
fn setup(mut commands: Commands) {
|
// laser works on non-exclusive system (like the normal setup()), _but_ world
|
||||||
// Spawn a camera for our main window
|
// is needed in the laser callback
|
||||||
commands.spawn((render::NannouCamera, RenderLayers::none()));
|
|
||||||
|
|
||||||
// let path = "your_future_points_test.json";
|
|
||||||
// let file = File::open(path)?;
|
|
||||||
// let data = fs::read_to_string(path).expect("Unable to read file");
|
|
||||||
// let reader = BufReader::new(file);
|
|
||||||
|
|
||||||
|
|
||||||
// let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
|
|
||||||
// let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
|
|
||||||
// let max = res[0].iter().cloned().fold(0./0., f64::max);
|
|
||||||
|
|
||||||
// println!("{}",res);
|
|
||||||
|
|
||||||
// let u = serde_json::from_reader(reader)?;
|
|
||||||
|
|
||||||
|
|
||||||
// Initialise the state that we want to live on the laser thread and spawn the stream.
|
// Initialise the state that we want to live on the laser thread and spawn the stream.
|
||||||
let laser_model = LaserModel {
|
let laser_model = LaserModel {
|
||||||
|
@ -84,28 +75,54 @@ fn setup(mut commands: Commands) {
|
||||||
laser_stream,
|
laser_stream,
|
||||||
};
|
};
|
||||||
commands.spawn(api);
|
commands.spawn(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup(mut commands: Commands) {
|
||||||
|
// Spawn a camera for our main window
|
||||||
|
commands.spawn(render::NannouCamera);
|
||||||
|
|
||||||
|
// let path = "your_future_points_test.json";
|
||||||
|
// let file = File::open(path)?;
|
||||||
|
// let data = fs::read_to_string(path).expect("Unable to read file");
|
||||||
|
// let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
|
||||||
|
// let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
|
||||||
|
// let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
|
||||||
|
// let max = res[0].iter().cloned().fold(0./0., f64::max);
|
||||||
|
|
||||||
|
// println!("{}",res);
|
||||||
|
|
||||||
|
// let u = serde_json::from_reader(reader)?;
|
||||||
|
|
||||||
|
|
||||||
// create a simple Perf UI with default settings
|
// create a simple Perf UI with default settings
|
||||||
// and all entries provided by the crate:
|
// and all entries provided by the crate:
|
||||||
// commands.spawn(PerfUiDefaultEntries::default());
|
// commands.spawn(PerfUiDefaultEntries::default());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text2points(position_and_intensity: [f32;3]) -> laser::Point{
|
|
||||||
|
fn text2points_with_color(position_and_intensity: PositionAndIntensity, color: Rgb) -> laser::Point{
|
||||||
|
let used_color = color.map(|v| v * position_and_intensity[2]);
|
||||||
|
let p = [position_and_intensity[0], -position_and_intensity[1]];
|
||||||
|
laser::Point::new(p, color)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn text2points(position_and_intensity: PositionAndIntensity) -> laser::Point{
|
||||||
let color = match position_and_intensity[2] {
|
let color = match position_and_intensity[2] {
|
||||||
1.0 => [1.0; 3],
|
1.0 => [1.0; 3],
|
||||||
0.0 => [0.0; 3],
|
0.0 => [0.0; 3],
|
||||||
_ => [1.0; 3] // TODO add provided color
|
_ => [1.0; 3] // TODO add provided color
|
||||||
};
|
};
|
||||||
// let p = &position_and_intensity[0..2];
|
|
||||||
let p = [position_and_intensity[0], -position_and_intensity[1]];
|
let p = [position_and_intensity[0], -position_and_intensity[1]];
|
||||||
return laser::Point::new(p, color)
|
laser::Point::new(p, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn laser_frame_producer(_laser: &mut LaserModel, frame: &mut laser::Frame){
|
fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){
|
||||||
|
|
||||||
|
let dt = model.t.elapsed().as_millis();
|
||||||
let dt = _laser.t.elapsed().as_millis();
|
|
||||||
let use_second = (dt % 1000) > 500;
|
let use_second = (dt % 1000) > 500;
|
||||||
|
|
||||||
let positions = match use_second {
|
let positions = match use_second {
|
||||||
|
@ -133,6 +150,7 @@ fn update(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
keys: Res<ButtonInput<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
draws: Query<(&Draw, Option<&WindowColor>)>,
|
draws: Query<(&Draw, Option<&WindowColor>)>,
|
||||||
|
lasers: Query<&LaserApi>,
|
||||||
mut count: Local<usize>,
|
mut count: Local<usize>,
|
||||||
) {
|
) {
|
||||||
if keys.just_pressed(KeyCode::Space) {
|
if keys.just_pressed(KeyCode::Space) {
|
||||||
|
@ -169,5 +187,14 @@ fn update(
|
||||||
}
|
}
|
||||||
|
|
||||||
draw.ellipse().color(LIGHT_GRAY).w_h(100.0, 100.0);
|
draw.ellipse().color(LIGHT_GRAY).w_h(100.0, 100.0);
|
||||||
|
|
||||||
|
for (laser_api) in lasers.iter() {
|
||||||
|
draw.text("test")
|
||||||
|
.color(BLACK)
|
||||||
|
// .glyph_colors(glyph_colors)
|
||||||
|
.font_size(24);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
|
@ -22,6 +22,7 @@ fn setup_zmq(world: &mut World, params: &mut SystemState<Res<ZmqSettings>>) {
|
||||||
let filter = &settings.filter; //"msgs";
|
let filter = &settings.filter; //"msgs";
|
||||||
assert!(subscriber.set_subscribe(filter.as_bytes()).is_ok());
|
assert!(subscriber.set_subscribe(filter.as_bytes()).is_ok());
|
||||||
world.insert_non_send_resource(subscriber);
|
world.insert_non_send_resource(subscriber);
|
||||||
|
// world.query::<>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_zmq_messsages(mut commands: Commands, subscriber: NonSend<Socket>, mut tracks_q: Query<&mut Track>) {
|
fn receive_zmq_messsages(mut commands: Commands, subscriber: NonSend<Socket>, mut tracks_q: Query<&mut Track>) {
|
||||||
|
|
Loading…
Reference in a new issue