-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
166 lines (131 loc) · 5.01 KB
/
app.py
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
from ursina import *
import time
import data
width = 6000
height = 4000
app = Ursina(title='Astroworlds', width = 600, height = 400)
Earth = Entity(model="sphere", texture="earth.jpg")
Moon = Entity(model="sphere", texture="moon.jpg")
Orion = Entity(model="Orion.obj")
Arrow = Entity(model="ballcam.obj", position=(-5, 39.588, -15), scale=2.6, color=color.gray)
orionSpeed = 1
key_text = Text(
text="KEY:\nGreen: Rocket Going\nBlue: Rocket Coming Back",
position=(-.85, .50),
color=color.white,
scale=0.8
)
txt = Text(text="X = " + str(time.dt + 1), position=(-.28, .4))
txt2 = Text(text="Z = " + str(time.dt + 1), position=(-.28, .4))
txt3 = Text(text="Y = " + str(time.dt + 1), position=(-.28, .4))
# orionSpeed = 5
txt4 = Text(text="Orion Speed = " + str(orionSpeed), position=(-.85, .3))
#for time timer
elapsedTime = 0
timerText = Text(text="00:00", position=(-.78, .43))
a = Audio("assets/sounds/woosh.mp3", loop=False, autoplay=False)
earthLock = False
moonLock = False
orionLock = False
window.color = color.black
# Set up Moon
Moon.scale = (50,50,50)
Moon.position = (float(data.orionX[6489]) / 100, float(data.orionY[6150]) / 100, float(data.orionZ[6489]) / 100)
# Set up Earth
Earth.scale = (75,75,75)
# Orion
Orion.scale = 0.09
orionX = data.orionX[1]
orionY = data.orionY[2]
orionZ = data.orionZ[3]
cout = 0
# Create a custom camera
camera_pivot = Entity()
camera.parent = camera_pivot
editor_camera = EditorCamera(enabled=True)
# Initial camera setup
camera.position = (0, 0, -40)
camera_pivot.enabled = False
size = len(data.orionX) - 3
half = 6488 # I think this is half
points = []
otherPoints = []
for i in range(1, size - half):
points.append(Vec3(float(data.orionX[i]) / 100, float(data.orionY[i]) / 100, float(data.orionZ[i]) / 100))
curve_renderer = Entity(model=Mesh(vertices=points, mode='line'), color=color.green)
for i in range(size-half, size):
otherPoints.append(Vec3(float(data.orionX[i]) / 100, float(data.orionY[i]) / 100, float(data.orionZ[i]) / 100))
second_curve_renderer = Entity(model=Mesh(vertices=otherPoints, mode='line'), color=color.blue)
#for i in range(1, len(data.orionX) - 3):
# Entity(model="sphere", position=(float(data.orionX[i])/100, float(data.orionY[i])/100, float(data.orionZ[i])/100), scale=2, color=color.red)
def input(key):
global earthLock, moonLock, a, orionLock, orionSpeed
if key == 'f':
a.play()
moonLock = False
earthLock = not earthLock
# Toggle between EditorCamera and locked camera
editor_camera.enabled = not earthLock
camera_pivot.enabled = earthLock
elif key == 'm':
a.play()
earthLock = False
moonLock = not moonLock
editor_camera.enabled = not moonLock
camera_pivot.enabled = moonLock
elif key == 'r': # New key to focus on Orion
a.play()
earthLock = False
moonLock = False
orionLock = not orionLock
editor_camera.enabled = not orionLock
camera_pivot.enabled = orionLock
elif key == 'g' and orionSpeed < 15:
# Slow Down Time
application.time_scale += 1
orionSpeed += 1
if application.time_scale >= 15:
application.time_scale = 15
elif key == 'h' and orionSpeed > 0:
application.time_scale -= 1
orionSpeed -= 1
if application.time_scale < 0:
application.time_scale = 0
def update():
global orionX, orionZ, orionY, elapsedTime, cout, orionSpeed
cout += orionSpeed
if cout >= len(data.orionX):
cout = 0
x_value = data.orionX[cout] if cout < len(data.orionX) else '0'
y_value = data.orionY[cout] if cout < len(data.orionY) else '0'
z_value = data.orionZ[cout] if cout < len(data.orionZ) else '0'
Orion.position = (float(x_value) / 100, float(y_value) / 100, float(z_value) / 100)
txt.text = "X = " + str(x_value)
txt.position = (-.78, .4)
txt2.text = "Y = " + str(y_value)
txt2.position = (-.78, .37)
txt3.text = "Z = " + str(z_value)
txt3.position = (-.78, .34)
Earth.rotation_y += time.dt
Orion.look_at(Moon)
# Smooth camera following
if earthLock:
target_pos = Earth.position + Vec3(0, 3, -5)
camera_pivot.position = lerp(camera_pivot.position, target_pos, time.dt * 5)
camera_pivot.look_at(Earth)
elif moonLock:
target_pos = Moon.position + Vec3(0, 3, -5)
camera_pivot.position = lerp(camera_pivot.position, target_pos, time.dt * 5)
camera_pivot.look_at(Moon)
# orionX += time.dt*5
#Orion.position = (orionX, orionY, orionZ)
Arrow.look_at(Orion, axis="up")
txt4.text="Orion speed = " + str(orionSpeed)
# txt4.position = (0, 0)
elapsedTime += time.dt
mins = int(elapsedTime) // 60
secs = int(elapsedTime) % 60
timerText.text = f"{mins:02}:{secs:02}"
skybox_image = load_texture("stars.jpg")
Sky(texture=skybox_image)
app.run()