Animation modes

This commit is contained in:
Synthasmagoria 2026-09-09 01:21:57 +02:00
commit 47884a00b3
3 changed files with 36 additions and 13 deletions

View file

@ -43,7 +43,7 @@ files="$OUT_DIR/$WASM_OBJ_NAME $RAYLIB_PATH/wasm/libraylib.a $RAYLIB_PATH/wasm/l
# index_template.html contains the javascript code that calls the procedures in # index_template.html contains the javascript code that calls the procedures in
# source/main_web/main_web.odin # source/main_web/main_web.odin
EMCC_SETTINGS="-sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0" EMCC_SETTINGS="-sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0"
flags="-Wl,--gc-sections -Os $EMCC_SETTINGS --shell-file $INDEX_TEMPLATE_PATH --preload-file src/assets" flags="-Os $EMCC_SETTINGS --shell-file $INDEX_TEMPLATE_PATH --preload-file src/assets"
# For debugging: Add `-g` to `emcc` (gives better error callstack in chrome) # For debugging: Add `-g` to `emcc` (gives better error callstack in chrome)
emcc -o $OUT_DIR/index.html $files $flags emcc -o $OUT_DIR/index.html $files $flags

View file

@ -170,6 +170,11 @@ AnimationMatrixType :: enum {
Mat4, Mat4,
} }
AnimationMode :: enum {
Step,
All,
}
@private @rodata animation_matrix_type_size := [AnimationMatrixType]int { @private @rodata animation_matrix_type_size := [AnimationMatrixType]int {
.Mat2 = size_of(mat2), .Mat2 = size_of(mat2),
.Mat3 = size_of(mat3), .Mat3 = size_of(mat3),
@ -199,7 +204,7 @@ animation_get_eased_progress :: proc(animation: Animation) -> f32 {
return math.floor(animation.matrix_index) + ease.ease(animation.ease, fract(animation.matrix_index)) return math.floor(animation.matrix_index) + ease.ease(animation.ease, fract(animation.matrix_index))
} }
animation_draw :: proc(animation: Animation, global_transform: mat3, temp_allocator := context.temp_allocator) { animation_draw :: proc(animation: Animation, global_transform: mat3, mode: AnimationMode, temp_allocator := context.temp_allocator) {
color_origin := cast([4]f32)ANIMATION_COLOR_ORIGIN color_origin := cast([4]f32)ANIMATION_COLOR_ORIGIN
color_end := cast([4]f32)ANIMATION_COLOR_END color_end := cast([4]f32)ANIMATION_COLOR_END
@ -221,16 +226,21 @@ animation_draw :: proc(animation: Animation, global_transform: mat3, temp_alloca
if animation.matrix_count <= 0 { if animation.matrix_count <= 0 {
break break
} }
animation_progress := math.clamp(animation.matrix_index, 0.0, f32(animation.matrix_count)) switch mode {
animation_progress_frame := ease.ease(animation.ease, fract(animation.matrix_index)) case .Step:
animation_progress_total := math.floor(animation_progress) + animation_progress_frame animation_progress := math.clamp(animation.matrix_index, 0.0, f32(animation.matrix_count))
// TODO (synthas): math.min is a temp fix because I lost track of the math and got lazy with it animation_progress_frame := ease.ease(animation.ease, fract(animation.matrix_index))
animation_progress_fraction := math.min(animation_progress_total / f32(animation.matrix_count), 1.0) animation_progress_total := math.floor(animation_progress) + animation_progress_frame
rectangle_previous := rectangles[int(animation_progress)] // TODO (synthas): math.min is a temp fix because I lost track of the math and got lazy with it
rectangle_next := rectangles[min(int(animation_progress + 1), animation.matrix_count)] animation_progress_fraction := math.min(animation_progress_total / f32(animation.matrix_count), 1.0)
rectangle_current := rectangle_corners_lerp(rectangle_previous, rectangle_next, animation_progress_frame) rectangle_previous := rectangles[int(animation_progress)]
rectangle_current_color := linalg.lerp(color_origin, color_end, animation_progress_fraction) rectangle_next := rectangles[min(int(animation_progress + 1), animation.matrix_count)]
draw_animation_rectangle_corners(rectangle_current, rl.Color(rectangle_current_color)) rectangle_current := rectangle_corners_lerp(rectangle_previous, rectangle_next, animation_progress_frame)
rectangle_current_color := linalg.lerp(color_origin, color_end, animation_progress_fraction)
draw_animation_rectangle_corners(rectangle_current, rl.Color(rectangle_current_color))
case .All:
}
} }
} }

View file

@ -295,6 +295,7 @@ Program :: struct {
animation: Animation, animation: Animation,
animation_state: ProgramAnimationState, animation_state: ProgramAnimationState,
animation_speed: f32, animation_speed: f32,
animation_mode: AnimationMode,
window_should_close: bool, window_should_close: bool,
} }
@ -568,7 +569,7 @@ program_update :: proc() {
animation.matrix_index += 0.01 animation.matrix_index += 0.01
} }
animation_draw(animation^, linalg.inverse(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset))) animation_draw(animation^, linalg.inverse(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset)), program.animation_mode)
switch animation.type { switch animation.type {
case .Rectangle: case .Rectangle:
@ -872,6 +873,18 @@ program_build_workspace_ui :: proc(ctx: ^ui.Context) -> (elements: []ui.Element,
} }
ui.same_line() ui.same_line()
ui.element(.Slider, slider_dimensions, slider_config, slider_data) ui.element(.Slider, slider_dimensions, slider_config, slider_data)
label_config := ui.ElementConfiguration{margin = button_margin, label = "Animation mode: ", color = ui.col(rl.WHITE)}
ui.same_line()
ui.element(.Label, ui.dimensions_auto(), label_config)
toggle_group_config := ui.ElementConfiguration{margin = button_margin, label = enum_to_raygui_options_string(AnimationMode, context.temp_allocator)}
toggle_group_dimensions := ui.Dimensions{top_bar_button_width * 2.0, ui.Size_Percentage(1.0)}
toggle_group_data: ^UiElementData_ToggleGroup
toggle_group_data = new(UiElementData_ToggleGroup, context.temp_allocator)
toggle_group_data^ = {value = cast(^i32)&program.animation_mode}
ui.same_line()
ui.element(.ToggleGroup, toggle_group_dimensions, toggle_group_config, toggle_group_data)
} }
ui.container_end() ui.container_end()