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

太阳系三体模拟器

上级 7904d98f
......@@ -80,11 +80,11 @@ class System(object):
"""
if not body.appeared: # 不显示
return False
if self.max_distance > 0:
# 超过了 max_distance 距离,则不显示,并消失
if calculate_distance(body.position) > self.max_distance:
body.appeared = False
return False
# if self.max_distance > 0:
# # 超过了 max_distance 距离,则不显示,并消失
# if calculate_distance(body.position) > self.max_distance:
# body.appeared = False
# return False
return True
......
......@@ -28,6 +28,10 @@ class UrsinaConfig:
__on_reset_funcs = []
show_trail = False
# 拖尾球体的数量
trail_length = 200
@property
@classmethod
def run_speed_factor(cls):
......
......@@ -39,10 +39,23 @@ class UrsinaUI:
self.slider_body_spin_factor.on_value_changed = self.on_slider_body_spin_changed
self.slider_run_speed_factor.on_value_changed = self.on_slider_run_speed_changed
self.slider_control_speed_factor.on_value_changed = self.on_slider_control_speed_changed
self.slider_trail_length = Slider(text="拖尾长度", y=-.1, step=1, min=30, max=500, default=UrsinaConfig.trail_length,
color=color.rgba(0.0, 0.0, 0.0, 0.5))
self.slider_trail_length.on_value_changed = self.on_slider_trail_length_changed
self.on_off_switch = ButtonGroup(('||', '○'), min_selection=1, y=0, default='○',
selected_color=color.green, ignore_paused=True,
color=color.rgba(0.0, 0.0, 0.0, 0.5))
self.on_off_switch.selected_color = color.red
self.on_off_trail = ButtonGroup((' ', '...'), min_selection=1, y=0, default=' ',
selected_color=color.green, ignore_paused=True,
color=color.rgba(0.0, 0.0, 0.0, 0.5))
self.on_off_trail.on_value_changed = self.on_off_trail_changed
self.point_button = Button(text='寻找', origin=(0, 0), y=2,
on_click=self.on_point_button_click, color=color.rgba(0.0, 0.0, 0.0, 0.5))
self.reset_button = Button(text='重置', origin=(0, 0), y=2,
......@@ -57,6 +70,8 @@ class UrsinaUI:
self.point_button,
self.reset_button,
self.on_off_switch,
self.on_off_trail,
self.slider_trail_length,
self.slider_body_spin_factor,
self.slider_run_speed_factor,
self.slider_control_speed_factor
......@@ -67,6 +82,12 @@ class UrsinaUI:
wp.x = -wp.scale_x
self.wp = wp
def on_off_trail_changed(self):
if self.on_off_trail.value == "...":
UrsinaConfig.show_trail = True
else:
UrsinaConfig.show_trail = False
def on_point_button_click(self):
pass
......@@ -81,6 +102,9 @@ class UrsinaUI:
self.on_off_switch.selected_color = color.red
application.paused = False
def on_slider_trail_length_changed(self):
UrsinaConfig.trail_length = int(self.slider_trail_length.value)
def on_slider_control_speed_changed(self):
application.time_scale = self.slider_control_speed_factor.value
......
......@@ -76,19 +76,9 @@ class Planet(Entity):
def on_reset(self):
# 删除拖尾
for entity, pos in self.trails.items():
destroy(entity)
self.clear_trails()
self.body_view.body.reset()
# pos = body.init_position * body.distance_scale * UrsinaConfig.SCALE_FACTOR
# vel = body.init_velocity
# self.x = -pos[1]
# self.y = pos[2]
# self.z = pos[0]
# self.x = pos[0]
# self.y = pos[1]
# self.z = pos[2]
def __init__(self, body_view: BodyView):
self.body_view = body_view
self.rotation_speed = self.body_view.body.rotation_speed
......@@ -139,8 +129,6 @@ class Planet(Entity):
"""
# 存放拖尾球体
self.trails = {}
# 拖尾球体的数量
self.trail_len = 100
# 根据天体的颜色获取拖尾的颜色
trail_color = conv_to_vec4_color(self.body_view.body.color)
......@@ -190,7 +178,7 @@ class Planet(Entity):
self.trails[self.create_trail(pos)] = pos
# 计算拖尾球体超过的数量
trail_overflow_count = len(self.trails) - self.trail_len
trail_overflow_count = len(self.trails) - UrsinaConfig.trail_length
if trail_overflow_count > 0:
# 如果拖尾球体超过的数量,就删除之前的拖尾球体
......@@ -248,9 +236,12 @@ class Planet(Entity):
self.rotation_y,
self.rotation_z)
# 有时候第一个位置不正确,所以判断一下有历史记录后在创建
if len(self.body_view.body.his_position()) > 1:
self.create_trails()
if UrsinaConfig.show_trail:
# 有时候第一个位置不正确,所以判断一下有历史记录后在创建
if len(self.body_view.body.his_position()) > 1:
self.create_trails()
else:
self.clear_trails()
def follow_parent(self):
if not hasattr(self.body_view, "bodies_system"):
......@@ -284,13 +275,18 @@ class Planet(Entity):
# 设置行星环不受灯光影响,否则看不清行星环
self.ring.set_light_off()
def clear_trails(self):
if not hasattr(self, "trails"):
return
# 删除拖尾
for entity, pos in self.trails.items():
destroy(entity)
def destroy_all(self):
# 从天体系统中移除自己(TODO:暂时还不能移除)
# self.body_view.bodies_system.bodies.remove(self.body_view.body)
# 删除拖尾
for entity, pos in self.trails.items():
destroy(entity)
self.clear_trails()
# 如果有行星环,则删除行星环
if hasattr(self, "ring"):
destroy(self.ring)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册