From 1147b3b1644f5fadb88f5177af9e9c63dc7a972d Mon Sep 17 00:00:00 2001 From: march3 Date: Wed, 25 Oct 2023 22:16:16 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?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 --- sim_scenes/solar_system/halley_comet_sim.py | 23 ++++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sim_scenes/solar_system/halley_comet_sim.py b/sim_scenes/solar_system/halley_comet_sim.py index ecfb961..857b686 100644 --- a/sim_scenes/solar_system/halley_comet_sim.py +++ b/sim_scenes/solar_system/halley_comet_sim.py @@ -13,8 +13,9 @@ from ursina import camera, application from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto from common.celestial_data_service import get_init_pos_vels, init_bodies_pos_vels from common.consts import SECONDS_PER_YEAR, AU +from common.func import calculate_distance from objs import HalleComet, Obj -from sim_scenes.func import camera_look_at, two_bodies_colliding +from sim_scenes.func import camera_look_at, two_bodies_colliding, create_text_panel from sim_scenes.func import ursina_run, create_sphere_sky from simulators.ursina.ursina_event import UrsinaEvent @@ -34,7 +35,7 @@ class HalleyCometSim: self.sun, # 太阳放大 80 倍 # Mercury(size_scale=4e3, distance_scale=1.3), # 水星放大 4000 倍,距离放大 1.3 倍 # Venus(size_scale=4e3, distance_scale=1.3), # 金星放大 4000 倍,距离放大 1.3 倍 - # Earth(size_scale=4e3, distance_scale=1.3, rotate_angle=0), # 地球放大 4000 倍,距离放大 1.3 倍 + Earth(size_scale=4e3, distance_scale=1.3, rotate_angle=0), # 地球放大 4000 倍,距离放大 1.3 倍 # Mars(size_scale=4e3, distance_scale=1.2), # 火星放大 4000 倍,距离放大 1.2 倍 Jupiter(size_scale=1.68e3, distance_scale=1), # 木星放大 680 倍,距离缩小到真实距离的 0.72 Saturn(size_scale=1.68e3, distance_scale=1), # 土星放大 680 倍,距离缩小到真实距离的 0.52 @@ -55,16 +56,17 @@ class HalleyCometSim: # 每76.1年环绕太阳一周的周期彗星 # 3.335, 0, 10.7 73 # 3.33, 0, 10.7 73 - - self.halley_comet = HalleComet(# size_scale=4e7, - size_scale=1e8, - init_velocity=[3.33, 0, 10.65], # [3.33, 0, 10.6] < ? <[3.34, 0, 10.7] - init_position=[0, 0.5 * AU, -10 * AU]) \ + # [3.33, 0, 10.65] 71 + # [3.33, 0, 10.655] 68 + # [3.33, 0, 10.66] 69 + self.halley_comet = HalleComet( # size_scale=4e7, + size_scale=1e8, + init_velocity=[3.33, 0, 10.699], # [3.33, 0, 10.6] < ? <[3.34, 0, 10.7] + init_position=[0, 0.5 * AU, -10 * AU]) \ .set_light_disable(True) self.bodies.append(self.halley_comet) - def build(self): self.build_solar_system() self.build_halley_comet() @@ -80,7 +82,7 @@ class HalleyCometSim: create_sphere_sky(scale=200000) application.time_scale = 5 - + self.text_panel = create_text_panel() def on_timer_changed(self, time_data): """ @@ -94,7 +96,8 @@ class HalleyCometSim: self.halley_comet.planet.rotation_y += 1 # 摄像机始终看向二向箔 # camera_look_at(self.halley_comet) - + d = calculate_distance(self.halley_comet.position, self.sun.position) + self.text_panel.text = "哈雷彗星距离太阳:%.3f AU" % (d / AU) if __name__ == '__main__': -- GitLab