grunk/levels/sandbox/debug_draw.gd

30 lines
621 B
GDScript3
Raw Normal View History

2025-03-01 14:40:02 -07:00
class_name DebugDraw extends Control
const COLOR := Color.ORANGE
const WIDTH := 4
var lines: Array = []
func _process(_delta: float) -> void:
if visible:
queue_redraw()
else:
lines = []
func draw_vector(vec: Vector3, origin: Vector3) -> void:
var camera := get_viewport().get_camera_3d()
var start := camera.unproject_position(origin)
var end := camera.unproject_position(origin + vec)
lines.push_back([start, end])
func _draw() -> void:
while lines:
var line: Array[Vector2] = []
2025-03-21 19:13:17 -06:00
@warning_ignore("unsafe_cast")
2025-03-01 14:40:02 -07:00
line.assign(lines.pop_back() as Array)
draw_line(line[0], line[1], COLOR, WIDTH)