add color helper
This commit is contained in:
parent
6fecc5632c
commit
641b069cb0
7
scripts/helper/color_helper.gd
Normal file
7
scripts/helper/color_helper.gd
Normal file
@ -0,0 +1,7 @@
|
||||
extends Resource
|
||||
class_name ColorHelper
|
||||
|
||||
static func get_direction_color(direction: Vector3) -> Color:
|
||||
var angle = atan2(direction.z, direction.x)
|
||||
var hue = (angle / (2.0 * PI)) + 0.5
|
||||
return Color.from_hsv(hue, 1.0, 1.0)
|
||||
@ -1,31 +0,0 @@
|
||||
extends Resource
|
||||
class_name FlowFieldCell
|
||||
|
||||
@export var cell_size: float = 1.0
|
||||
@export var position: Vector3 = Vector3.ZERO
|
||||
var flow_direction: Vector3 = Vector3.ZERO
|
||||
var is_target:bool = false
|
||||
|
||||
|
||||
func update(targetPos: Vector3):
|
||||
if is_target:
|
||||
flow_direction = Vector3.ZERO
|
||||
return
|
||||
|
||||
if targetPos != position:
|
||||
flow_direction = (targetPos - position).normalized() * (cell_size/2)
|
||||
else:
|
||||
flow_direction = Vector3.ZERO
|
||||
|
||||
func debug_process() -> void:
|
||||
if flow_direction.length() > 0.0:
|
||||
var arrow_color = get_direction_color(flow_direction.normalized())
|
||||
DebugDraw3D.draw_arrow(position, position + flow_direction, arrow_color, 0.1)
|
||||
else:
|
||||
DebugDraw3D.draw_sphere(position, 0.05)
|
||||
|
||||
func get_direction_color(direction: Vector3) -> Color:
|
||||
var angle = atan2(direction.z, direction.x)
|
||||
var hue = (angle / (2.0 * PI)) + 0.5
|
||||
|
||||
return Color.from_hsv(hue, 1.0, 1.0)
|
||||
@ -1,6 +1,9 @@
|
||||
extends Node3D
|
||||
class_name FlowFieldNav
|
||||
|
||||
# https://docs.godotengine.org/cs/4.x/tutorials/shaders/compute_shaders.html#create-a-local-renderingdevice
|
||||
# Das Updaten der flow richtung kann auf der grafikkarte gemacht werden mit compute shader
|
||||
|
||||
@export_category("Debug Visualization")
|
||||
@export_group("Grid Center")
|
||||
@export var show_grid_center: bool = false
|
||||
@ -32,9 +35,11 @@ class_name FlowFieldNav
|
||||
@export var target: Node3D = null
|
||||
var flow_direction_list: Array[Vector2] = []
|
||||
|
||||
|
||||
var half_size_x: float
|
||||
var half_size_z: float
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
for x in range(grid_size_x):
|
||||
for z in range(grid_size_z):
|
||||
@ -109,22 +114,16 @@ func _draw_arrows():
|
||||
if flow_direction_list[index].length() > 0.0:
|
||||
var direction = Vector3(flow_direction_list[index].x, 0, flow_direction_list[index].y).normalized()
|
||||
var arrow_end = cell_center + direction * (cell_size * 0.4)
|
||||
DebugDraw3D.draw_arrow(cell_center, arrow_end, get_direction_color(direction), arrows_size)
|
||||
DebugDraw3D.draw_arrow(cell_center, arrow_end, ColorHelper.get_direction_color(direction), arrows_size)
|
||||
else:
|
||||
points.append(cell_center)
|
||||
DebugDraw3D.draw_points(points, DebugDraw3D.POINT_TYPE_SQUARE, cell_center_size, cell_center_color)
|
||||
|
||||
func get_direction_color(direction: Vector3) -> Color:
|
||||
var angle = atan2(direction.z, direction.x)
|
||||
var hue = (angle / (2.0 * PI)) + 0.5
|
||||
return Color.from_hsv(hue, 1.0, 1.0)
|
||||
|
||||
func _get_cell_center_with_coordinates(x:int, z:int) -> Vector3:
|
||||
return position + Vector3(
|
||||
(-half_size_x + (x * cell_size) + (cell_size * 0.5)),
|
||||
0,
|
||||
(-half_size_z + (z * cell_size) + (cell_size * 0.5))
|
||||
)
|
||||
(-half_size_z + (z * cell_size) + (cell_size * 0.5)))
|
||||
|
||||
func _get_index_from_position(pos: Vector3) -> int:
|
||||
var x = int((pos.x - position.x + half_size_x) / cell_size)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user