Animation start
This commit is contained in:
parent
4de20264fa
commit
18e6f23d2b
3 changed files with 59 additions and 21 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import rl "libraries/raylib"
|
||||
import "core:math/linalg"
|
||||
import "core:fmt"
|
||||
|
||||
/*
|
||||
|
|
@ -16,8 +17,17 @@ RectangleCorners :: struct {
|
|||
tl, tr, br, bl: v2,
|
||||
}
|
||||
|
||||
rectangle_corners_transform :: proc(m: mat3, corners: RectangleCorners) -> RectangleCorners {
|
||||
return {
|
||||
tl = (v3{**corners.tl, 1.0} * m).xy,
|
||||
tr = (v3{**corners.tr, 1.0} * m).xy,
|
||||
br = (v3{**corners.br, 1.0} * m).xy,
|
||||
bl = (v3{**corners.bl, 1.0} * m).xy,
|
||||
}
|
||||
}
|
||||
|
||||
AnimationData_Rectangle :: struct {
|
||||
origin, middle, previous, next, last: RectangleCorners
|
||||
origin, middle, previous, next, last: RectangleCorners,
|
||||
}
|
||||
|
||||
draw_transformation_rectangle :: proc(rectangle: RectangleCorners, color: rl.Color) {
|
||||
|
|
@ -51,6 +61,13 @@ _animation_rectangle_reset :: proc(animation: ^AnimationInterface) {
|
|||
data.previous = data.origin
|
||||
}
|
||||
|
||||
_animation_rectangle_next_matrix :: proc(animation: ^AnimationInterface, next_matrix: mat3) {
|
||||
data := cast(^AnimationData_Rectangle)animation.data
|
||||
data.previous = data.next
|
||||
data.middle = data.next
|
||||
data.next = rectangle_corners_transform(next_matrix, data.next)
|
||||
}
|
||||
|
||||
_animation_rectangle_update_last :: proc(animation: ^AnimationInterface, master_matrix: mat3) {
|
||||
data := cast(^AnimationData_Rectangle)animation.data
|
||||
data.last = {
|
||||
|
|
@ -59,12 +76,16 @@ _animation_rectangle_update_last :: proc(animation: ^AnimationInterface, master_
|
|||
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 :: proc(animation: ^AnimationInterface, animation_progress: f32) {
|
||||
data := cast(^AnimationData_Rectangle)animation.data
|
||||
data.middle = {
|
||||
tl = linalg.lerp(data.previous.tl, data.next.tl, animation_progress),
|
||||
tr = linalg.lerp(data.previous.tr, data.next.tr, animation_progress),
|
||||
br = linalg.lerp(data.previous.br, data.next.br, animation_progress),
|
||||
bl = linalg.lerp(data.previous.bl, data.next.bl, animation_progress),
|
||||
}
|
||||
}
|
||||
|
||||
_animation_rectangle_update_goto_next :: proc(animation: ^AnimationInterface, next_matrix: mat3) {
|
||||
|
|
@ -76,6 +97,8 @@ animation_create_rectangle :: proc(rectangle: ^AnimationData_Rectangle) -> Anima
|
|||
data = rectangle,
|
||||
reset = _animation_rectangle_reset,
|
||||
update_last = _animation_rectangle_update_last,
|
||||
update = _animation_rectangle_update,
|
||||
next_matrix = _animation_rectangle_next_matrix,
|
||||
draw_idle = _animation_rectangle_draw_idle,
|
||||
draw_active = _animation_rectangle_draw_active,
|
||||
}
|
||||
|
|
@ -85,6 +108,8 @@ AnimationInterface :: struct {
|
|||
data: rawptr,
|
||||
reset: proc(animation: ^AnimationInterface),
|
||||
update_last: proc(animation: ^AnimationInterface, master_matrix: mat3),
|
||||
update: proc(animation: ^AnimationInterface, animation_progress: f32),
|
||||
next_matrix: proc(animation: ^AnimationInterface, next_matrix: mat3),
|
||||
draw_idle: proc(animation: AnimationInterface),
|
||||
draw_active: proc(animation: AnimationInterface),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue