improve angle dir and add debug lines

This commit is contained in:
2025-02-25 02:12:26 +10:00
parent 50e5421317
commit 58983ecda2
2 changed files with 59 additions and 16 deletions

View File

@@ -13,6 +13,7 @@ const DEFAULT_COLOR: Color = Color.RED
var mode: Mode = Mode.PERFORMANCE
var _vectors_to_draw: Dictionary = {}
var _lines_to_draw: Dictionary = {}
var _markers_to_draw: Dictionary = {}
var _circles_to_draw: Dictionary = {}
var _text_to_draw: Dictionary = {}
@@ -88,6 +89,15 @@ func vector(
_vectors_to_draw[key] = {"from": from, "to": to, "color": color, "on": true}
func line(
key: String, from: Vector3, to: Vector3, color: Color = DEFAULT_COLOR
) -> void:
if not show_debug():
return
_lines_to_draw[key] = {"from": from, "to": to, "color": color, "on": true}
func marker(
key: String,
pos: Vector3,
@@ -209,6 +219,19 @@ func _draw_vector(from: Vector3, to: Vector3, color: Color) -> void:
_draw_triangle(end, start.direction_to(end), 5, color)
func _draw_line(from: Vector3, to: Vector3, color: Color) -> void:
if (
not Referencer.main_camera.is_position_in_frustum(from)
and not Referencer.main_camera.is_position_in_frustum(to)
):
return
var start := _unproject(from)
var end := _unproject(to)
if (start - end).length() > 0:
_control.draw_line(start, end, color, LINE_WIDTH)
func _draw_triangle(
pos: Vector2,
dir: Vector2,
@@ -288,6 +311,15 @@ func _on_control_draw() -> void:
)
# v["on"] = false
for v: Dictionary in _lines_to_draw.values():
if v["on"]:
_draw_line(
v["from"] as Vector3,
v["to"] as Vector3,
v["color"] as Color,
)
# v["on"] = false
for v: Dictionary in _markers_to_draw.values():
if v["on"]:
_draw_marker(