transformation_visualizer/animation.odin
2026-08-17 14:37:33 +02:00

90 lines
3 KiB
Odin

package main
import rl "libraries/raylib"
import "core:fmt"
/*
Maybe it is possible to have everything 3d be mathed the same way
as in 2d. But I'm not sure if that's actually how it works.
*/
AnimationType :: enum {
Rectangle,
}
RectangleCorners :: struct {
tl, tr, br, bl: v2,
}
AnimationData_Rectangle :: struct {
origin, middle, previous, next, last: RectangleCorners
}
draw_transformation_rectangle :: proc(rectangle: RectangleCorners, color: rl.Color) {
rect := rect_from_corners(rectangle.tl, rectangle.tr, rectangle.br, rectangle.bl)
rl.DrawRectangleRec(rect, rl.Color{**color.rgb, color.a / 2})
points := []v2{rectangle.tl, rectangle.tr, rectangle.br, rectangle.bl}
for i := 0; i < len(points); i += 1 {
rl.DrawLineV(points[i], points[(i + 1) % len(points)], color)
rl.DrawCircleV(points[i], 4.0, rl.RED)
}
}
_animation_rectangle_draw_idle :: proc(animation: AnimationInterface) {
data := cast(^AnimationData_Rectangle)animation.data
draw_transformation_rectangle(data.last, TRANSFORMATION_RECTANGLE_COLOR_LAST)
draw_transformation_rectangle(data.origin, TRANSFORMATION_RECTANGLE_COLOR_ORIGIN)
}
_animation_rectangle_draw_active :: proc(animation: AnimationInterface) {
data := cast(^AnimationData_Rectangle)animation.data
draw_transformation_rectangle(data.last, TRANSFORMATION_RECTANGLE_COLOR_LAST)
draw_transformation_rectangle(data.next, TRANSFORMATION_RECTANGLE_COLOR_NEXT)
draw_transformation_rectangle(data.middle, TRANSFORMATION_RECTANGLE_COLOR_MIDDLE)
draw_transformation_rectangle(data.origin, TRANSFORMATION_RECTANGLE_COLOR_ORIGIN)
}
_animation_rectangle_reset :: proc(animation: ^AnimationInterface) {
data := cast(^AnimationData_Rectangle)animation.data
data.middle = data.origin
data.next = data.origin
data.previous = data.origin
}
_animation_rectangle_update_last :: proc(animation: ^AnimationInterface, master_matrix: mat3) {
data := cast(^AnimationData_Rectangle)animation.data
data.last = {
tl = (master_matrix * v3{**data.origin.tl, 1.0}).xy,
tr = (master_matrix * v3{**data.origin.tr, 1.0}).xy,
br = (master_matrix * v3{**data.origin.br, 1.0}).xy,
bl = (master_matrix * v3{**data.origin.bl, 1.0}).xy,
}
fmt.println(data.last)
fmt.println(data.origin)
}
_animation_rectangle_update :: proc(animation: ^AnimationInterface, current_matrix: mat3, progress: f32) {
}
_animation_rectangle_update_goto_next :: proc(animation: ^AnimationInterface, next_matrix: mat3) {
}
animation_create_rectangle :: proc(rectangle: ^AnimationData_Rectangle) -> AnimationInterface {
return {
data = rectangle,
reset = _animation_rectangle_reset,
update_last = _animation_rectangle_update_last,
draw_idle = _animation_rectangle_draw_idle,
draw_active = _animation_rectangle_draw_active,
}
}
AnimationInterface :: struct {
data: rawptr,
reset: proc(animation: ^AnimationInterface),
update_last: proc(animation: ^AnimationInterface, master_matrix: mat3),
draw_idle: proc(animation: AnimationInterface),
draw_active: proc(animation: AnimationInterface),
}