From 2285f601e8f1717af49938d2dfc85539714e6551 Mon Sep 17 00:00:00 2001 From: march3 Date: Sun, 16 Apr 2023 20:43:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=A4=A9=E4=BD=93=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E5=80=BE=E6=96=9C=E5=8F=82=E6=95=B0=EF=BC=8C=E5=9C=B0?= =?UTF-8?q?=E7=90=83=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E7=94=B1=E4=BA=8E=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=80=BE=E6=96=9C=E7=9A=84parent=20entity=EF=BC=8C=E6=89=80?= =?UTF-8?q?=E4=BB=A5=EF=BC=8C=E6=94=B9=E5=8A=A8=E6=AF=94=E8=BE=83=E5=A4=A7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sim_scenes/science/free_fall_of_ball.py | 2 +- simulators/ursina/entities/entity_utils.py | 4 +-- simulators/ursina/entities/planet.py | 38 +++++++++++++++------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/sim_scenes/science/free_fall_of_ball.py b/sim_scenes/science/free_fall_of_ball.py index a4669c2..ff85488 100644 --- a/sim_scenes/science/free_fall_of_ball.py +++ b/sim_scenes/science/free_fall_of_ball.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import Moon, Earth, Body +from bodies import Earth, Body from objs import Football from common.consts import SECONDS_PER_HOUR, SECONDS_PER_MINUTE from sim_scenes.func import ursina_run diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index 0f603d7..bb9c2f3 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -39,7 +39,7 @@ def create_name_text(parent): return name_text -def trail_init(parent): +def trail_init(parent, scale): """ 拖尾球体的初始化 @return: @@ -52,7 +52,7 @@ def trail_init(parent): trail_color = adjust_brightness(trail_color, 0.4) parent.trail_color = color.rgba(trail_color[0], trail_color[1], trail_color[2], 0.6) # 拖尾球体的大小为该天体的 1/5 - parent.trail_scale = parent.scale_x / 5 + parent.trail_scale = scale / 5 if parent.trail_scale < 1: # 如果太小,则 pass diff --git a/simulators/ursina/entities/planet.py b/simulators/ursina/entities/planet.py index 63533e3..fba2d4b 100644 --- a/simulators/ursina/entities/planet.py +++ b/simulators/ursina/entities/planet.py @@ -36,6 +36,7 @@ class Planet(Entity): if hasattr(self.body, "rotation_speed"): self.rotation_speed = self.body.rotation_speed self.rotMode = 'x' # random.choice(["x", "y", "z"]) + self.name = body_view.name pos = body_view.position * self.body.distance_scale * UrsinaConfig.SCALE_FACTOR @@ -97,6 +98,21 @@ class Planet(Entity): rotation=rotation, double_sided=True ) + if hasattr(self.body, "rotate_angle"): + if self.body.rotate_angle != 0: + self.rotate_angle = self.body.rotate_angle + self.main_entity = Entity() + self.main_entity.rotation_x = self.rotate_angle + self.main_entity.body_view = self.body_view + self.main_entity.body = self.body + self.parent = self.main_entity + self.position = [0, 0, 0] + else: + self.rotate_angle = 0 + self.main_entity = self + else: + self.rotate_angle = 0 + self.main_entity = self if hasattr(self.body, "torus_stars"): # 星环小天体群(主要模拟小行星群,非一个天体) @@ -105,7 +121,7 @@ class Planet(Entity): else: # 一个天体 # 拖尾球体的初始化 - trail_init(self) + trail_init(self.main_entity, self.scale_x) if hasattr(self.body, "is_fixed_star"): if self.body.is_fixed_star: @@ -141,9 +157,9 @@ class Planet(Entity): # self.x = -pos[1] # self.y = pos[2] # self.z = pos[0] - self.x = pos[0] - self.y = pos[1] - self.z = pos[2] + self.main_entity.x = pos[0] + self.main_entity.y = pos[1] + self.main_entity.z = pos[2] else: self.follow_parent() @@ -183,9 +199,9 @@ class Planet(Entity): if UrsinaConfig.show_trail: # 有时候第一个位置不正确,所以判断一下有历史记录后在创建 if len(self.body.his_position()) > 1: - create_trails(self) + create_trails(self.main_entity) else: - clear_trails(self) + clear_trails(self.main_entity) if hasattr(self, "name_text"): d = (camera.world_position - self.name_text.world_position).length() @@ -213,18 +229,18 @@ class Planet(Entity): # self.x = -pos[1] # self.y = pos[2] # self.z = pos[0] - self.x = pos[0] - self.y = pos[1] - self.z = pos[2] + self.main_entity.x = pos[0] + self.main_entity.y = pos[1] + self.main_entity.z = pos[2] def destroy_all(self): # 从天体系统中移除自己(TODO:暂时还不能移除) # self.body_view.bodies_system.bodies.remove(self.body) # 删除拖尾 - clear_trails(self) + clear_trails(self.main_entity) # 如果有行星环,则删除行星环 if hasattr(self, "ring"): - destroy(self.ring) + destroy(self.main_entity.ring) self.body.appeared = False self.body_view.appeared = False # 最后删除自己 -- GitLab