From b95b7659c3a8f76b495f39bcc1fdbec6910e33b6 Mon Sep 17 00:00:00 2001 From: Synthasmagoria Date: Sun, 30 Aug 2026 15:06:47 +0200 Subject: [PATCH] Get rectangle corners as triangles --- default | Bin 110 -> 182 bytes src/animation.odin | 61 +++++++++++++++++++++++++------- src/main_desktop.odin | 6 ++-- src/program.odin | 79 ++++++++++++++++++------------------------ src/utils.odin | 8 +++++ 5 files changed, 95 insertions(+), 59 deletions(-) diff --git a/default b/default index 79faf49898fbed2c37c87054f38e779d908154a5..7e73b9688c614c672eab5b835e54ab22ae80997b 100755 GIT binary patch literal 182 zcmWId4+lYo5D(8_1t9Wpb#!qJQUDA3hchxTFt7kI14Dy7m||#fg3>@fj17_h%wlQ} m#QQ-!C>yE=q61> 1}) - rl.DrawTriangle(corners.br, corners.tr, corners.tl, {**color.rgb, color.a >> 1}) - rl.DrawLineV(corners.tl, corners.tr, color) - rl.DrawLineV(corners.tr, corners.br, color) - rl.DrawLineV(corners.br, corners.bl, color) - rl.DrawLineV(corners.bl, corners.tl, color) + triangles := rectangle_corners_get_triangles(corners) + draw_triangle(triangles[0], {**color.rgb, color.a >> 1}) + draw_triangle(triangles[1], {**color.rgb, color.a >> 1}) + rl.DrawLineEx(triangles[0][0], triangles[0][1], 2.0, color) + rl.DrawLineEx(triangles[0][1], triangles[0][2], 2.0, color) + rl.DrawLineEx(triangles[1][0], triangles[1][1], 2.0, color) + rl.DrawLineEx(triangles[1][1], triangles[1][2], 2.0, color) +} + +rectangle_corners_get_triangles :: proc (corners: RectangleCorners) -> [2]tri2 { + middle := (corners.tl + corners.tr + corners.br + corners.bl) / 4.0 + corners := [4]v2{corners.tl, corners.tr, corners.br, corners.bl} + AngleAndReference :: struct{angle: f32, corner: v2} + corners_polar: [4]AngleAndReference + for i in 0..<4 { + corner_centered := corners[i] - middle + corners_polar[i] = { + angle = linalg.atan2(-corner_centered.y, corner_centered.x), + corner = corners[i] + } + } + corners_slice := corners_polar[:] + sorting_interface := sort.Interface { + collection = &corners_slice, + len = proc(it: sort.Interface) -> int { + array := (cast(^[]AngleAndReference)it.collection)^ + return 4 + }, + less = proc(it: sort.Interface, i, j: int) -> bool { + array := (cast(^[]AngleAndReference)it.collection)^ + return array[i].angle < array[j].angle + }, + swap = proc(it: sort.Interface, i, j: int) { + array := (cast(^[]AngleAndReference)it.collection)^ + array[i], array[j] = array[j], array[i] + }, + } + sort.sort(sorting_interface) + return { + {corners_slice[0].corner, corners_slice[1].corner, corners_slice[2].corner}, + {corners_slice[2].corner, corners_slice[3].corner, corners_slice[0].corner}, + } } /* @@ -177,12 +214,12 @@ animation_draw :: proc(animation: Animation, global_transform: mat3) { draw_animation_rectangle_corners(rectangle_corners_transform_mat3(global_transform, shape), ANIMATION_COLOR_ORIGIN) transform := linalg.identity(mat3) matrices := slice.reinterpret([]mat3, animation.matrices[:animation.matrix_count * 9]) - for mat in matrices { - transform *= mat - shape_next := rectangle_corners_transform_mat3(transform, shape) - shape_next_world := rectangle_corners_transform_mat3(global_transform, shape_next) - draw_animation_rectangle_corners(shape_next_world, ANIMATION_COLOR_ORIGIN) - } + // for mat in matrices { + // transform *= mat + // shape_next := rectangle_corners_transform_mat3(transform, shape) + // shape_next_world := rectangle_corners_transform_mat3(global_transform, shape_next) + // draw_animation_rectangle_corners(shape_next_world, ANIMATION_COLOR_ORIGIN) + // } diff --git a/src/main_desktop.odin b/src/main_desktop.odin index d5acc73..f469777 100644 --- a/src/main_desktop.odin +++ b/src/main_desktop.odin @@ -2,16 +2,18 @@ package main import rl "libraries/raylib" import "core:log" +import "libraries/back" main :: proc() { // exe_path := os.args[0] // exe_dir := filepath.dir(string(exe_path)) // os.set_working_directory(exe_dir) rl.ChangeDirectory(rl.GetApplicationDirectory()) - // back.register_segfault_handler() - // context.assertion_failure_proc = back.assertion_failure_proc + back.register_segfault_handler() + context.assertion_failure_proc = back.assertion_failure_proc register_illegal_instruction_handler() + context.logger = log.create_console_logger() init() diff --git a/src/program.odin b/src/program.odin index 9243e90..c8d8803 100644 --- a/src/program.odin +++ b/src/program.odin @@ -31,6 +31,7 @@ import rl "libraries/raylib" import ui "libraries/snths_ui" import "core:mem" import "core:fmt" +import "core:math" import "core:math/linalg" import "core:strings" @@ -372,6 +373,11 @@ program_show_dialog :: proc(program: ^Program, dialog_type: ProgramDialogType, m program.state = .Dialog program.dialog_type = dialog_type program.dialog_message = message + mem.set(&program.dialog_data, 0, size_of(program.dialog_data)) + for i in 0.. []ui.Element { diff --git a/src/utils.odin b/src/utils.odin index 77f73af..acb5bb0 100644 --- a/src/utils.odin +++ b/src/utils.odin @@ -93,6 +93,10 @@ draw_float_aligned :: proc(value: f32, position: v2, style: FontStyle, halign: J draw_text_aligned(text, position, style, halign, valign, color) } +draw_triangle :: proc(t: tri2, color: rl.Color) { + rl.DrawTriangle(t[0], t[1], t[2], color) +} + /// ### MATH ### /// fract :: proc(val: f32) -> f32 { return val - math.trunc(val) @@ -322,3 +326,7 @@ matrix3_transform_rect2 :: proc(m: mat3, r: rect2) -> rect2 { br := m * v3{r.x + r.width, r.y + r.height, 1.0} return {**tl.xy, **(br - tl).xy} } + +euclidean_to_polar :: proc(v: v2) -> v2 { + return {linalg.atan2(-v.y, v.x), linalg.length(v)} +}