From e2a288180d0f11f4abe4fadff26354872d76453c Mon Sep 17 00:00:00 2001 From: march3 Date: Fri, 17 Mar 2023 22:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E9=98=B3=E7=B3=BB=E4=B8=89=E4=BD=93?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simulators/ursina/ui_component.py | 7 +++---- simulators/ursina/ursina_config.py | 8 +++++--- simulators/ursina/ursina_ui.py | 6 +++--- simulators/ursina_simulator.py | 20 ++++++++++++++++++-- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/simulators/ursina/ui_component.py b/simulators/ursina/ui_component.py index b6e793b..c0e2037 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 e685ae9..e73270b 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 5231a42..1c5112c 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 6e27ba2..69012e9 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: -- GitLab