Skip to content

Commit 43bea0d

Browse files
Fix y-shift, and shift getting stuck at the end
1 parent db7dff2 commit 43bea0d

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/pixel_shift.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,35 @@ impl PixelShiftManager {
7373
match self.state {
7474
ShiftState::Normal => {
7575
self.state = ShiftState::ShiftingSubpixel;
76-
self.subpixel_progress = if self.direction == 1 { 0.0 } else { 1.0 };
7776
},
7877
ShiftState::ShiftingSubpixel => {
7978
let shift_by = ANIMATION_INTERVAL_MS as f64 / ANIMATION_DURATION_MS as f64;
8079
self.subpixel_progress += shift_by * self.direction as f64;
81-
if self.subpixel_progress <= 0.01 || self.subpixel_progress >= 0.99 {
80+
if self.subpixel_progress <= -0.99 || self.subpixel_progress >= 0.99 {
8281
self.pixel_progress = (self.direction + self.pixel_progress as i64) as u64;
8382
self.state = ShiftState::Normal;
8483
self.subpixel_progress = 0.0;
85-
}
86-
if self.pixel_progress == 0 || self.pixel_progress >= PIXEL_SHIFT_WIDTH_PX {
87-
self.state = ShiftState::WaitingAtEnd;
88-
self.direction = -self.direction;
84+
if self.pixel_progress == 0 || self.pixel_progress >= PIXEL_SHIFT_WIDTH_PX {
85+
self.state = ShiftState::WaitingAtEnd;
86+
self.direction = -self.direction;
87+
dbg!(self.direction);
88+
}
8989
}
9090
},
9191
ShiftState::WaitingAtEnd => {
9292
self.state = ShiftState::Normal;
93+
self.subpixel_progress = 0.0;
9394
}
9495
}
9596
(true, wait_for_state(self.state))
9697
}
9798

9899
pub fn get(&self) -> (f64, f64) {
99100
let x_progress = self.pixel_progress as f64 + self.subpixel_progress;
100-
let y_progress = (x_progress + self.y_constant) % PIXEL_SHIFT_HEIGHT_PX as f64;
101+
let mut y_progress = (x_progress + self.y_constant) % (PIXEL_SHIFT_HEIGHT_PX * 2) as f64;
102+
if y_progress > PIXEL_SHIFT_HEIGHT_PX as f64 {
103+
y_progress = (PIXEL_SHIFT_HEIGHT_PX * 2) as f64 - y_progress;
104+
}
101105
(x_progress - (PIXEL_SHIFT_WIDTH_PX / 2) as f64, y_progress - (PIXEL_SHIFT_HEIGHT_PX / 2) as f64)
102106
}
103107
}

0 commit comments

Comments
 (0)