-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.go
More file actions
59 lines (51 loc) · 1.84 KB
/
simulation.go
File metadata and controls
59 lines (51 loc) · 1.84 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
package main
import (
"FlightControl/ThreeDView"
"FlightControl/ThreeDView/camera"
"FlightControl/ThreeDView/object"
"FlightControl/ThreeDView/types"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"image/color"
)
func simulationTab() fyne.CanvasObject {
threeDEnv := ThreeDView.NewThreeDWidget()
threeDEnv.Hide()
threeDEnv.SetBackgroundColor(color.RGBA{R: 135, G: 206, B: 235, A: 255})
threeDEnv.SetTPSCap(1600)
if fyne.CurrentDevice().IsMobile() {
threeDEnv.SetFPSCap(30)
threeDEnv.SetResolutionFactor(0.3)
object.NewPlane(1000, types.Point3D{X: 0, Y: 0, Z: 0}, types.Rotation3D{Roll: 0, Pitch: 0, Yaw: 0}, color.RGBA{G: 255, A: 255}, threeDEnv, 4)
} else {
threeDEnv.SetResolutionFactor(0.5)
object.NewPlane(5000, types.Point3D{X: 0, Y: 0, Z: 0}, types.Rotation3D{Roll: 0, Pitch: 0, Yaw: 0}, color.RGBA{G: 255, A: 255}, threeDEnv, 5)
}
rocket := NewTwoStageRocket(types.Point3D{X: 0, Y: 0, Z: 0}, types.Rotation3D{Roll: 0, Pitch: 0, Yaw: 0}, threeDEnv)
envCamera := camera.NewCamera(types.Point3D{Y: 500, Z: 200}, types.Rotation3D{})
orbitController := camera.NewOrbitController(rocket)
envCamera.SetController(orbitController)
threeDEnv.SetCamera(&envCamera)
threeDEnv.RegisterTickMethod(func() {
rocket.Move(types.Point3D{X: 0, Y: 0, Z: 1})
orbitController.Update()
})
separateButton := widget.NewButton("Separate", func() {
rocket.SeparateStage()
})
separateButton.Resize(fyne.NewSize(100, 50))
buttonContainer := container.NewVBox(separateButton)
go func() {
selectedTabChannel := ps.Sub("selectedTab")
for selectedTab := range selectedTabChannel {
selectedTab := selectedTab.(*container.TabItem)
if selectedTab.Text == "Simulation" {
threeDEnv.Show()
} else {
threeDEnv.Hide()
}
}
}()
return container.NewBorder(nil, buttonContainer, nil, nil, container.NewStack(threeDEnv))
}