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

Python超人-宇宙模拟器

上级 d9c2d475
......@@ -51,6 +51,7 @@ class HalleyCometSim(HalleyCometSimBase):
@return:
"""
self.build_solar_system(ignore_gravity=True, start_time=self.start_time)
self.sun.glows = (80, 1.005, 0.01)
# 创建哈雷彗星创建哈雷彗星
self.halley_comet = create_halley_comet(self.params.init_velocity, self.params.init_position)
self.bodies.append(self.halley_comet)
......@@ -72,9 +73,6 @@ class HalleyCometSim(HalleyCometSimBase):
# UrsinaConfig.trail_length = 180
UrsinaConfig.trail_factor = 3
# r = 1
# self.set_window_size((int(1920 * r), int(1080 * r)), True)
# camera.clip_plane_near = 0.1
camera.clip_plane_far = 1000000
......@@ -83,22 +81,6 @@ class HalleyCometSim(HalleyCometSimBase):
camera_move_update()
# camera_move_to_target_update()
def on_ready(self):
"""
事件绑定后,模拟器运行前会触发
@return:
"""
# 初始化设置
self.init_settings()
# 显示网格以及坐标线
# self.show_grid_axises()
# 创建太阳系天体的真实轨迹(太阳和哈雷彗星除外)
self.create_orbit_lines()
# 创建信息显示面板
self.text_panel = create_text_panel()
def create_orbit_lines(self):
"""
创建太阳系天体的真实轨迹(太阳和哈雷彗星除外)
......@@ -185,7 +167,7 @@ class HalleyCometSim(HalleyCometSimBase):
@param dt:
@return:
"""
milestones = [("1986-02-09", (0, 2, 0)), ("2023-12-09", (0, -2, 0)), ("2061-07-28", (0, 2, 0))]
milestones = [("1986-02-09", (0, 2, 0)), ("2023-12-09", (0, 2, 0)), ("2061-07-28", (0, 2, 0))]
for milestone, pos in milestones:
prop_name = f"milestone_{milestone}"
if not hasattr(self, prop_name) and dt.strftime("%Y-%m-%d") >= milestone:
......@@ -230,30 +212,6 @@ class HalleyCometSim(HalleyCometSimBase):
cond_cb=lambda ps: ps["next_cond"] > dt.year >= ps["cond"],
value_conv=self.s_f)
def on_timer_changed(self, time_data):
"""
@param time_data:
@return:
"""
dt = time_data.get_datetime(self.start_time)
# 摄像机看向哈雷彗星
camera_look_at(self.halley_comet, rotation_z=0)
time_total_hours = time_data.total_hours
if not hasattr(self, "last_total_hours"):
self.last_total_hours = time_total_hours
self.update_halley_comet_info(dt)
# 每隔一段时间运行一次更新(不要太频繁更新,会导致摄像机抖动)
if time_total_hours - self.last_total_hours > 100:
self.camera_move(dt)
self.update_halley_comet_info(dt)
self.update_ui(time_data, dt)
# 记录最后更新的总耗时(小时)
self.last_total_hours = time_total_hours
def check_create_year_label(self, last_trail, dt):
"""
检测并创建年标签
......@@ -370,8 +328,8 @@ class HalleyCometSim(HalleyCometSimBase):
@param dt:
@return:
"""
if dt.year > 2058:
UrsinaConfig.trail_length = 155
if dt.year > 2045:
UrsinaConfig.trail_length = 211
# 更新天体的位置
self.set_bodies_position(time_data)
# 更新时钟
......@@ -380,6 +338,50 @@ class HalleyCometSim(HalleyCometSimBase):
# for i, orbit_line in enumerate(self.orbit_lines):
# orbit_line.position = self.sun.planet.position
def on_ready(self):
"""
事件绑定后,模拟器运行前会触发
@return:
"""
# 初始化设置
self.init_settings()
# self.set_window_size((int(1920 * r), int(1080 * r)), False)
# 最大分辨率的高度-1,保证不全屏
self.set_window_size((1920, 1079), False)
# self.set_window_size((1920 , 1080 ), False)
# 显示网格以及坐标线
# self.show_grid_axises()
# 创建太阳系天体的真实轨迹(太阳和哈雷彗星除外)
self.create_orbit_lines()
# 创建信息显示面板
self.text_panel = create_text_panel()
def on_timer_changed(self, time_data):
"""
@param time_data:
@return:
"""
dt = time_data.get_datetime(self.start_time)
# 摄像机看向哈雷彗星
camera_look_at(self.halley_comet, rotation_z=0)
time_total_hours = time_data.total_hours
if not hasattr(self, "last_total_hours"):
self.last_total_hours = time_total_hours
self.camera_move(dt)
self.update_halley_comet_info(dt)
# 每隔一段时间运行一次更新(不要太频繁更新,会导致摄像机抖动)
if time_total_hours - self.last_total_hours > 100:
self.update_ui(time_data, dt)
# 记录最后更新的总耗时(小时)
self.last_total_hours = time_total_hours
if __name__ == '__main__':
"""
......
......@@ -13,21 +13,27 @@ class UniverseSimScenes:
可以作为宇宙模拟场景的基类,但是不是必须的。
"""
@staticmethod
def set_window_size(size=(1536, 684), fullscreen=False):
from ursina import window
# window.x =-20
# window.y=-20
# window.position = (-20, -20)
if fullscreen:
# 设置窗口为全屏模式
window.fullscreen = True
else:
# 设置最大分辨率
# window.maximized = True
window.fullscreen = False
window.position = (0, 0)
# 设置窗口的宽度和高度
window.size = size
# self.set_window_size((3500, 1024))
# r = 1
# self.set_window_size((1920*2, 1080*2))
# self.set_window_size((int(1920 * r), int(1080 * r)))
# self.set_window_size((2376, 1080))
# self.set_window_size((520, 540), fullscreen=False)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册