Animation sequence

This commit is contained in:
Synthasmagoria 2026-08-25 14:19:28 +02:00
commit 7b980a699a
2 changed files with 20 additions and 13 deletions

View file

@ -105,10 +105,6 @@ animation_reset :: proc(animation: ^Animation) {
animation.matrix_index = 0.0
}
animation_update :: proc(animation: ^Animation, speed: f32) {
animation.matrix_index = min(animation.matrix_index + speed, f32(animation.matrix_count))
}
animation_is_finished :: proc(animation: Animation) -> bool {
return animation.matrix_index == f32(animation.matrix_count)
}
@ -118,26 +114,26 @@ animation_draw :: proc(animation: Animation, global_transform: mat3) {
case .Rectangle:
shape := animation.shapes.rectangle
transform := linalg.identity(mat3)
previous, next := shape.origin, shape.origin
color_origin := cast([4]f32)(ANIMATION_COLOR_ORIGIN)
color_end := cast([4]f32)(ANIMATION_COLOR_END)
draw_animation_rectangle_corners(rectangle_corners_transform_mat3(next, global_transform), ANIMATION_COLOR_ORIGIN)
draw_animation_rectangle_corners(rectangle_corners_transform_mat3(shape.origin, global_transform), ANIMATION_COLOR_ORIGIN)
matrices := slice.reinterpret([]mat3, animation.matrices)
for i in 0..<animation.matrix_count {
animation_progress := f32(i + 1) / f32(animation.matrix_count)
previous := rectangle_corners_transform_mat3(shape.origin, transform)
transform *= matrices[i]
previous = next
next := rectangle_corners_transform_mat3(previous, transform)
next := rectangle_corners_transform_mat3(shape.origin, transform)
color_next := linalg.lerp(color_origin, color_end, animation_progress)
draw_animation_rectangle_corners(rectangle_corners_transform_mat3(next, global_transform), cast(rl.Color)color_next)
if f32(i) == math.floor(animation.matrix_index) {
color_previous := linalg.lerp(color_origin, color_end, animation_progress)
progress := ease.ease(animation.ease, fract(animation.matrix_index))
color_previous := linalg.lerp(color_origin, color_end, animation.matrix_index / f32(animation.matrix_count))
color := linalg.lerp(color_previous, color_next, progress)
corners := rectangle_corners_lerp(previous, next, progress)
draw_animation_rectangle_corners(corners, cast(rl.Color)color)
animated_corners := rectangle_corners_lerp(previous, next, progress)
animated_corners_world := rectangle_corners_transform_mat3(animated_corners, global_transform)
draw_animation_rectangle_corners(animated_corners_world, cast(rl.Color)color)
}
}
}

View file

@ -32,6 +32,7 @@ UiElementData_Container :: struct {
type: UiContainerType,
thickness: f32,
scroll: f32,
matrix_index: int,
}
UiElementData_Slider :: struct {
@ -391,7 +392,10 @@ program_update :: proc() {
grid_text_clip := rect_from_area(v2{matrix_container_br.x, top_bar_container_br.y}, v2{WINDOW_WIDTH, WINDOW_HEIGHT})
draw_grid(program.grid, rect_grow(grid_text_clip, -4.0), rect_grow(grid_text_clip, -32.0))
animation_update(&program.animation, 0.01)
if program.animation_state == .Playing {
program.animation.matrix_index += 0.01
}
animation_draw(program.animation, linalg.inverse(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset)))
ui_element_focus := program.state == .Normal ? program.ui_element_focus : ui.element_id_invalid()
@ -632,6 +636,13 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
rl.DrawRectangleRounded(area, 0.1, 4.0, dim)
rl.GuiGroupBox(area, element.label)
case .Matrix:
element_matrix_index := f32(data.matrix_index + 1)
animation_matrix_index := program.animation.matrix_index
matrix_animation_distance := element_matrix_index - animation_matrix_index
alpha := max(0.0, 1.0 - abs(matrix_animation_distance))
color := rl.Color{128, 255, 128, u8(alpha * 64.0)}
rl.DrawRectangleRec(rect2(ui.get_element_outer_area(element)), color)
matrix_area := ui.rect_grow(ui.rect2(area), element.margin / 2.0)
tl, tr, br, bl := ui.rect_get_corners(matrix_area)
col := rl.WHITE
@ -843,7 +854,7 @@ ui_mat3 :: proc(idx: int, mat: []f32, value_strings: []InputFloatField, dimensio
matrix_container_dimensions := ui.Dimensions {ui.Size_Percentage(1.0), ui.Size_PercentageRemainder(1.0)}
matrix_container_config := ui.ElementConfiguration {margin = 4.0}
matrix_container_data := new(UiElementData_Container, allocator)
matrix_container_data^ = {type = .Matrix, thickness = 2.0}
matrix_container_data^ = {type = .Matrix, thickness = 2.0, matrix_index = idx}
ui.container_begin(matrix_container_dimensions, matrix_container_config, matrix_container_data)
matrix_input_dimensions := ui.Dimensions {ui.Size_Percentage(1.0 / 3.0), ui.Size_Percentage(1.0 / 3.0)}
matrix_input_config := ui.ElementConfiguration {margin = 4.0}