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

Python超人-宇宙模拟器

上级 30b8ddd2
......@@ -136,8 +136,8 @@ def calc_simulator(params, factor=1):
def before_evolve(dt, context: CalcContext):
sim.start_time = conv_to_astropy_time(params.start_time)
# td = TimeData(sim.total_times * dt, BodyTimer.MIN_UNIT_SECONDS)
time_data = TimeData(sim.total_times * dt, BodyTimer.MIN_UNIT_SECONDS)
# td = TimeData(sim.total_times * dt, BodyTimer.MIN_UNIT_SECONDS, dt)
time_data = TimeData(sim.total_times * dt, BodyTimer.MIN_UNIT_SECONDS, dt)
sim.total_times += 1
t = sim.start_time + time_data.total_days
......@@ -157,7 +157,7 @@ def calc_simulator(params, factor=1):
d_sun = calculate_distance(sim.halley_comet.position, sim.sun.position)
d_earth = calculate_distance(sim.halley_comet.position, sim.earth.position)
time_data = context.get_param("time_data")
# td = TimeData(sim.total_times * dt * UrsinaSimulator.INTERVAL_FATOR, BodyTimer.MIN_UNIT_SECONDS)
# td = TimeData(sim.total_times * dt * UrsinaSimulator.INTERVAL_FATOR, BodyTimer.MIN_UNIT_SECONDS, dt)
# sim.set_bodies_position(td)
......
......@@ -43,7 +43,7 @@ if __name__ == '__main__':
def on_ready():
# 运行前触发
create_sphere_sky(scale=2000)
sky = create_sphere_sky(scale=10000, rotation_y=150)
def on_timer_changed(time_data):
......@@ -52,6 +52,13 @@ if __name__ == '__main__':
# 地球转了一圈(360)就停止,370是留些余量
if abs(earth.planet.rotation_y) > 365:
exit(0)
# from ursina import camera, Vec3, time
# camera.parent.position += Vec3(0.0000001 * time_data.dt, 0, -0.0000003 * time_data.dt)
# Camera3d.look_to(earth.planet)
# camera.parent.look_at(earth.planet)
# # camera.rotation_x = 0
# # camera.rotation_y = 0
# camera.rotation_z = 0
UniverseSimScenes.set_window_size((1920, 1079), False)
......@@ -63,8 +70,8 @@ if __name__ == '__main__':
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies,
# SECONDS_PER_HOUR / 2,
SECONDS_PER_HOUR,
SECONDS_PER_HOUR / 5,
# SECONDS_PER_HOUR,
position=(1.45 * earth.radius, 0, -30000),
cosmic_bg="", # 无背景(黑色)
show_grid=False, # 不显示网格
......
此差异已折叠。
......@@ -367,7 +367,7 @@ def create_light_ship(size_scale, init_position, speed=LIGHT_SPEED):
init_velocity=[0, 0, speed]).set_light_disable(True)
def create_3d_card(left=-.885, top=0.495, width=0.02, height=0.02):
def create_3d_card(left=-.885, top=0.495, width=0.01, height=0.01):
# 创建一个 Panel 组件
from ursina import Text, Panel, color, camera, Vec3
from simulators.ursina.ursina_config import UrsinaConfig
......@@ -707,13 +707,19 @@ def speed_smooth_adjust_test():
plt.show()
def create_sphere_sky(texture="bg_pan.jpg", scale=8000):
def create_sphere_sky(texture="bg_pan.jpg", scale=8000, rotation_x=None, rotation_y=None, rotation_z=None):
from common.image_utils import find_texture
from simulators.ursina.entities.sphere_sky import SphereSky
sky_texture = find_texture(texture, None)
if sky_texture is not None:
sky = SphereSky(texture=sky_texture)
sky.scale = scale
if rotation_x is not None:
sky.rotation_x = rotation_x
if rotation_y is not None:
sky.rotation_y = rotation_y
if rotation_z is not None:
sky.rotation_z = rotation_z
return sky
else:
print(f'`textures`目录下没有找到图片`{texture}`,请访问如下链接下载,下载后,将图片放在`textures`目录下')
......
......@@ -17,7 +17,7 @@ from simulators.ursina.ursina_event import UrsinaEvent
class TimeData:
def __init__(self, seconds, min_unit):
def __init__(self, seconds, min_unit, dt):
from ursina import time
if not hasattr(TimeData, "app_start_time"):
setattr(TimeData, "app_start_time", time.time())
......@@ -32,6 +32,7 @@ class TimeData:
days, hours = divmod(hours, 24)
years = days // 365
days = days % 365
self.dt = dt
self.years = int(years)
self.days = int(days)
......@@ -196,7 +197,7 @@ class BodyTimer(Singleton):
# time_text = f'{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
# print(self.text)
UrsinaEvent.on_timer_changed(TimeData(seconds, self.min_unit))
UrsinaEvent.on_timer_changed(TimeData(seconds, self.min_unit, dt))
def ignore_gravity(self, body):
return True
......
......@@ -37,15 +37,21 @@ class Camera3d(Entity):
def switch_position(self):
if self.camera_pos == "right": # 摄像机右眼
self.x -= 2 * self.eye_distance
# self.x -= 2 * self.eye_distance
self.position += self.left * 2 * self.eye_distance
self.camera_pos = "left"
elif self.camera_pos == "left": # 摄像机左眼
self.x += 2 * self.eye_distance
# self.x += 2 * self.eye_distance
self.position += self.right * 2 * self.eye_distance
self.camera_pos = "right"
def update(self):
pass
@staticmethod
def look_to(target, axis='forward'):
Camera3d.o.camera3d.look_at(target, axis)
@staticmethod
def init(eye_distance=None, init_pos=None):
Camera3d.is_ready = True
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册