提交 b1a0aa58 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 b4b2d814
...@@ -12,6 +12,7 @@ from bodies import * ...@@ -12,6 +12,7 @@ from bodies import *
from common.celestial_data_service import set_solar_system_celestial_position, conv_to_astropy_time, get_body_posvel, \ from common.celestial_data_service import set_solar_system_celestial_position, conv_to_astropy_time, get_body_posvel, \
get_reality_orbit_points get_reality_orbit_points
from common.consts import SECONDS_PER_DAY, AU from common.consts import SECONDS_PER_DAY, AU
from common.func import calculate_distance
from sim_scenes.featured.earth_seasons_base import EarthSeasonsSimBase from sim_scenes.featured.earth_seasons_base import EarthSeasonsSimBase
from sim_scenes.func import ursina_run, camera_look_at, create_sphere_sky from sim_scenes.func import ursina_run, camera_look_at, create_sphere_sky
from sim_scenes.science.earth_season_func import create_important_pos_earths, get_solar_terms_angles, create_earth from sim_scenes.science.earth_season_func import create_important_pos_earths, get_solar_terms_angles, create_earth
...@@ -30,13 +31,13 @@ import math ...@@ -30,13 +31,13 @@ import math
class CenterPointMovingSimLive(EarthSeasonsSimBase): class CenterPointMovingSimLive(EarthSeasonsSimBase):
def __init__(self): def __init__(self):
super(CenterPointMovingSimLive, self).__init__(sun_transparent=False, super(CenterPointMovingSimLive, self).__init__(sun_transparent=False,
exit_at_total_days=3700, exit_at_total_days=37000,
delay_run=False, delay_run=False,
look_at_earth=False, look_at_earth=False,
earth_cn_size_factor=1.01, earth_cn_size_factor=1.01,
earth_clouds_size_factor=1.015) earth_clouds_size_factor=1.015)
self.start_time = '2023-12-20 00:00:00' self.start_time = '2023-12-20 00:00:00'
self.sun.size_scale = 3e1 self.sun.size_scale = 4e1
self.earth.size_scale = 2e3 self.earth.size_scale = 2e3
self.earth_clouds.size_scale = self.earth.size_scale self.earth_clouds.size_scale = self.earth.size_scale
self.earth_cn.size_scale = self.earth.size_scale self.earth_cn.size_scale = self.earth.size_scale
...@@ -68,21 +69,6 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase): ...@@ -68,21 +69,6 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase):
self.season_earths = [self.earth_1, self.earth_2, self.earth_3, self.earth_4] self.season_earths = [self.earth_1, self.earth_2, self.earth_3, self.earth_4]
self.planets = [] self.planets = []
# self.jieqis = {
# "春分-2023": '2023-03-21 00:00:00',
# "夏至-2023": '2023-06-21 00:00:00',
# "秋分-2023": '2023-09-23 00:00:00',
# "冬至-2023": '2023-12-22 00:00:00',
# "春分-2024": '2024-03-20 00:00:00',
# "夏至-2024": '2024-06-21 00:00:00',
# "秋分-2024": '2024-09-22 00:00:00',
# "冬至-2024": '2024-12-21 00:00:00',
# "春分-2025": '2025-03-20 00:00:00',
# "夏至-2025": '2025-06-21 00:00:00',
# "秋分-2025": '2025-09-23 00:00:00',
# "冬至-2025": '2024-12-21 00:00:00',
# }
font = "fonts/DroidSansFallback.ttf" font = "fonts/DroidSansFallback.ttf"
from common.func import find_file from common.func import find_file
self.font = find_file(f"{font}", UrsinaConfig.CN_FONT) self.font = find_file(f"{font}", UrsinaConfig.CN_FONT)
...@@ -106,7 +92,7 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase): ...@@ -106,7 +92,7 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase):
segments=100) segments=100)
# print(points) # print(points)
orbit_line = create_orbit_by_points(center_body.position, points, line_color=body.trail_color, orbit_line = create_orbit_by_points(center_body.position, points, line_color=body.trail_color,
alpha=alpha,thickness=2) alpha=alpha, thickness=2)
return orbit_line return orbit_line
def create_orbit_lines(self): def create_orbit_lines(self):
...@@ -128,16 +114,39 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase): ...@@ -128,16 +114,39 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase):
self.orbit_lines.append(orbit_line) self.orbit_lines.append(orbit_line)
return self.orbit_lines return self.orbit_lines
def count_days(self, key, time_data, days):
key = "k_" + str(key)
days_counter_key = f"{key}_days_counter"
days_counter_init_val_key = f"{key}_days_counter_init_val"
if not hasattr(self, days_counter_key):
setattr(self, days_counter_key, 0)
setattr(self, days_counter_init_val_key, time_data.total_days)
else:
d = time_data.total_days - getattr(self, days_counter_init_val_key)
setattr(self, days_counter_key, d)
rd = getattr(self, days_counter_key)
if rd >= days:
delattr(self, days_counter_key)
delattr(self, days_counter_init_val_key)
return True
return False
# if days is None:
# return self.days_counter
# else:
# self.days_counter = days
# self.days_counter_init_val = time_data.total_days
def get_center_pos(self, dt, time_data): def get_center_pos(self, dt, time_data):
ec = UrsinaSimulator.EditorCamera ec = UrsinaSimulator.EditorCamera
d_sun = distance(ec.world_position, self.sun.planet.world_position) d_sun = self.get_distance_sun()
if not hasattr(self, "moving_factor"): if not hasattr(self, "moving_factor"):
self.moving_factor = 1e-6 self.moving_factor = 1e-6
self.phase_num = 1 self.phase_num = 1
# elif time_data.total_days > 1500 and self.moving_factor < 1: # elif time_data.total_days > 1500 and self.moving_factor < 1:
elif d_sun > 4500 and self.moving_factor < 1: elif (d_sun < 7 or self.phase_num == 2) and self.moving_factor < 1:
self.moving_factor += 0.01 self.moving_factor += 0.01 * UrsinaConfig.run_speed_factor
if self.phase_num == 1: if self.phase_num == 1:
for b in self.bodies: for b in self.bodies:
from simulators.ursina.entities.entity_utils import clear_trails from simulators.ursina.entities.entity_utils import clear_trails
...@@ -153,7 +162,8 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase): ...@@ -153,7 +162,8 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase):
from simulators.ursina.entities.entity_utils import clear_trails from simulators.ursina.entities.entity_utils import clear_trails
clear_trails(b.planet.main_entity) clear_trails(b.planet.main_entity)
UrsinaConfig.trail_type = "curve_line" UrsinaConfig.trail_type = "curve_line"
UrsinaConfig.trail_length = 91 UrsinaConfig.trail_length = 500
self.phase_num = 3 self.phase_num = 3
e_posvel = get_body_posvel(self.earth, dt) e_posvel = get_body_posvel(self.earth, dt)
...@@ -171,7 +181,7 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase): ...@@ -171,7 +181,7 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase):
UrsinaConfig.trail_type = "line" UrsinaConfig.trail_type = "line"
# UrsinaConfig.trail_length = 91 # UrsinaConfig.trail_length = 91
UrsinaConfig.trail_type = "curve_line" UrsinaConfig.trail_type = "curve_line"
UrsinaConfig.trail_length = 200 UrsinaConfig.trail_length = 250
# UrsinaConfig.trail_length = 1000 # UrsinaConfig.trail_length = 1000
UrsinaConfig.trail_thickness_factor = 2 UrsinaConfig.trail_thickness_factor = 2
UrsinaConfig.trail_factor = 2 UrsinaConfig.trail_factor = 2
...@@ -215,25 +225,43 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase): ...@@ -215,25 +225,43 @@ class CenterPointMovingSimLive(EarthSeasonsSimBase):
self.set_bodies_position(time_data) self.set_bodies_position(time_data)
self.show_clock(dt) self.show_clock(dt)
print("total_days:", time_data.total_days)
ec = UrsinaSimulator.EditorCamera ec = UrsinaSimulator.EditorCamera
d_sun = distance(ec.world_position, self.sun.planet.world_position)
print("Sun distance:", d_sun)
if self.phase_num == 1: if self.phase_num == 1:
ec.world_position += ec.up * 2 * UrsinaConfig.run_speed_factor ec.world_position += ec.up * 2 * UrsinaConfig.run_speed_factor # 前进
ec.world_position += ec.back * 1 * UrsinaConfig.run_speed_factor ec.world_position += ec.back * 1 * UrsinaConfig.run_speed_factor # 下
elif self.phase_num == 2: elif self.phase_num == 2:
self.hide_orbit_lines() self.hide_orbit_lines()
elif self.phase_num == 3: elif self.phase_num == 3:
pass if self.count_days(self.phase_num, time_data, 370):
# ec.world_position -= ec.up * 2 * UrsinaConfig.run_speed_factor self.phase_num = 4
# ec.world_position -= ec.back * 1 * UrsinaConfig.run_speed_factor elif self.phase_num == 4:
ec.world_position -= ec.up * 2 * UrsinaConfig.run_speed_factor # 后退
ec.world_position -= ec.back * 1.4 * UrsinaConfig.run_speed_factor # 下(快一点)
ec.world_position += ec.right * 0.8 * UrsinaConfig.run_speed_factor # 左
d_sun = self.get_distance_sun()
print("d_sun:", d_sun)
if d_sun > 45:
self.phase_num = 5
elif self.phase_num == 5:
ec.world_position -= ec.back * 1.4 * UrsinaConfig.run_speed_factor # 下
ec.world_position += ec.right * 0.7 * UrsinaConfig.run_speed_factor # 左
pos = camera.world_position
if pos[2] > 2000:
self.phase_num = 6
print("pos:", pos)
# if d_sun > 4500: # if d_sun > 4500:
# ec.target_z -= 0.01 # ec.target_z -= 0.01
# self.camera_around() # self.camera_around()
def get_distance_sun(self):
d_sun = distance(camera.world_position, self.sun.planet.world_position)
return round(d_sun / UrsinaConfig.SCALE_FACTOR / AU, 4)
def camera_around(self): def camera_around(self):
ec = UrsinaSimulator.EditorCamera ec = UrsinaSimulator.EditorCamera
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册