-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
114 lines (88 loc) · 2.57 KB
/
main.py
File metadata and controls
114 lines (88 loc) · 2.57 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
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
from objects import Vector3D, PI, Planet, Simulation
from ursina.shaders import lit_with_shadows_shader
from ursina import *
import typing as tp
import time
SIM: Simulation
START = time.perf_counter()
TIME_SCALE = 1
# sim settings
PAUSE = True
WAS_LAST_HELD: tp.List[str] = []
def update() -> None:
"""
called by ursina
"""
global START, PAUSE
now = time.perf_counter()
dt = now-START
START = now
if held_keys["down arrow"]:
camera.rotation_x += 1
if held_keys["up arrow"]:
camera.rotation_x -= 1
if held_keys["left arrow"]:
camera.rotation_y -= 1
if held_keys["right arrow"]:
camera.rotation_y += 1
if held_keys["w"]:
camera.y += .1
if held_keys["s"]:
camera.y -= .1
if held_keys["a"]:
camera.x -= .1
if held_keys["d"]:
camera.x += .1
if held_keys["p"]:
if not "p" in WAS_LAST_HELD:
PAUSE = not PAUSE
WAS_LAST_HELD.append("p")
else:
if "p" in WAS_LAST_HELD:
WAS_LAST_HELD.remove("p")
if not PAUSE:
SIM.iter(dt*TIME_SCALE)
def main() -> None:
"""
main program
"""
global SIM
app = Ursina()
EditorCamera()
# configure window
window.title = '3dGravitySim'
window.borderless = True
window.fullscreen = True
window.exit_button.visible = False
window.fps_counter.enabled = True
window.color=(0, 0, 0, 0)
# stuff
SIM = Simulation([
Planet(name="1", diameter=0.5, mass=2, position=Vector3D.from_cartesian(-1, 0, 0),
velocity=Vector3D.from_polar(angle_xy=0, angle_xz=0, length=1)),
Planet(name="2", diameter=0.5, mass=2, position=Vector3D.from_cartesian(0, 0, 0)),
Planet(name="2", diameter=0.5, mass=3, position=Vector3D.from_cartesian(0.5, 0.2, 0.1)),
Planet(name="2", diameter=0.5, mass=2, position=Vector3D.from_cartesian(1, 0, 0))
])
# setup camera
camera.x = 0
camera.y = 2
camera.z = 0
# create floor plane
Entity(model='plane', scale=10, color=color.black,
x=0, y=-1 , z=0,
shader=lit_with_shadows_shader)
# create lighting
pivot = Entity()
DirectionalLight(parent=pivot, y=2, z=3, shadows=True, rotation=(45, -45, 45))
# load coordinate system file
# sys = load_model("coord_sys", path=Path("/home/nilusink/Documents/assets/simple_coord_system.obj"))
# Entity(model=sys,
# x=0,
# y=0,
# z=0,
# origin=(0, 0))
# start app
app.run()
if __name__ == "__main__":
main()