add mirror_y feature
This commit is contained in:
parent
1e3a92000a
commit
56a9480f0a
4 changed files with 85 additions and 16 deletions
|
@ -6,7 +6,9 @@ use {
|
|||
pub struct Controller {
|
||||
pub tbegin: Instant,
|
||||
pub transition_begin: Instant,
|
||||
pub last_tap: Instant
|
||||
pub last_tap: Instant,
|
||||
|
||||
pub ctrl: bool
|
||||
}
|
||||
|
||||
impl Controller {
|
||||
|
@ -14,7 +16,8 @@ impl Controller {
|
|||
Controller {
|
||||
tbegin: Instant::now(),
|
||||
transition_begin: Instant::now(),
|
||||
last_tap: Instant::now()
|
||||
last_tap: Instant::now(),
|
||||
ctrl: false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,11 +25,68 @@ impl Controller {
|
|||
&mut self,
|
||||
event: winit::event::KeyEvent,
|
||||
inputs: &mut crate::inputs::Inputs,
|
||||
) {
|
||||
setup: &mut crate::setup::LightingSetup
|
||||
) {
|
||||
if event.state == winit::event::ElementState::Released {
|
||||
match event.logical_key {
|
||||
winit::keyboard::Key::Named(
|
||||
winit::keyboard::NamedKey::Control
|
||||
) => {
|
||||
eprintln!("released control");
|
||||
self.ctrl = false;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else
|
||||
if event.state == winit::event::ElementState::Pressed {
|
||||
match event.logical_key {
|
||||
winit::keyboard::Key::Character(c) => {
|
||||
eprintln!("pressed {}", c);
|
||||
winit::keyboard::Key::Named(
|
||||
winit::keyboard::NamedKey::Control
|
||||
) => {
|
||||
eprintln!("pressed control");
|
||||
self.ctrl = true;
|
||||
}
|
||||
winit::keyboard::Key::Character(c) => {
|
||||
eprintln!("pressed {}", c);
|
||||
|
||||
if self.ctrl {
|
||||
if c.is_ascii() {
|
||||
match &c[0..1] {
|
||||
"0" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(0) {
|
||||
eprintln!("toggle mirror_y of fixture 0");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"1" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(1) {
|
||||
eprintln!("toggle mirror_y of fixture 1");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"2" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(2) {
|
||||
eprintln!("toggle mirror_y of fixture 2");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"3" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(3) {
|
||||
eprintln!("toggle mirror_y of fixture 3");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"4" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(4) {
|
||||
eprintln!("toggle mirror_y of fixture 4");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if c.is_ascii() {
|
||||
match &c[0..1] {
|
||||
"x" => {
|
||||
|
@ -79,6 +139,7 @@ impl Controller {
|
|||
|
||||
_=>{}
|
||||
}
|
||||
}
|
||||
|
||||
eprintln!("--------------");
|
||||
eprintln!("updated inputs:\n {:?}", inputs);
|
||||
|
|
|
@ -15,19 +15,21 @@ pub struct Fixture {
|
|||
pub position: Vector2<f32>,
|
||||
pub rotation: f32,
|
||||
pub scale: f32,
|
||||
pub mirror_y: bool,
|
||||
pub brightness: f32,
|
||||
pub buffer: Vec< Rgb<u8> >,
|
||||
pub driver: Option<Box<dyn FixtureDriver>>
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
pub fn new_stripe() -> Self {
|
||||
pub fn new_stripe(mirror_y: bool) -> Self {
|
||||
let mut fixture = Fixture {
|
||||
resolution: Vector2::new(1, 72),
|
||||
position: Vector2::new(0.0, 0.0),
|
||||
rotation: 0.0,
|
||||
scale: 0.015,
|
||||
brightness: 0.8,
|
||||
mirror_y,
|
||||
buffer: Vec::new(),
|
||||
driver: None
|
||||
};
|
||||
|
@ -43,6 +45,7 @@ impl Fixture {
|
|||
position: Vector2::new(0.0, 0.0),
|
||||
rotation: 0.0,
|
||||
scale: 0.03,
|
||||
mirror_y: false,
|
||||
brightness: 0.8,
|
||||
buffer: Vec::new(),
|
||||
driver: None
|
||||
|
@ -76,6 +79,11 @@ impl Fixture {
|
|||
let gpos = self.get_global_pos(&Vector2::new(xi, yi));
|
||||
let col = view.get(&gpos);
|
||||
|
||||
let yi = if self.mirror_y {
|
||||
self.resolution.y - 1 - yi
|
||||
} else {
|
||||
yi
|
||||
};
|
||||
let index = xi + yi * self.resolution.x;
|
||||
self.buffer[index as usize] = Rgb::new(
|
||||
(col.red() * 255.0 * self.brightness) as u8,
|
||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -58,20 +58,20 @@ async fn main() {
|
|||
Fixture::new_matrix(),
|
||||
// .with_driver( Box::new(MatrixTcpDriver::new("ip:port")) ),
|
||||
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone())) )
|
||||
Fixture::new_stripe(false)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone())) )
|
||||
.offset(Vector2::new(-0.5, 0.0)),
|
||||
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) )
|
||||
Fixture::new_stripe(true)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) )
|
||||
.offset(Vector2::new(-0.4, 0.0)),
|
||||
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) )
|
||||
Fixture::new_stripe(false)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) )
|
||||
.offset(Vector2::new(0.4, 0.0)),
|
||||
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone())))
|
||||
Fixture::new_stripe(true)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone())))
|
||||
.offset(Vector2::new(0.5, 0.0))
|
||||
],
|
||||
|
||||
|
@ -159,7 +159,7 @@ async fn main() {
|
|||
event: winit::event::WindowEvent::KeyboardInput{ device_id, event, is_synthetic }
|
||||
} => {
|
||||
controller.handle_key(
|
||||
event, &mut inputs
|
||||
event, &mut inputs, &mut lighting_setup
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use {
|
|||
};
|
||||
|
||||
pub struct LightingSetup {
|
||||
fixtures: Vec<Fixture>,
|
||||
pub fixtures: Vec<Fixture>,
|
||||
t: Arc<RwLock<Duration>>,
|
||||
|
||||
animation: Box<dyn Animation>
|
||||
|
|
Loading…
Reference in a new issue