-
Notifications
You must be signed in to change notification settings - Fork 1
/
Control.gd
81 lines (61 loc) · 1.88 KB
/
Control.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
extends Control
class Vector:
var object # The node to follow
var property # The property to draw
var posOffset
var isRotated
var scale # Scale factor
var width # Line width
var color # Draw color
var value # ASDASD
func _init(_object, _property, _posOffset, _isRotated, _scale, _width, _color):
object = _object
value = _property
posOffset = _posOffset
isRotated = _isRotated
scale = _scale
width = _width
color = _color
func draw(node, camera):
var basePosition = object.global_transform.origin + posOffset
var start = camera.unproject_position(basePosition)
var end
if isRotated:
end = camera.unproject_position(basePosition + object.get_parent().transform.basis.xform(object.get(value)) * scale)
else:
end = camera.unproject_position(basePosition + object.get(value) * scale)
node.draw_line(start, end, color, width)
node.draw_triangle(end, start.direction_to(end), width * 2, color)
var vectors = [] # Array to hold all registered values.
func _process(delta):
if not visible:
return
update()
func _draw():
var camera = get_viewport().get_camera()
for vector in vectors:
vector.draw(self, camera)
func add_vector(object, property, posOffset, isRotated, scale, width, color):
vectors.append(Vector.new(object, property, posOffset, isRotated, scale, width, color))
func draw_triangle(pos, dir, size, color):
var a = pos + dir * size
var b = pos + dir.rotated(2*PI/3) * size
var c = pos + dir.rotated(4*PI/3) * size
var points = PoolVector2Array([a, b, c])
draw_polygon(points, PoolColorArray([color]))
#extends Control
#
#
## Declare member variables here. Examples:
## var a = 2
## var b = "text"
#
#
## Called when the node enters the scene tree for the first time.
#func _ready():
# pass # Replace with function body.
#
#
## Called every frame. 'delta' is the elapsed time since the previous frame.
##func _process(delta):
## pass