diff --git a/simulators/ursina/ui_component.py b/simulators/ursina/ui_component.py index b6e793be28e5693bcad1e47bd99a691efac22d6b..c0e203713f0230fb0ab4aec672e992f85139e504 100644 --- a/simulators/ursina/ui_component.py +++ b/simulators/ursina/ui_component.py @@ -16,12 +16,12 @@ from simulators.ursina.ursina_config import UrsinaConfig class UiSlider(Slider): - def __init__(self, text, min=0.01, max=3, default=1): + def __init__(self, text, min=0.01, max=3, step=.01, default=1): # Text.default_font = 'msyhl.ttc' # 'simsun.ttc' super().__init__(text=text, height=Text.size, y=-.6, - step=.01, + step=step, min=min, max=max, default=default, @@ -35,10 +35,9 @@ class UiSlider(Slider): # self.height *= 8/10 - class SwithButton(ButtonGroup): def __init__(self, options, default, tooltips=None): - super().__init__(options, min_selection=1,default=default, + super().__init__(options, min_selection=1, default=default, selected_color=color.rgba(0.1, 0.6, 0.1, 1.0), ignore_paused=True, color=color.rgba(0.0, 0.0, 0.0, 0.5)) # self.label.scale = 0.8 diff --git a/simulators/ursina/ursina_config.py b/simulators/ursina/ursina_config.py index e685ae9db377d67418f12ab22b3f90a37c60457f..e73270b293c9efe0853f06eb6464418adf5f9e43 100644 --- a/simulators/ursina/ursina_config.py +++ b/simulators/ursina/ursina_config.py @@ -11,15 +11,15 @@ class UrsinaConfig: # 常量定义 - # 天体缩放的因子(不能太大,否则无法容得下大数量级的天体) - SCALE_FACTOR = 5e-10 + # 天体缩放的因子(不能太大,否则无法容得下大数量级的天体)调整 5e-7 最佳 + SCALE_FACTOR = 5e-7 # 旋转因子为1,则为正常的转速 ROTATION_SPEED_FACTOR = 1.0 # ROTATION_SPEED_FACTOR = 0.01 # 中文字体(微软雅黑) CN_FONT = "msyhl.ttc" # 'simsun.ttc' 仿宋体 - CN_FONT = 'simsun.ttc' # 仿宋体 + # CN_FONT = 'simsun.ttc' # 仿宋体 # 速度的倍数 __run_speed_factor = 1.0 @@ -37,6 +37,8 @@ class UrsinaConfig: trail_length = 200 # 默认秒数(0表示默认) seconds_per = 0 + # # 控制摄像机动作速度(天体越大,速度越快,天体越小,速度越慢) + # control_camera_speed = 1 __body_size_factor = 1.0 diff --git a/simulators/ursina/ursina_ui.py b/simulators/ursina/ursina_ui.py index 5231a42ff095bd834b536b83dcda424a9c086e3e..1c5112c1c6e58586d31f9b936040d92bdf5ae16e 100644 --- a/simulators/ursina/ursina_ui.py +++ b/simulators/ursina/ursina_ui.py @@ -27,12 +27,12 @@ class UrsinaUI: self.no_trail_button_text = "○ " self.trail_button_text = "○--" - application.time_scale = 0.5 + # application.time_scale = 0.5 self.slider_body_spin_factor = UiSlider(text='自转速度', min=0.01, max=30, default=1) self.slider_body_size_factor = UiSlider(text='天体缩放', min=0.1, max=100, default=1) self.slider_run_speed_factor = UiSlider(text="运行速度", min=0.01, max=80, default=1) - self.slider_control_speed_factor = UiSlider(text="控制速度", min=0.01, max=30, default=application.time_scale) - self.slider_trail_length = UiSlider(text="拖尾长度", min=30, max=500, default=UrsinaConfig.trail_length) + self.slider_control_speed_factor = UiSlider(text="控制速度", min=0.01, max=50, default=application.time_scale) + self.slider_trail_length = UiSlider(text="拖尾长度", min=30, max=500, step=10, default=UrsinaConfig.trail_length) self.slider_body_size_factor.on_value_changed = self.on_slider_body_size_changed self.slider_body_spin_factor.on_value_changed = self.on_slider_body_spin_changed diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index 6e27ba261c081f421e0b0ca0e6faec22647a709d..69012e9ef0da2bc40e4485e9d25f501f693b20e3 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -8,7 +8,7 @@ # ============================================================================== # pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \ - load_texture, held_keys + load_texture, held_keys, distance from ursina.prefabs.first_person_controller import FirstPersonController from simulators.ursina.ursina_event import UrsinaEvent @@ -57,9 +57,25 @@ class UrsinaSimulator(Simulator): self.ursina_views.append(view) # planets.append(newPlanet) # x += cp[i] * 10 - + self.adj_application_time_scale() UrsinaEvent.on_searching_bodies_subscription(type(self).__name__, self.on_searching_bodies) + def adj_application_time_scale(self): + max_distance = 0 + for b1 in self.body_views: + for b2 in self.body_views: + if b1 is b2: + continue + d = distance(b1.planet, b2.planet) + if d > max_distance: + max_distance = d + + # UrsinaConfig.control_camera_speed = round(max_distance * 10, 2) + time_scale = round(pow(max_distance, 1 / 3), 2) + if time_scale < 0.01: + time_scale = 0.01 + application.time_scale = time_scale + def on_searching_bodies(self, **kwargs): views = [] for view in self.body_views: