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

太阳系三体模拟器

上级 571f216c
...@@ -35,6 +35,8 @@ class UrsinaConfig: ...@@ -35,6 +35,8 @@ class UrsinaConfig:
show_trail = False show_trail = False
# 拖尾球体的数量 # 拖尾球体的数量
trail_length = 200 trail_length = 200
# 默认秒数(0表示默认)
seconds_per = 0
__body_size_factor = 1.0 __body_size_factor = 1.0
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \ from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \
load_texture, held_keys, Button, ButtonList, destroy, scene, distance, Sequence, Wait, Func load_texture, held_keys, Button, ButtonList, destroy, scene, distance, Sequence, Wait, Func
from ursina.prefabs.first_person_controller import FirstPersonController from ursina.prefabs.first_person_controller import FirstPersonController
from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, \
SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH, SECONDS_PER_YEAR
from common.consts import AU from common.consts import AU
from simulators.ursina.ui_component import UiSlider, SwithButton, UiButton from simulators.ursina.ui_component import UiSlider, SwithButton, UiButton
from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_config import UrsinaConfig
...@@ -50,6 +51,7 @@ class UrsinaUI: ...@@ -50,6 +51,7 @@ class UrsinaUI:
tooltips=("系统默认", "每秒相当于1天", "每秒相当于1周", tooltips=("系统默认", "每秒相当于1天", "每秒相当于1周",
"每秒相当于1个月", "每秒相当于1个月",
"每秒相当于1年", "每秒相当于十年", "每秒相当于1百年")) "每秒相当于1年", "每秒相当于十年", "每秒相当于1百年"))
self.sec_per_time_switch.on_value_changed = self.sec_per_time_switch_changed
self.on_off_trail = SwithButton((self.no_trail_button_text, self.trail_button_text), self.on_off_trail = SwithButton((self.no_trail_button_text, self.trail_button_text),
default=self.no_trail_button_text, default=self.no_trail_button_text,
...@@ -95,9 +97,9 @@ class UrsinaUI: ...@@ -95,9 +97,9 @@ class UrsinaUI:
), ignore_paused=True, color=color.rgba(0.0, 0.0, 0.0, 0.5) # , popup=True ), ignore_paused=True, color=color.rgba(0.0, 0.0, 0.0, 0.5) # , popup=True
) )
self.sec_per_time_switch.x = -0.5 self.sec_per_time_switch.x = -0.4
self.on_off_switch.x = -0.2 self.on_off_switch.x = 0.2
self.on_off_trail.x = -0.2 self.on_off_trail.x = -0.4
wp.y = 0.5 # wp.panel.scale_y / 2 * wp.scale_y # center the window panel wp.y = 0.5 # wp.panel.scale_y / 2 * wp.scale_y # center the window panel
wp.x = 0.6 # wp.scale_x + 0.1 wp.x = 0.6 # wp.scale_x + 0.1
# wp.x = 0#wp.panel.scale_x / 2 * wp.scale_x # wp.x = 0#wp.panel.scale_x / 2 * wp.scale_x
...@@ -136,13 +138,30 @@ class UrsinaUI: ...@@ -136,13 +138,30 @@ class UrsinaUI:
destroy(message_box) destroy(message_box)
s = Sequence( s = Sequence(
Wait(3), Wait(close_time),
Func(close_message) Func(close_message)
) )
s.start() s.start()
# # 使用 time 模块来实现定时关闭 # # 使用 time 模块来实现定时关闭
# invoke(close_message, delay=close_time) # invoke(close_message, delay=close_time)
def sec_per_time_switch_changed(self):
# ("默认", "天", "周", "月", "年", "十年", "百年")
if self.sec_per_time_switch.value == "天":
UrsinaConfig.seconds_per = SECONDS_PER_DAY
elif self.sec_per_time_switch.value == "周":
UrsinaConfig.seconds_per = SECONDS_PER_WEEK
elif self.sec_per_time_switch.value == "月":
UrsinaConfig.seconds_per = SECONDS_PER_MONTH
elif self.sec_per_time_switch.value == "年":
UrsinaConfig.seconds_per = SECONDS_PER_YEAR
elif self.sec_per_time_switch.value == "十年":
UrsinaConfig.seconds_per = SECONDS_PER_YEAR * 10
elif self.sec_per_time_switch.value == "百年":
UrsinaConfig.seconds_per = SECONDS_PER_YEAR * 100
else:
UrsinaConfig.seconds_per = 0
def on_off_trail_changed(self): def on_off_trail_changed(self):
if self.on_off_trail.value == self.trail_button_text: if self.on_off_trail.value == self.trail_button_text:
UrsinaConfig.show_trail = True UrsinaConfig.show_trail = True
...@@ -164,10 +183,10 @@ class UrsinaUI: ...@@ -164,10 +183,10 @@ class UrsinaUI:
# 返回摄像机移动后的坐标 # 返回摄像机移动后的坐标
return camera_pos + move_vector return camera_pos + move_vector
def move_camera_to_entity(self,entity,d): def move_camera_to_entity(self, entity, d):
import math import math
# print("before",camera.position, entity.position) # print("before",camera.position, entity.position)
camera.position = entity.position #- Vec3(0, 0, d) # 设置摄像机位置 camera.position = entity.position # - Vec3(0, 0, d) # 设置摄像机位置
camera.world_position = entity.position camera.world_position = entity.position
# camera.rotation = (0, 0, 0) # 重置摄像机旋转角度 # camera.rotation = (0, 0, 0) # 重置摄像机旋转角度
...@@ -190,8 +209,11 @@ class UrsinaUI: ...@@ -190,8 +209,11 @@ class UrsinaUI:
# UrsinaConfig.SCALE_FACTOR # UrsinaConfig.SCALE_FACTOR
# import copy # import copy
# camera_rotation = copy.deepcopy(camera.rotation) # camera_rotation = copy.deepcopy(camera.rotation)
d = item.planet.scale_x * 20 try:
self.move_camera_to_entity(item.planet, d) d = item.planet.scale_x * 20
self.move_camera_to_entity(item.planet, d)
except Exception as e:
self.show_message(f"{item}飞不见了")
# d = distance(camera.position, item.planet.position) # d = distance(camera.position, item.planet.position)
# camera.look_at(item.planet) # camera.look_at(item.planet)
# if d > 1.5 * x: # if d > 1.5 * x:
......
...@@ -79,7 +79,12 @@ class UrsinaSimulator(Simulator): ...@@ -79,7 +79,12 @@ class UrsinaSimulator(Simulator):
def check_and_evolve(self): def check_and_evolve(self):
if self.check_elapsed_time(): if self.check_elapsed_time():
run_speed_factor = UrsinaConfig.run_speed_factor run_speed_factor = UrsinaConfig.run_speed_factor
super().evolve(self.evolve_dt * run_speed_factor) if UrsinaConfig.seconds_per == 0:
evolve_dt = self.evolve_dt * run_speed_factor
else:
evolve_dt = UrsinaConfig.seconds_per * run_speed_factor
super().evolve(evolve_dt)
def cosmic_background(self, texture='../textures/cosmic2.jpg'): def cosmic_background(self, texture='../textures/cosmic2.jpg'):
""" """
......
...@@ -111,8 +111,8 @@ class Planet(Entity): ...@@ -111,8 +111,8 @@ class Planet(Entity):
texture=texture, texture=texture,
color=color.white, color=color.white,
position=pos, position=pos,
rotation=rotation, rotation=rotation # ,double_sided=True
double_sided=True) )
if hasattr(self.body_view.body, "torus_stars"): if hasattr(self.body_view.body, "torus_stars"):
# 星环小天体群(主要模拟小行星群,非一个天体) # 星环小天体群(主要模拟小行星群,非一个天体)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册