diff --git a/common/system.py b/common/system.py index a41fed50f2884f41c9fd6c11188e13be10718816..a1dacf02f8b9e130f4c3d93a3df5055c53a3975c 100644 --- a/common/system.py +++ b/common/system.py @@ -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 diff --git a/simulators/ursina/ursina_config.py b/simulators/ursina/ursina_config.py index c707b5ac30aded893452ea731e2e13b5e3df659c..9c094c9961a37cff8b73dc9666e9b2248034018b 100644 --- a/simulators/ursina/ursina_config.py +++ b/simulators/ursina/ursina_config.py @@ -28,6 +28,10 @@ class UrsinaConfig: __on_reset_funcs = [] + show_trail = False + # 拖尾球体的数量 + trail_length = 200 + @property @classmethod def run_speed_factor(cls): diff --git a/simulators/ursina/ursina_ui.py b/simulators/ursina/ursina_ui.py index 5d3921b8af127db9d163b95046776c150fb4bb9c..adcba8c5d17cbe6a579d8012a616a8c81e000c18 100644 --- a/simulators/ursina/ursina_ui.py +++ b/simulators/ursina/ursina_ui.py @@ -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 diff --git a/simulators/views/ursina_view.py b/simulators/views/ursina_view.py index 9e5480025c0064cc12dbe1636a76e620302fecf9..5356071848da79d692528a1eb371bcfdb05ac690 100644 --- a/simulators/views/ursina_view.py +++ b/simulators/views/ursina_view.py @@ -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)