-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrbit.gd
More file actions
71 lines (55 loc) · 1.54 KB
/
Orbit.gd
File metadata and controls
71 lines (55 loc) · 1.54 KB
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
extends ImmediateGeometry
# 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
#draw_orbit()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func drawline(a, b):
begin(Mesh.PRIMITIVE_LINES)
set_color(Color( 0.75, 0.75, 0.75, 1))
add_vertex(a)
add_vertex(b)
end()
func draw_points(points):
begin(Mesh.PRIMITIVE_LINES)
set_color(Color( 0.5, 0.5, 0.5, 1))
var i = 0
while i < (points.size()):
set_normal(Vector3(1,0,0))
set_uv(Vector2(0,0))
add_vertex(points[i])
set_normal(Vector3(1,0,0))
set_uv(Vector2(0,0))
if (i+1) == points.size():
# the last point connects to the first point
add_vertex(points[0])
else:
add_vertex(points[i+1])
i += 1
end()
func draw_orbit():
var point_count = 64
var points_arc = PoolVector3Array()
var center = Vector3(0,0,0)
var radius = 30
var angle_from = 0
var angle_to = 360
for i in range(point_count + 1):
# TODO: extend to ellipse; a, b params derived from eccentricity
var angle_point = deg2rad(angle_from + i * (angle_to-angle_from) / point_count - 90)
points_arc.push_back(center + Vector3(cos(angle_point), 0, sin(angle_point)) * radius)
begin(Mesh.PRIMITIVE_LINES)
set_color(Color( 0.5, 0.5, 0.5, 1))
for i in range(point_count):
set_normal(Vector3(1,0,0))
set_uv(Vector2(0,0))
add_vertex(points_arc[i])
set_normal(Vector3(1,0,0))
set_uv(Vector2(0,0))
add_vertex(points_arc[i+1])
end()