/
viewer3D2.jl
231 lines (190 loc) · 8.5 KB
/
viewer3D2.jl
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#= MIT License
Copyright (c) 2020, 2021 Uwe Fechner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. =#
@consts begin
SCALE = 1.2
INITIAL_HEIGHT = 80.0*se().zoom # meter, for demo
MAX_HEIGHT = 200.0*se().zoom # meter, for demo
KITE = FileIO.load(joinpath(dirname(get_data_path()), se().model))
FLYING = [false]
PLAYING = [false]
GUI_ACTIVE = [false]
AXIS_LABEL_SIZE = 30
TEXT_SIZE = 16
running = Observable(false)
starting = [0]
zoom = [1.0]
steering = [0.0]
textnode = Observable("") # lower left
textnode2 = Observable("") # upper right
fontsize = Observable(TEXT_SIZE)
fontsize2 = Observable(AXIS_LABEL_SIZE)
status = Observable("")
p1 = Observable(Vector{Point2f}(undef, 6000)) # 5 min
p2 = Observable(Vector{Point2f}(undef, 6000)) # 5 min
pos_x = Observable(0.0f0)
points = Vector{Point3f}(undef, se().segments+1+4)
quat = Observable(Quaternionf(0,0,0,1)) # orientation of the kite
kite_pos = Observable(Point3f(1,0,0)) # position of the kite
positions = Observable([Point3f(x,0,0) for x in 1:se().segments+KITE_SPRINGS]) # positions of the tether segments
part_positions = Observable([Point3f(x,0,0) for x in 1:se().segments+1+4]) # positions of the tether particles
markersizes = Observable([Point3f(1,1,1) for x in 1:se().segments+KITE_SPRINGS]) # includes the segment length
rotations = Observable([Point3f(1,0,0) for x in 1:se().segments+KITE_SPRINGS]) # unit vectors corresponding with
# the orientation of the segments
end
"""
abstract type AbstractKiteViewer
All kite viewers must inherit from this type. All methods that are defined on this type must work
with all kite viewers. All exported methods must work on this type.
"""
abstract type AbstractKiteViewer end
"""
const AKV = AbstractKiteViewer
Short alias for the AbstractKiteViewer.
"""
const AKV = AbstractKiteViewer
# # struct that stores the state of the 3D viewer
# mutable struct Viewer3D <: AKV
# scene::Scene
# layout::GridLayout
# scene3D::LScene
# cam::Camera3D
# screen::GLMakie.Screen
# btn_RESET::Button
# btn_ZOOM_in::Button
# btn_ZOOM_out::Button
# btn_PLAY::Button
# btn_AUTO::Button
# btn_PARKING::Button
# btn_STOP::Button
# step::Int64
# energy::Float64
# show_kite::Bool
# stop::Bool
# end
mutable struct Viewer3D
# scene::Scene
fig::Figure
# layout::GridLayout
scene3D::LScene
cam::Camera3D
# screen::GLMakie.Screen
btn_RESET::Button
btn_ZOOM_in::Button
btn_ZOOM_out::Button
end
function clear_viewer(kv::AKV)
kv.stop = false
kv.step = 1
kv.energy = 0
status[] = "Running..."
end
function stop(kv::AKV)
kv.stop = true
status[]="Stopped"
end
function set_status(kv::AKV, status_text)
status[] = status_text
end
function Viewer3D(show_kite=true, autolabel="Autopilot")
# scene, layout = layoutscene(resolution = (840, 900), backgroundcolor = RGBf(0.7, 0.8, 1))
# scene3D = LScene(scene, scenekw = (show_axis=false, limits = Rect(-7,-10.0,0, 11,10,11), resolution = (800, 800)), raw=false)
# create_coordinate_system(scene3D)
# cam = cameracontrols(scene3D.scene)
fig = Figure(size=(840, 900), backgroundcolor=RGBf(0.7, 0.8, 1))
scene = fig[1,1]
scene3D = LScene(scene, show_axis=false, scenekw=(limits=Rect(-7,-10.0,0, 11,10,11), size=(800, 800)))
# hidedecorations!(scene3D.scene, grid = false)
create_coordinate_system(scene3D)
cam = cameracontrols(scene3D.scene)
FLYING[1] = false
PLAYING[1] = false
GUI_ACTIVE[1] = true
reset_view(cam, scene3D)
fontsize[] = TEXT_SIZE
fontsize2[] = AXIS_LABEL_SIZE
text!(scene3D, "z", position = Point3f0(0, 0, 14.6), fontsize = fontsize2, align = (:center, :center), show_axis = false)
text!(scene3D, "x", position = Point3f0(17, 0,0), fontsize = fontsize2, align = (:center, :center), show_axis = false)
text!(scene3D, "y", position = Point3f0( 0, 14.5, 0), fontsize = fontsize2, align = (:center, :center), show_axis = false)
text!(scene, status, position = Point2f0( 20, 0), fontsize = TEXT_SIZE, align = (:left, :bottom), show_axis = false)
status[]="Stopped"
fig[2, 1] = buttongrid = GridLayout(tellwidth=false)
l_sublayout = GridLayout()
fig[1:3, 1] = l_sublayout
l_sublayout[:v] = [scene3D, buttongrid]
btn_RESET = Button(scene, label = "RESET")
btn_ZOOM_in = Button(scene, label = "Zoom +")
btn_ZOOM_out = Button(scene, label = "Zoom -")
btn_PLAY_PAUSE = Button(scene, label = @lift($running ? "PAUSE" : " PLAY "))
btn_STOP = Button(scene, label = "STOP")
sw = Toggle(scene, active = false)
label = Label(scene, "repeat")
buttongrid[1, 1:7] = [btn_PLAY_PAUSE, btn_ZOOM_in, btn_ZOOM_out, btn_RESET, btn_STOP, sw, label]
display(fig)
Viewer3D(fig, scene3D, cam, btn_RESET, btn_ZOOM_in, btn_ZOOM_out)
FLYING[1] = false
PLAYING[1] = false
GUI_ACTIVE[1] = true
reset_view(cam, scene3D)
# fontsize[] = TEXT_SIZE
# fontsize2[] = AXIS_LABEL_SIZE
# text!(scene3D, "z", position = Point3f(0, 0, 14.6), fontsize = fontsize2, align = (:center, :center), show_axis = false)
# text!(scene3D, "x", position = Point3f(17, 0,0), fontsize = fontsize2, align = (:center, :center), show_axis = false)
# text!(scene3D, "y", position = Point3f( 0, 14.5, 0), fontsize = fontsize2, align = (:center, :center), show_axis = false)
# text!(scene, status, position = Point2f( 20, 0), fontsize = TEXT_SIZE, align = (:left, :bottom), show_axis = false)
# status[]="Stopped"
# layout[1, 1] = scene3D
# layout[2, 1] = buttongrid = GridLayout(tellwidth = false)
# l_sublayout = GridLayout()
# layout[1:3, 1] = l_sublayout
# l_sublayout[:v] = [scene3D, buttongrid]
# btn_RESET = Button(scene, label = "RESET")
# btn_ZOOM_in = Button(scene, label = "Zoom +")
# btn_ZOOM_out = Button(scene, label = "Zoom -")
# btn_PLAY_PAUSE = Button(scene, label = @lift($running ? "PAUSE" : " PLAY "))
# btn_AUTO = Button(scene, label = autolabel)
# btn_PARKING = Button(scene, label = "Parking")
# btn_STOP = Button(scene, label = "STOP")
# sw = Toggle(scene, active = false)
# label = Label(scene, "repeat")
# buttongrid[1, 1:9] = [btn_PLAY_PAUSE, btn_ZOOM_in, btn_ZOOM_out, btn_RESET, btn_AUTO, btn_PARKING, btn_STOP, sw, label]
# gl_screen = display(scene)
# s = Viewer3D(scene, layout, scene3D, cam, gl_screen, btn_RESET, btn_ZOOM_in, btn_ZOOM_out, btn_PLAY_PAUSE, btn_AUTO, btn_PARKING, btn_STOP, 0, 0, show_kite, false)
# init_system(s.scene3D; show_kite=show_kite)
# camera = cameracontrols(s.scene3D.scene)
# reset_view(camera, s.scene3D)
# on(s.btn_RESET.clicks) do c
# reset_view(camera, s.scene3D)
# zoom[1] = 1.0
# end
# on(s.btn_ZOOM_in.clicks) do c
# zoom[1] *= 1.2
# reset_and_zoom(camera, s.scene3D, zoom[1])
# end
# on(s.btn_ZOOM_out.clicks) do c
# zoom[1] /= 1.2
# reset_and_zoom(camera, s.scene3D, zoom[1])
# end
# status[] = "Stopped"
# return s
scene3D
end
# function save_png(viewer; filename="video", index = 1)
# buffer = IOBuffer()
# @printf(buffer, "%06i", index)
# save(filename * String(take!(buffer)) * ".png", viewer.scene)
# end