The
This commit is contained in:
parent
4e920b5f0a
commit
d5793c836f
4 changed files with 73 additions and 61 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import rl "libraries/raylib"
|
||||
import "core:math"
|
||||
import "core:math/ease"
|
||||
import "core:math/linalg"
|
||||
import "core:slice"
|
||||
|
|
@ -13,10 +14,10 @@ RectangleCorners :: struct {tl, tr, br, bl: v2}
|
|||
|
||||
rectangle_corners_from_rect :: proc "contextless" (rect: rect2) -> RectangleCorners {
|
||||
return {
|
||||
tl = {rect.x, rect.y},
|
||||
tr = {rect.x + rect.width, rect.y},
|
||||
bl = {rect.x + rect.width, rect.y + rect.height},
|
||||
br = {rect.x, rect.y + rect.height}
|
||||
{rect.x, rect.y},
|
||||
{rect.x + rect.width, rect.y},
|
||||
{rect.x + rect.width, rect.y + rect.height},
|
||||
{rect.x, rect.y + rect.height}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,13 +30,22 @@ rectangle_corners_transform_mat3 :: proc "contextless" (corners: RectangleCorner
|
|||
}
|
||||
}
|
||||
|
||||
rectangle_corners_lerp :: proc "contextless" (a, b: RectangleCorners, t: f32) -> RectangleCorners {
|
||||
return {
|
||||
linalg.lerp(a.tl, b.tl, t),
|
||||
linalg.lerp(a.tr, b.tr, t),
|
||||
linalg.lerp(a.bl, b.bl, t),
|
||||
linalg.lerp(a.br, b.br, t),
|
||||
}
|
||||
}
|
||||
|
||||
rectangle_corners_transform_mat2 :: proc "contextless" (corners: RectangleCorners, transform: mat2) -> RectangleCorners {
|
||||
return {corners.tl * transform, corners.tr * transform, corners.br * transform, corners.bl * transform}
|
||||
}
|
||||
|
||||
draw_animation_rectangle_corners :: proc(corners: RectangleCorners, color: rl.Color) {
|
||||
rect := rect_from_corners(corners.tl, corners.tr, corners.br, corners.bl)
|
||||
rl.DrawRectangleRec(rect, {**color.rgb, color.a << 1})
|
||||
rl.DrawRectangleRec(rect, {**color.rgb, color.a >> 1})
|
||||
rl.DrawRectangleLinesEx(rect, 2, color)
|
||||
}
|
||||
|
||||
|
|
@ -54,12 +64,11 @@ AnimationShapes :: struct {
|
|||
|
||||
Animation :: struct {
|
||||
matrices: []f32,
|
||||
matrix_index: int,
|
||||
matrix_index: f32,
|
||||
matrix_count: int,
|
||||
matrix_type: AnimationMatrixType,
|
||||
shapes: AnimationShapes,
|
||||
ease: ease.Ease,
|
||||
state: AnimationState,
|
||||
type: AnimationType,
|
||||
}
|
||||
|
||||
|
|
@ -79,13 +88,6 @@ AnimationType :: enum {
|
|||
Rectangle,
|
||||
}
|
||||
|
||||
AnimationState :: enum {
|
||||
Ready,
|
||||
Playing,
|
||||
Paused,
|
||||
Finished,
|
||||
}
|
||||
|
||||
animation_init :: proc(animation: ^Animation, matrices: []f32) {
|
||||
animation^ = {
|
||||
ease = .Cubic_Out,
|
||||
|
|
@ -99,39 +101,44 @@ animation_init :: proc(animation: ^Animation, matrices: []f32) {
|
|||
}
|
||||
}
|
||||
|
||||
animation_play :: proc(animation: ^Animation) {
|
||||
|
||||
}
|
||||
|
||||
animation_reset :: proc(animation: ^Animation) {
|
||||
|
||||
animation.matrix_index = 0.0
|
||||
}
|
||||
|
||||
animation_pause :: proc(animation: ^Animation) {
|
||||
|
||||
animation_update :: proc(animation: ^Animation, speed: f32) {
|
||||
animation.matrix_index = min(animation.matrix_index + speed, f32(animation.matrix_count))
|
||||
}
|
||||
|
||||
animation_update :: proc(animation: ^Animation, matrices: []mat3) {
|
||||
|
||||
animation_is_finished :: proc(animation: Animation) -> bool {
|
||||
return animation.matrix_index == f32(animation.matrix_count)
|
||||
}
|
||||
|
||||
animation_draw :: proc(animation: Animation) {
|
||||
animation_draw :: proc(animation: Animation, global_transform: mat3) {
|
||||
switch animation.type {
|
||||
case .Rectangle:
|
||||
shape := animation.shapes.rectangle
|
||||
transformation := linalg.identity(mat3)
|
||||
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(next, ANIMATION_COLOR_ORIGIN)
|
||||
draw_animation_rectangle_corners(rectangle_corners_transform_mat3(next, global_transform), ANIMATION_COLOR_ORIGIN)
|
||||
|
||||
matrices := slice.reinterpret([]mat3, animation.matrices)
|
||||
for m, i in matrices {
|
||||
progress := f32(i + 1) / f32(len(animation.matrices))
|
||||
transformation *= m
|
||||
for i in 0..<animation.matrix_count {
|
||||
animation_progress := f32(i + 1) / f32(animation.matrix_count)
|
||||
transform *= matrices[i]
|
||||
previous = next
|
||||
next := rectangle_corners_transform_mat3(previous, transformation)
|
||||
draw_animation_rectangle_corners(next, cast(rl.Color)linalg.lerp(color_origin, color_end, progress))
|
||||
next := rectangle_corners_transform_mat3(previous, 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 := linalg.lerp(color_previous, color_next, progress)
|
||||
corners := rectangle_corners_lerp(previous, next, progress)
|
||||
draw_animation_rectangle_corners(corners, cast(rl.Color)color)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,7 +150,3 @@ animation_set_playback_speed :: proc(animation: ^Animation) {
|
|||
animation_set_type :: proc(animation: ^Animation, type: AnimationType) {
|
||||
animation.type = type
|
||||
}
|
||||
|
||||
animation_is_finished :: proc() -> bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue