Skip to content

Commit

Permalink
Support and allow negative animation speed
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Jan 14, 2024
1 parent a84a326 commit 2e26c05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 8 additions & 2 deletions neothesia-core/src/render/waterfall/pipeline/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ struct VertexOutput {
@vertex
fn vs_main(vertex: Vertex, note: NoteInstance) -> VertexOutput {
let speed = time_uniform.speed / view_uniform.scale;
let size = vec2<f32>(note.size.x, note.size.y * speed);
let size = vec2<f32>(note.size.x, note.size.y * abs(speed));

let keyboard_start_y = view_uniform.size.y - view_uniform.size.y / 5.0;
let y = keyboard_start_y - size.y / 2.0;
let pos = vec2<f32>(note.n_position.x, y) - vec2<f32>(0.0, size.y / 2.0);
var pos = vec2<f32>(note.n_position.x, y) - vec2<f32>(0.0, size.y / 2.0);

// If notes are falling from down to top, we need to adjust the position,
// as their start is on top of the quad rather than down
if speed < 0.0 {
pos.y += size.y;
}

let offset = vec2<f32>(0.0, -(note.n_position.y - time_uniform.time) * speed);

Expand Down
9 changes: 8 additions & 1 deletion neothesia/src/scene/playing_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,16 @@ fn handle_settings_input(

if key == NamedKey::PageUp {
target.config.animation_speed += amount;
// 0.0 is invalid speed, let's skip it and jump to positive
if target.config.animation_speed == 0.0 {
target.config.animation_speed += amount;
}
} else {
target.config.animation_speed -= amount;
target.config.animation_speed = target.config.animation_speed.max(100.0);
// 0.0 is invalid speed, let's skip it and jump to negative
if target.config.animation_speed == 0.0 {
target.config.animation_speed -= amount;
}
}

waterfall
Expand Down

0 comments on commit 2e26c05

Please sign in to comment.