2024-10-04 21:16:58 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "core:math"
|
|
|
|
import "core:math/linalg"
|
|
|
|
import rl "vendor:raylib"
|
|
|
|
|
|
|
|
|
|
|
|
angle_cycle :: proc(value, min, max: f32) -> f32 {
|
|
|
|
delta := (max - min)
|
|
|
|
result := linalg.mod(value - min, delta)
|
|
|
|
if result < 0 {
|
|
|
|
result += delta
|
|
|
|
}
|
|
|
|
|
|
|
|
return min + result
|
|
|
|
}
|
|
|
|
|
|
|
|
angle_rotate :: proc(angle, target, speed: f32) -> f32 {
|
|
|
|
diff := angle_cycle(target - angle, -math.PI, math.PI)
|
|
|
|
if diff < -speed {return angle - speed}
|
|
|
|
if diff > speed {return angle + speed}
|
|
|
|
return target
|
|
|
|
}
|
|
|
|
|
|
|
|
get_vec_from_angle :: proc(angle: f32) -> vec3 {
|
|
|
|
return rl.Vector3RotateByAxisAngle(vec3right, vec3backward, angle)
|
|
|
|
}
|
|
|
|
|
2024-10-05 21:11:57 +03:00
|
|
|
draw_text_centered :: proc(font: rl.Font, text: cstring, pos: vec2, size: f32, spacing : f32 = 1, color : rl.Color = rl.BLACK) {
|
2024-10-04 21:16:58 +03:00
|
|
|
text_size := rl.MeasureTextEx(font, text, size, 1)
|
2024-10-05 21:11:57 +03:00
|
|
|
rl.DrawTextPro(font, text, pos, text_size / 2, 0, size, 1, color)
|
2024-10-04 21:16:58 +03:00
|
|
|
}
|