提交 02fa3606 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 28e024d5
......@@ -33,21 +33,22 @@ class HalleyCometSim:
def build_solar_system(self):
# region 构建太阳系
self.sun = Sun(size_scale=0.8e2, show_trail=False)
self.mercury = Mercury(size_scale=5e3, show_trail=False)
self.venus = Venus(size_scale=5e3, show_trail=False)
self.earth = Earth(size_scale=5e3, rotate_angle=0, show_trail=False)
self.mars = Mars(size_scale=5e3, show_trail=False)
self.jupiter = Jupiter(size_scale=2.5e3, show_trail=False)
self.saturn = Saturn(size_scale=2.5e3, show_trail=False)
self.uranus = Uranus(size_scale=6e3, show_trail=False)
self.neptune = Neptune(size_scale=6e3, show_trail=False)
self.pluto = Pluto(size_scale=1e5, show_trail=False)
show_trail = True
self.sun = Sun(size_scale=0.8e2, show_trail=show_trail)
self.mercury = Mercury(size_scale=5e3, show_trail=show_trail)
self.venus = Venus(size_scale=5e3, show_trail=show_trail)
self.earth = Earth(size_scale=5e3, rotate_angle=0, show_trail=show_trail)
self.mars = Mars(size_scale=5e3, show_trail=show_trail)
self.jupiter = Jupiter(size_scale=2.5e3, show_trail=show_trail)
self.saturn = Saturn(size_scale=2.5e3, show_trail=show_trail)
self.uranus = Uranus(size_scale=6e3, show_trail=show_trail)
self.neptune = Neptune(size_scale=6e3, show_trail=show_trail)
self.pluto = Pluto(size_scale=1e5, show_trail=show_trail)
self.bodies = [
self.sun, # 太阳
# self.mercury, # 水星
# self.venus, # 金星
# self.earth, # 地球
self.mercury, # 水星
self.venus, # 金星
self.earth, # 地球
self.mars, # 火星
self.jupiter, # 木星
self.saturn, # 土星
......@@ -55,6 +56,11 @@ class HalleyCometSim:
self.neptune, # 海王星
# self.pluto, # 冥王星
]
self.bodies = [
self.sun, # 太阳
self.mars, # 火星
self.neptune, # 海王星
]
# endregion
init_bodies_reality_pos_vels(self.bodies)
......@@ -81,7 +87,7 @@ class HalleyCometSim:
def build(self):
self.build_solar_system()
self.build_halley_comet()
# self.build_halley_comet()
def calculate_rotation_angles(self, point1, point2):
dx = point2.x - point1.x
......@@ -107,13 +113,13 @@ class HalleyCometSim:
return angle_x, angle_y, angle_z
def calculate_angles(self, point1, point2):
import numpy as np
# 计算向量AB
AB = point2 - point1
# 计算向量AB与x轴、y轴和z轴之间的夹角
angle_x = np.degrees(np.arctan2(AB.y, AB.x))
angle_y = np.degrees(np.arctan2(AB.z, np.sqrt(AB.x ** 2 + AB.y ** 2)))
angle_z = np.degrees(np.arctan2(np.sqrt(AB.x ** 2 + AB.y ** 2), AB.z))
angle_x = math.degrees(math.atan2(AB.z, AB.y))
angle_y = math.degrees(math.atan2(AB.z, AB.x))
angle_z = math.degrees(math.atan2(AB.y, AB.x))
return angle_x, angle_y, angle_z
def on_ready(self):
......@@ -125,6 +131,7 @@ class HalleyCometSim:
from ursina import scene
UrsinaConfig.trail_type = "line"
UrsinaConfig.trail_length = 91
UrsinaConfig.trail_length = 1000
UrsinaConfig.trail_thickness_factor = 3
# camera.clip_plane_near = 0.1
camera.clip_plane_far = 1000000
......@@ -167,9 +174,9 @@ body.position - sun.position
# orbit_line.rotation_y = rotation_y + 120
# #
# angle = math.atan2(relative_position.y, relative_position.x)
orbit_line.rotation_x = angle_x + 90
orbit_line.rotation_y = angle_y + 180
orbit_line.rotation_z = angle_z
orbit_line.rotation_x = angle_x
orbit_line.rotation_y = angle_y # - 50
orbit_line.rotation_z = -angle_z
orbit_line.body = body
......@@ -183,6 +190,7 @@ body.position - sun.position
@param time_data:
@return:
"""
if hasattr(self, "self.halley_comet"):
# 哈雷彗星飞行的翻转效果
if self.halley_comet.planet.enabled:
self.halley_comet.planet.rotation_x += 0.1
......@@ -207,6 +215,9 @@ if __name__ == '__main__':
"""
sim = HalleyCometSim()
sim.build()
# 订阅事件后,上面2个函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent.on_timer_changed_subscription(sim.on_timer_changed)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册