diff --git a/sim_scenes/science/free_fall_of_ball.py b/sim_scenes/science/free_fall_of_ball.py index a4669c26d4306050f8fc3a97fe38e8ad27a42c9f..ff85488818352d7ce5d6169e8bb2a220f1b9f206 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 0f603d782381f77bb38bc5b4df6794d41ed40581..bb9c2f33c83a75107df3763b63d92ffc6b68b5e1 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 63533e380c85ef93936dc17b59d17864a76efe51..fba2d4b90337e574c5c58f9f8ec4479adca03780 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 # 最后删除自己