Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
10a5eca8
宇宙模拟器
项目概览
Python_超人
/
宇宙模拟器
通知
19
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
宇宙模拟器
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
10a5eca8
编写于
11月 11, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
3c8602f2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
332 addition
and
92 deletion
+332
-92
common/celestial_data_service.py
common/celestial_data_service.py
+19
-10
objs/obj.py
objs/obj.py
+2
-0
sim_lab/halley_comet_sim.py
sim_lab/halley_comet_sim.py
+70
-1
sim_scenes/func.py
sim_scenes/func.py
+146
-1
sim_scenes/solar_system/halley_comet_lib.py
sim_scenes/solar_system/halley_comet_lib.py
+5
-4
sim_scenes/solar_system/halley_comet_sim.py
sim_scenes/solar_system/halley_comet_sim.py
+63
-67
simulators/ursina/entities/body_trail.py
simulators/ursina/entities/body_trail.py
+2
-2
simulators/ursina/entities/planet.py
simulators/ursina/entities/planet.py
+1
-1
simulators/ursina/ursina_mesh.py
simulators/ursina/ursina_mesh.py
+24
-6
未找到文件。
common/celestial_data_service.py
浏览文件 @
10a5eca8
...
@@ -109,14 +109,19 @@ def get_celestial_body_data(body_name):
...
@@ -109,14 +109,19 @@ def get_celestial_body_data(body_name):
return
position
,
velocity
return
position
,
velocity
def
set_solar_system_celestial_position
(
bodies
,
dt
,
recalc_moon_pos
):
def
set_solar_system_celestial_position
(
bodies
,
dt
,
recalc_moon_pos
,
set_velocity
=
True
,
set_acceleration
=
True
):
"""
"""
根据日期时间 dt 设置太阳系中天体的真实位置
根据日期时间 dt 设置太阳系中天体的真实位置
@param bodies: 太阳系中天体
@param bodies: 太阳系中天体
@param dt: 时间
@param dt: 时间
@param recalc_moon_pos: 是否对月球的位置进行重新计算。
@param recalc_moon_pos: 是否对月球的位置进行重新计算。
为了更好的展示效果,需要对月球的位置重新计算(使得地月距离放大,月球相对地球方向不变),
为了更好的展示效果,需要对月球的位置重新计算(使得地月距离放大,月球相对地球方向不变),
重新计算位置后,地球和月球可以放大1000倍以上
重新计算位置后,地球和月球可以放大1000倍以上
@param set_velocity: 是否设置速度
@param set_acceleration: 是否设置加速度
@return:
@return:
"""
"""
earth_pos
=
None
earth_pos
=
None
...
@@ -163,7 +168,9 @@ def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos):
...
@@ -163,7 +168,9 @@ def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos):
# 实时调整天体的位置和速度
# 实时调整天体的位置和速度
body
.
position
=
np
.
array
(
position
)
body
.
position
=
np
.
array
(
position
)
body
.
velocity
=
np
.
array
(
velocity
)
if
set_velocity
:
body
.
velocity
=
np
.
array
(
velocity
)
if
isinstance
(
body
,
Asteroids
):
if
isinstance
(
body
,
Asteroids
):
pass
pass
...
@@ -171,12 +178,13 @@ def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos):
...
@@ -171,12 +178,13 @@ def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos):
# 记录太阳的位置
# 记录太阳的位置
sun_pos
=
posvel
[
0
]
sun_pos
=
posvel
[
0
]
elif
isinstance
(
body
,
Moon
):
elif
isinstance
(
body
,
Moon
):
# 月球受到2个影响比较大的天体引力(地球和太阳),计算引力引起的加速度和
if
set_acceleration
:
acc_earth
=
calc_solar_acceleration
(
moon_real_pos
,
earth
)
# 月球受到2个影响比较大的天体引力(地球和太阳),计算引力引起的加速度和
acc_sun
=
calc_solar_acceleration
(
moon_real_pos
,
sun
)
acc_earth
=
calc_solar_acceleration
(
moon_real_pos
,
earth
)
body
.
acceleration
=
[
acc_earth
[
0
]
+
acc_sun
[
0
],
acc_sun
=
calc_solar_acceleration
(
moon_real_pos
,
sun
)
acc_earth
[
1
]
+
acc_sun
[
1
],
body
.
acceleration
=
[
acc_earth
[
0
]
+
acc_sun
[
0
],
acc_earth
[
2
]
+
acc_sun
[
2
]]
acc_earth
[
1
]
+
acc_sun
[
1
],
acc_earth
[
2
]
+
acc_sun
[
2
]]
# elif isinstance(body, Earth):
# elif isinstance(body, Earth):
# # 月球受到2个影响比较大的天体引力(地球和太阳),计算引力引起的加速度和
# # 月球受到2个影响比较大的天体引力(地球和太阳),计算引力引起的加速度和
# acc_earth = calc_solar_acceleration(earth, moon)
# acc_earth = calc_solar_acceleration(earth, moon)
...
@@ -185,8 +193,9 @@ def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos):
...
@@ -185,8 +193,9 @@ def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos):
# acc_earth[1] + acc_sun[1],
# acc_earth[1] + acc_sun[1],
# acc_earth[2] + acc_sun[2]]
# acc_earth[2] + acc_sun[2]]
else
:
else
:
# 其他天体受到太阳引力
if
set_acceleration
:
body
.
acceleration
=
calc_solar_acceleration
(
body
,
sun
)
# 其他天体受到太阳引力
body
.
acceleration
=
calc_solar_acceleration
(
body
,
sun
)
if
isinstance
(
body
,
Earth
):
if
isinstance
(
body
,
Earth
):
# 记录地球的位置
# 记录地球的位置
...
...
objs/obj.py
浏览文件 @
10a5eca8
...
@@ -60,6 +60,8 @@ class Obj(metaclass=ABCMeta):
...
@@ -60,6 +60,8 @@ class Obj(metaclass=ABCMeta):
if
name
is
None
:
if
name
is
None
:
name
=
getattr
(
self
.
__class__
,
'__name__'
)
name
=
getattr
(
self
.
__class__
,
'__name__'
)
self
.
text_color
=
None
self
.
name
=
name
self
.
name
=
name
self
.
__mass
=
mass
self
.
__mass
=
mass
...
...
sim_lab/halley_comet_sim.py
浏览文件 @
10a5eca8
...
@@ -144,7 +144,7 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -144,7 +144,7 @@ class HalleyCometSim(HalleyCometSimBase):
_pos
=
pos
_pos
=
pos
if
_pos
is
None
:
if
_pos
is
None
:
_pos
=
(
0
,
0
,
0
)
_pos
=
(
0
,
0
,
0
)
label
=
create_label
(
trail
,
label
=
year
,
pos
=
_pos
,
color
=
(
255
,
255
,
255
),
scale
=
scale
,
alpha
=
1.0
,
label
=
create_label
(
trail
,
label
=
year
,
pos
=
_pos
,
label_
color
=
(
255
,
255
,
255
),
scale
=
scale
,
alpha
=
1.0
,
background
=
background
)
background
=
background
)
label
.
set_light_off
()
label
.
set_light_off
()
...
@@ -235,6 +235,75 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -235,6 +235,75 @@ class HalleyCometSim(HalleyCometSimBase):
# # camera.position += Vec3(0, 0, -1)
# # camera.position += Vec3(0, 0, -1)
# camera.position += camera.forward * -5
# camera.position += camera.forward * -5
def
camera_move2
(
self
,
dt
):
camera_move_infos
=
[
# 开始年份, 向前移动因子, (上移动因子, 下移动因子, 左移动因子, 右移动因子)
(
1983
,
self
.
s_f
(
1.2
),
(
0
,
self
.
s_f
(
0.5
),
0
,
0
)),
(
1986
,
self
.
s_f
(
-
12
),
(
0
,
self
.
s_f
(),
0
,
0
)),
(
1987
,
self
.
s_f
(
-
24
),
(
0
,
self
.
s_f
(
2
),
0
,
0
)),
(
1988
,
0
,
(
0
,
self
.
s_f
(
2
),
0
,
self
.
s_f
(
2
))),
(
2049
,
self
.
s_f
(
12
),
None
),
(
2061
,
0
,
None
),
(
2062
,
self
.
s_f
(
-
60
),
None
),
(
2066
,
0
,
None
),
(
2100
,
0
,
None
),
(
2124
,
0
,
None
)
]
for
idx
,
(
year
,
factor
,
udlr
)
in
enumerate
(
camera_move_infos
[:
-
1
]):
next_year
=
camera_move_infos
[
idx
+
1
][
0
]
if
next_year
>
dt
.
year
>=
year
:
camera
.
forward_factor
=
factor
if
udlr
is
not
None
:
u
,
d
,
l
,
r
=
udlr
camera
.
up_factor
=
u
camera
.
down_factor
=
d
camera
.
left_factor
=
l
camera
.
right_factor
=
r
def
camera_move___
(
self
,
dt
):
camera_move_infos
=
[
# 年份, x:左+右-, y:升+降-, z:前+(接近太阳)后-(远离太阳)
(
1982
,
2
,
2
,
0
),
(
1986
,
2
,
2
,
2
),
(
1996
,
2
,
0
,
2
),
(
2004
,
0
,
0
,
0
),
(
2124
,
0
,
0
,
0
),
]
for
idx
,
(
year
,
x
,
y
,
z
)
in
enumerate
(
camera_move_infos
[:
-
1
]):
next_year
=
camera_move_infos
[
idx
+
1
][
0
]
if
next_year
>
dt
.
year
>=
year
:
p
=
camera
.
position
camera
.
position
=
[
p
[
0
]
+
self
.
s_f
(
x
),
p
[
1
]
+
self
.
s_f
(
y
),
p
[
2
]
+
self
.
s_f
(
z
)]
def
camera_move_
(
self
,
dt
):
camera_move_infos
=
[
# 开始年份, 向前移动因子, (上移动因子, 下移动因子, 左移动因子, 右移动因子)
(
1984
,
0
,
(
0
,
0
,
0
,
self
.
s_f
(
2
))),
(
1986
,
self
.
s_f
(
-
2
),
(
self
.
s_f
(
2
),
0
,
0
,
self
.
s_f
(
2
))),
# (2005, 0, None),
(
2049
,
0
,
None
),
(
2061
,
0
,
None
),
(
2062
,
0
,
None
),
(
2066
,
0
,
None
),
(
2100
,
0
,
None
),
(
2124
,
0
,
None
)
]
for
idx
,
(
year
,
factor
,
udlr
)
in
enumerate
(
camera_move_infos
[:
-
1
]):
next_year
=
camera_move_infos
[
idx
+
1
][
0
]
if
next_year
>
dt
.
year
>=
year
:
camera
.
forward_factor
=
factor
if
udlr
is
not
None
:
u
,
d
,
l
,
r
=
udlr
camera
.
up_factor
=
u
camera
.
down_factor
=
d
camera
.
left_factor
=
l
camera
.
right_factor
=
r
# return
# camera.move_to_target = self.halley_comet.planet
# camera.move_to_target_t = 0.001
def
on_timer_changed
(
self
,
time_data
):
def
on_timer_changed
(
self
,
time_data
):
"""
"""
...
...
sim_scenes/func.py
浏览文件 @
10a5eca8
...
@@ -103,16 +103,25 @@ def create_main_entity(target, rotation_x=None, rotation_y=None, rotation_z=None
...
@@ -103,16 +103,25 @@ def create_main_entity(target, rotation_x=None, rotation_y=None, rotation_z=None
planet
.
main_entity
=
main_entity
planet
.
main_entity
=
main_entity
def
camera_look_at
(
target
,
rotation_x
=
None
,
rotation_y
=
None
,
rotation_z
=
None
):
def
camera_look_at
(
target
,
rotation_x
=
None
,
rotation_y
=
None
,
rotation_z
=
None
,
keep_pose
=
False
):
"""
"""
让摄像机看向指定天体
让摄像机看向指定天体
@param target: 天体
@param target: 天体
@param rotation_x: x轴旋转角度(None表示不旋转)
@param rotation_x: x轴旋转角度(None表示不旋转)
@param rotation_y: y轴旋转角度(None表示不旋转)
@param rotation_y: y轴旋转角度(None表示不旋转)
@param rotation_z: z轴旋转角度(None表示不旋转)
@param rotation_z: z轴旋转角度(None表示不旋转)
@param keep_pose: 保持摄像机的姿态(未用保留)
@return:
@return:
"""
"""
from
ursina
import
camera
from
ursina
import
camera
# if keep_pose:
# if hasattr(camera, "keep_pose"):
# rotation_x, rotation_y, rotation_z = camera.keep_pose
# else:
# if hasattr(camera, "keep_pose"):
# delattr(camera, "keep_pose")
if
hasattr
(
target
,
"planet"
):
if
hasattr
(
target
,
"planet"
):
camera
.
look_at
(
target
.
planet
.
main_entity
)
camera
.
look_at
(
target
.
planet
.
main_entity
)
else
:
else
:
...
@@ -125,6 +134,10 @@ def camera_look_at(target, rotation_x=None, rotation_y=None, rotation_z=None):
...
@@ -125,6 +134,10 @@ def camera_look_at(target, rotation_x=None, rotation_y=None, rotation_z=None):
if
rotation_z
is
not
None
:
if
rotation_z
is
not
None
:
camera
.
rotation_z
=
rotation_z
camera
.
rotation_z
=
rotation_z
# if keep_pose:
# if not hasattr(camera, "keep_pose"):
# camera.keep_pose = [camera.rotation_x, camera.rotation_y, camera.rotation_z]
def
ursina_run
(
bodies
,
def
ursina_run
(
bodies
,
dt
=
SECONDS_PER_HALF_DAY
,
dt
=
SECONDS_PER_HALF_DAY
,
...
@@ -695,6 +708,138 @@ def create_sphere_sky(texture="bg_pan.jpg", scale=8000):
...
@@ -695,6 +708,138 @@ def create_sphere_sky(texture="bg_pan.jpg", scale=8000):
print
(
"高清下载地址:https://www.aliyundrive.com/s/zC4VbN9Mas7/folder/64f52f25ef4f4b0b34c6477e9ca73ddd35a27800"
)
print
(
"高清下载地址:https://www.aliyundrive.com/s/zC4VbN9Mas7/folder/64f52f25ef4f4b0b34c6477e9ca73ddd35a27800"
)
def
camera_move_to_target_update
(
before_update
=
None
,
after_update
=
None
):
from
ursina
import
camera
,
lerp
camera
.
move_to_target
=
None
camera
.
move_to_target_t
=
0.01
def
_camera_update
():
if
before_update
is
not
None
:
before_update
()
if
camera
.
move_to_target
is
not
None
:
target
=
camera
.
move_to_target
camera
.
position
=
\
lerp
(
camera
.
position
,
target
.
position
,
camera
.
move_to_target_t
)
if
after_update
is
not
None
:
after_update
()
camera
.
update
=
_camera_update
def
camera_move_update
(
before_update
=
None
,
after_update
=
None
):
"""
- camera.forward:将摄像机向前移动。
- camera.back:将摄像机向后移动。
- camera.right:将摄像机向右移动。
- camera.position:获取或设置摄像机的位置。
- camera.left:将摄像机向左移动。
- camera.up:将摄像机向上移动。
- camera.down:将摄像机向下移动。
"""
from
ursina
import
camera
# 用于设置相机的投影模式为正交投影。在计算机图形学中,正交投影是一种将三维空间中的物体投影到二维平面上的方法,
# 通常用于2D游戏和图形渲染。
# camera.orthographic = True
camera
.
forward_factor
=
0
camera
.
back_factor
=
0
camera
.
up_factor
=
0
camera
.
down_factor
=
0
camera
.
left_factor
=
0
camera
.
right_factor
=
0
def
_camera_update
():
if
before_update
is
not
None
:
before_update
()
if
camera
.
forward_factor
!=
0
:
camera
.
position
+=
camera
.
forward
*
camera
.
forward_factor
if
camera
.
back_factor
!=
0
:
camera
.
position
+=
camera
.
back
*
camera
.
back_factor
if
camera
.
up_factor
!=
0
:
camera
.
position
+=
camera
.
up
*
camera
.
up_factor
if
camera
.
down_factor
!=
0
:
camera
.
position
+=
camera
.
down
*
camera
.
down_factor
if
camera
.
left_factor
!=
0
:
camera
.
position
+=
camera
.
left
*
camera
.
left_factor
if
camera
.
right_factor
!=
0
:
camera
.
position
+=
camera
.
right
*
camera
.
right_factor
if
after_update
is
not
None
:
after_update
()
camera
.
update
=
_camera_update
def
get_run_speed_factor
(
run_speed_factor
=
1
/
8
):
"""
获取运行速度因子
1: 速度相当于 1年/秒
1/8: 录视频用
1/30: 摄像机勉强不抖动
@return:
"""
from
simulators.ursina.ui.control_ui
import
ControlUI
if
hasattr
(
ControlUI
,
"current_ui"
):
control_speed_factor
=
ControlUI
.
current_ui
.
slider_run_speed_factor
.
value
else
:
control_speed_factor
=
1
return
run_speed_factor
*
control_speed_factor
def
camera_move_control
(
camera_move_infos
,
cond_cb
,
value_conv
=
None
):
"""
@param camera_move_infos:
条件:比如年份、时间、位置等信息
x: y: z: 按坐标移动, 需要打开 WorldGrid().draw_axises(10)
按摄像机视角移动 f:前 b:后 l:左 r:右 u:上 d:下
(1996, {"x": 2, "y": 0, "z": 0, "f": 3}),
(2004, {"b": 3}), # 摄像机向后
(2006, {}), # 全部置零
(2048, {"f": 3}), # 摄像机向前
@param cond_cb: 条件回调,参数为:
cond:当前条件数据, next_cond:下一个条件数据, idx:当前索引, info:当前信息, next_info:下一个信息
@param value_conv:
@return:
"""
from
ursina
import
camera
,
Vec3
import
inspect
def
conv_val
(
val
,
p_name
):
if
callable
(
value_conv
):
num_params
=
len
(
inspect
.
signature
(
value_conv
).
parameters
)
if
num_params
==
1
:
return
value_conv
(
val
)
return
value_conv
(
val
,
p_name
)
return
val
for
idx
,
(
cond
,
info
)
in
enumerate
(
camera_move_infos
[:
-
1
]):
next_cond
=
camera_move_infos
[
idx
+
1
][
0
]
next_info
=
camera_move_infos
[
idx
+
1
][
1
]
cond_cb_params
=
{
"cond"
:
cond
,
"next_cond"
:
next_cond
,
"idx"
:
idx
,
"info"
:
info
,
"next_info"
:
next_info
}
if
cond_cb
(
cond_cb_params
):
p
=
camera
.
position
x
,
y
,
z
=
info
.
get
(
"x"
,
0
),
info
.
get
(
"y"
,
0
),
info
.
get
(
"z"
,
0
)
mis
=
info
.
get
(
"f"
,
0
),
info
.
get
(
"b"
,
0
),
info
.
get
(
"l"
,
0
),
info
.
get
(
"r"
,
0
),
\
info
.
get
(
"u"
,
0
),
info
.
get
(
"d"
,
0
)
dns
=
"fblrud"
mas
=
camera
.
forward
,
camera
.
back
,
camera
.
left
,
camera
.
right
,
camera
.
up
,
camera
.
down
if
x
!=
0
or
y
!=
0
or
z
!=
0
:
p
+=
Vec3
(
conv_val
(
x
,
"x"
),
conv_val
(
y
,
"y"
),
conv_val
(
z
,
"z"
))
for
i
,
mi
in
enumerate
(
mis
):
if
mi
!=
0
:
p
+=
mas
[
i
]
*
conv_val
(
mi
,
dns
[
i
])
camera
.
position
=
p
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
# from bodies import Sun, Earth
# from bodies import Sun, Earth
#
#
...
...
sim_scenes/solar_system/halley_comet_lib.py
浏览文件 @
10a5eca8
...
@@ -94,16 +94,17 @@ class HalleyCometSimBase:
...
@@ -94,16 +94,17 @@ class HalleyCometSimBase:
# self.pluto, # 冥王星
# self.pluto, # 冥王星
]
]
trail_color_brightest
(
self
.
bodies
)
trail_color_brightest
(
self
.
bodies
)
if
ignore_gravity
:
for
body
in
self
.
bodies
[
1
:]:
body
.
init_velocity
=
[
0
,
0
,
0
]
body
.
set_ignore_gravity
(
True
)
if
start_time
is
not
None
:
if
start_time
is
not
None
:
init_bodies_reality_pos_vels
(
self
.
bodies
,
start_time
)
init_bodies_reality_pos_vels
(
self
.
bodies
,
start_time
)
else
:
else
:
init_bodies_pos_vels
(
self
.
bodies
)
init_bodies_pos_vels
(
self
.
bodies
)
if
ignore_gravity
:
for
body
in
self
.
bodies
[
1
:]:
body
.
init_velocity
=
[
0
,
0
,
0
]
body
.
set_ignore_gravity
(
True
)
def
show_grid_axises
(
self
):
def
show_grid_axises
(
self
):
"""
"""
显示网格以及坐标线
显示网格以及坐标线
...
...
sim_scenes/solar_system/halley_comet_sim.py
浏览文件 @
10a5eca8
...
@@ -13,7 +13,8 @@ from common.celestial_data_service import init_bodies_reality_pos_vels, conv_to_
...
@@ -13,7 +13,8 @@ from common.celestial_data_service import init_bodies_reality_pos_vels, conv_to_
set_solar_system_celestial_position
set_solar_system_celestial_position
from
common.consts
import
SECONDS_PER_YEAR
,
AU
from
common.consts
import
SECONDS_PER_YEAR
,
AU
from
common.func
import
calculate_distance
from
common.func
import
calculate_distance
from
sim_scenes.func
import
create_text_panel
,
camera_look_at
from
sim_scenes.func
import
create_text_panel
,
camera_look_at
,
get_run_speed_factor
,
\
camera_move_update
,
camera_move_to_target_update
,
camera_move_control
from
sim_scenes.func
import
ursina_run
,
create_sphere_sky
from
sim_scenes.func
import
ursina_run
,
create_sphere_sky
from
sim_scenes.solar_system.halley_comet_lib
import
HalleyCometSimBase
,
HalleyCometParams
,
\
from
sim_scenes.solar_system.halley_comet_lib
import
HalleyCometSimBase
,
HalleyCometParams
,
\
create_halley_comet
,
create_orbit_line
create_halley_comet
,
create_orbit_line
...
@@ -24,8 +25,6 @@ from simulators.ursina.ursina_config import UrsinaConfig
...
@@ -24,8 +25,6 @@ from simulators.ursina.ursina_config import UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_mesh
import
create_label
from
simulators.ursina.ursina_mesh
import
create_label
RUN_SPEED
=
1
/
8
class
HalleyCometSim
(
HalleyCometSimBase
):
class
HalleyCometSim
(
HalleyCometSimBase
):
"""
"""
...
@@ -76,15 +75,9 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -76,15 +75,9 @@ class HalleyCometSim(HalleyCometSimBase):
camera
.
clip_plane_far
=
1000000
camera
.
clip_plane_far
=
1000000
application
.
time_scale
=
5
application
.
time_scale
=
5
# 摄像机移动 update
camera
.
forward_factor
=
0
camera_move_update
()
# camera_move_to_target_update()
def
camera_update
():
camera_look_at
(
self
.
halley_comet
,
rotation_z
=
0
)
if
camera
.
forward_factor
!=
0
:
camera
.
position
+=
camera
.
forward
*
camera
.
forward_factor
camera
.
update
=
camera_update
def
on_ready
(
self
):
def
on_ready
(
self
):
"""
"""
...
@@ -122,7 +115,12 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -122,7 +115,12 @@ class HalleyCometSim(HalleyCometSimBase):
t
=
self
.
start_time
+
time_data
.
total_days
t
=
self
.
start_time
+
time_data
.
total_days
set_solar_system_celestial_position
(
self
.
bodies
,
t
,
False
)
set_solar_system_celestial_position
(
self
.
bodies
,
t
,
False
)
def
create_year_label
(
self
,
trail
,
year
,
halley_comet_pos
=
None
,
pos
=
None
,
scale
=
40
,
background
=
False
):
def
create_year_label
(
self
,
trail
,
year
,
halley_comet_pos
=
None
,
pos
=
None
,
label_color
=
None
,
scale
=
40
,
background
=
False
):
"""
"""
在界面上创建年份的标签
在界面上创建年份的标签
@param trail:
@param trail:
...
@@ -140,8 +138,14 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -140,8 +138,14 @@ class HalleyCometSim(HalleyCometSimBase):
_pos
=
pos
_pos
=
pos
if
_pos
is
None
:
if
_pos
is
None
:
_pos
=
(
0
,
0
,
0
)
_pos
=
(
0
,
0
,
0
)
label
=
create_label
(
trail
,
label
=
year
,
pos
=
_pos
,
color
=
(
255
,
255
,
255
),
scale
=
scale
,
alpha
=
1.0
,
background
=
background
)
if
label_color
is
None
:
label_color
=
(
255
,
255
,
255
,
255
)
label
=
create_label
(
trail
,
label
=
year
,
pos
=
_pos
,
label_color
=
label_color
,
scale
=
scale
,
alpha
=
1.0
,
background
=
background
)
label
.
set_light_off
()
label
.
set_light_off
()
def
set_comet_trail_alpha
(
self
,
distance_sun
):
def
set_comet_trail_alpha
(
self
,
distance_sun
):
...
@@ -183,31 +187,37 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -183,31 +187,37 @@ class HalleyCometSim(HalleyCometSimBase):
setattr
(
self
,
prop_name
,
milestone
)
setattr
(
self
,
prop_name
,
milestone
)
if
pos
is
None
:
if
pos
is
None
:
pos
=
(
0
,
2
,
0
)
pos
=
(
0
,
2
,
0
)
self
.
create_year_label
(
last_trail
,
milestone
,
pos
=
pos
,
scale
=
60
,
background
=
True
)
self
.
create_year_label
(
last_trail
,
milestone
,
label_color
=
(
0
,
255
,
0
),
pos
=
pos
,
scale
=
60
,
background
=
True
)
# application.paused = True
# application.paused = True
# UrsinaEvent.on_pause()
# UrsinaEvent.on_pause()
ControlUI
.
current_ui
.
on_off_switch
.
on_value_changed
()
def
look_at_halley_comet
(
self
,
dt
):
forward_infos
=
[
def
s_f
(
self
,
value
=
1
):
(
1983
,
0.1
*
RUN_SPEED
*
12
),
if
value
==
0
:
(
1986
,
-
8
*
RUN_SPEED
*
12
),
return
0
(
1987
,
-
2
*
RUN_SPEED
*
12
),
return
get_run_speed_factor
()
*
value
(
1988
,
0
),
(
2049
,
1
*
RUN_SPEED
*
12
),
def
camera_move
(
self
,
dt
):
(
2061
,
0
),
camera_move_infos
=
[
(
2062
,
-
5
*
RUN_SPEED
*
12
),
# 条件:年份
(
2066
,
0
),
# 移动的信息:
(
2100
,
0
),
# 按坐标系方向移动 x:右+左-, y:升+降-, z:前+(接近太阳)后-(远离太阳)
(
2124
,
0
)
# 以摄像机视角移动 f:前 b:后 l:左 r:右 u:上 d:下
(
1982
,
{
"x"
:
2
,
"y"
:
2
,
"z"
:
0
}),
(
1986
,
{
"x"
:
2
,
"y"
:
2
,
"z"
:
2
}),
(
1996
,
{
"x"
:
2
,
"y"
:
0
,
"z"
:
0
,
"f"
:
3
}),
(
2004
,
{
"x"
:
0
,
"y"
:
0
,
"z"
:
0
,
"f"
:
3
}),
(
2006
,
{}),
(
2048
,
{
"f"
:
3
}),
(
2061
,
{}),
(
2124
,
{}),
]
]
for
idx
,
(
year
,
factor
)
in
enumerate
(
forward_infos
[:
-
1
]):
camera_move_control
(
camera_move_infos
,
next_year
=
forward_infos
[
idx
+
1
][
0
]
cond_cb
=
lambda
ps
:
ps
[
"next_cond"
]
>
dt
.
year
>=
ps
[
"cond"
],
if
next_year
>
dt
.
year
>=
year
:
value_conv
=
self
.
s_f
)
if
factor
<
0
and
camera
.
position
[
0
]
<
-
3000
:
# 最远
continue
camera
.
forward_factor
=
factor
def
on_timer_changed
(
self
,
time_data
):
def
on_timer_changed
(
self
,
time_data
):
"""
"""
...
@@ -218,9 +228,9 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -218,9 +228,9 @@ class HalleyCometSim(HalleyCometSimBase):
dt
=
time_data
.
get_datetime
(
str
(
self
.
start_time
))
dt
=
time_data
.
get_datetime
(
str
(
self
.
start_time
))
year
=
dt
.
strftime
(
"%Y"
)
year
=
dt
.
strftime
(
"%Y"
)
# camera_look_at(self.halley_comet
)
camera_look_at
(
self
.
halley_comet
,
rotation_z
=
0
)
self
.
look_at_halley_comet
(
dt
)
self
.
camera_move
(
dt
)
if
hasattr
(
self
,
"halley_comet"
):
if
hasattr
(
self
,
"halley_comet"
):
if
self
.
halley_comet
.
planet
.
enabled
:
if
self
.
halley_comet
.
planet
.
enabled
:
...
@@ -229,13 +239,11 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -229,13 +239,11 @@ class HalleyCometSim(HalleyCometSimBase):
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
if
len
(
trail_keys
)
>
0
:
if
len
(
trail_keys
)
>
0
:
last_trail
=
list
(
trail_keys
)[
-
1
]
# self.halley_comet.planet.trails[list(trail_keys)[-1]]
last_trail
=
list
(
trail_keys
)[
-
1
]
if
hasattr
(
last_trail
,
"entity_infos"
):
if
hasattr
(
last_trail
,
"entity_infos"
):
# print(last_trail.entity_infos)
last_trail
.
entity_infos
[
"distance_from_sun"
]
=
d_sun
last_trail
.
entity_infos
[
"distance_from_sun"
]
=
d_sun
last_trail
.
entity_infos
[
"distance_from_earth"
]
=
d_earth
last_trail
.
entity_infos
[
"distance_from_earth"
]
=
d_earth
last_trail
.
entity_infos
[
"time"
]
=
dt
.
strftime
(
"%Y-%m-%d"
)
last_trail
.
entity_infos
[
"time"
]
=
dt
.
strftime
(
"%Y-%m-%d"
)
# print(last_trail.entity_infos)
pos
=
self
.
halley_comet
.
planet
.
position
pos
=
self
.
halley_comet
.
planet
.
position
...
@@ -257,8 +265,8 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -257,8 +265,8 @@ class HalleyCometSim(HalleyCometSimBase):
self
.
last_label_pos
=
copy
.
deepcopy
(
self
.
halley_comet
.
position
)
self
.
last_label_pos
=
copy
.
deepcopy
(
self
.
halley_comet
.
position
)
self
.
last_year
=
year
self
.
last_year
=
year
# 哈雷彗星离太阳最近的点称为 "perihelion of Halley's Comet"(近日点:comet_peri),
# 哈雷彗星离太阳最近的点称为 "perihelion of Halley's Comet"(近日点:comet_peri),
if
not
hasattr
(
self
,
"comet_peri"
):
if
not
hasattr
(
self
,
"comet_peri"
):
self
.
comet_peri
=
d_sun
self
.
comet_peri
=
d_sun
self
.
comet_peri_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
self
.
comet_peri_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
...
@@ -277,34 +285,25 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -277,34 +285,25 @@ class HalleyCometSim(HalleyCometSimBase):
self
.
set_comet_trail_alpha
(
d_sun
)
self
.
set_comet_trail_alpha
(
d_sun
)
panel_text
=
"哈雷彗星:
\n\n
距离太阳:%.3f AU"
%
(
d_sun
/
AU
)
panel_text
=
"哈雷彗星:
\n\n
距离太阳:%.3f AU"
%
(
d_sun
/
AU
)
# panel_text += "\n离日最远:%.3f AU(%s)" % (self.comet_aphel / AU, self.comet_aphel_dt)
panel_text
+=
"
\n\n
离日最远:%.3f AU"
%
(
self
.
comet_aphel
/
AU
)
panel_text
+=
"
\n\n
离日最远:%.3f AU"
%
(
self
.
comet_aphel
/
AU
)
# panel_text += "\n离日最近:%.3f AU(%s)" % (self.comet_peri / AU, self.comet_peri_dt)
panel_text
+=
"
\n\n
离日最近:%.3f AU"
%
(
self
.
comet_peri
/
AU
)
panel_text
+=
"
\n\n
离日最近:%.3f AU"
%
(
self
.
comet_peri
/
AU
)
# panel_text += "\n距离地球:%.3f AU" % (d_earth / AU)
velocity
,
_
=
get_value_direction_vectors
(
self
.
halley_comet
.
velocity
)
velocity
,
_
=
get_value_direction_vectors
(
self
.
halley_comet
.
velocity
)
panel_text
+=
"
\n\n
当前速度:%.3f km/s"
%
velocity
panel_text
+=
"
\n\n
当前速度:%.3f km/s"
%
velocity
self
.
text_panel
.
text
=
panel_text
self
.
text_panel
.
text
=
panel_text
self
.
set_bodies_position
(
time_data
)
time_total_hours
=
time_data
.
total_hours
self
.
show_clock
(
dt
)
if
not
hasattr
(
self
,
"last_total_hours"
):
self
.
last_total_hours
=
time_total_hours
for
i
,
orbit_line
in
enumerate
(
self
.
orbit_lines
):
if
time_total_hours
-
self
.
last_total_hours
>
240
:
orbit_line
.
position
=
self
.
sun
.
planet
.
position
self
.
set_bodies_position
(
time_data
)
self
.
show_clock
(
dt
)
self
.
last_total_hours
=
time_total_hours
def
on_body_trail_clicked
(
self
,
e
):
# for i, orbit_line in enumerate(self.orbit_lines):
if
e
[
"key"
]
==
"right mouse up"
:
# orbit_line.position = self.sun.planet.position
trail
=
e
[
"sender"
]
d_sun
=
trail
.
entity_infos
[
"distance_from_sun"
]
d_earth
=
trail
.
entity_infos
[
"distance_from_earth"
]
t
=
trail
.
entity_infos
[
"time"
]
# print("key:", e["key"])
msg
=
"哈雷彗星:
\n
距离太阳:%.3f AU"
%
(
d_sun
/
AU
)
msg
+=
"
\n
距离地球:%.3f AU"
%
(
d_earth
/
AU
)
msg
+=
"
\n
当前日期:[%s]"
%
t
ControlUI
.
current_ui
.
show_message
(
msg
,
close_time
=
3
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -316,9 +315,6 @@ if __name__ == '__main__':
...
@@ -316,9 +315,6 @@ if __name__ == '__main__':
# 2019年5月6日 34.772
# 2019年5月6日 34.772
params
=
HalleyCometParams
(
params
=
HalleyCometParams
(
start_time
=
'1982-09-24 00:00:00'
,
start_time
=
'1982-09-24 00:00:00'
,
# init_velocity=[-2.835, 4.72, 8.847],
# init_velocity=[-2.826, 4.695, 8.86],
# init_velocity=[-2.836, 4.705, 8.85],
# init_velocity=[-2.80, 5.10, 8.65], # 1/8
# init_velocity=[-2.80, 5.10, 8.65], # 1/8
init_velocity
=
[
-
2.774
,
5.126
,
8.65
],
# 1/8
init_velocity
=
[
-
2.774
,
5.126
,
8.65
],
# 1/8
init_position
=
[
0
,
-
5
*
AU
,
-
10
*
AU
]
init_position
=
[
0
,
-
5
*
AU
,
-
10
*
AU
]
...
@@ -332,16 +328,16 @@ if __name__ == '__main__':
...
@@ -332,16 +328,16 @@ if __name__ == '__main__':
UrsinaEvent
.
on_timer_changed_subscription
(
sim
.
on_timer_changed
)
UrsinaEvent
.
on_timer_changed_subscription
(
sim
.
on_timer_changed
)
# 运行前会触发 on_ready
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
sim
.
on_ready
)
UrsinaEvent
.
on_ready_subscription
(
sim
.
on_ready
)
# 天体拖尾点击事件
UrsinaEvent
.
on_body_trail_clicked_subscription
(
sim
.
on_body_trail_clicked
)
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
sim
.
bodies
,
ursina_run
(
sim
.
bodies
,
SECONDS_PER_YEAR
*
RUN_SPEED
,
SECONDS_PER_YEAR
*
get_run_speed_factor
()
,
# position=(0, 2 * AU, -11 * AU),
# position=(0, 2 * AU, -11 * AU),
# position=(0, 0.5 * AU, -5 * AU),
# position=(0, 0.5 * AU, -5 * AU),
position
=
(
2
*
AU
,
-
5
*
AU
,
-
20
*
AU
),
# position=(2 * AU, -5 * AU, -20 * AU),
show_name
=
True
,
position
=
(
2
*
AU
,
-
6
*
AU
,
-
20
*
AU
),
cosmic_bg
=
''
,
cosmic_bg
=
''
,
show_trail
=
True
,
show_trail
=
True
,
# bg_music='sounds/no_glory.mp3',
# bg_music='sounds/no_glory.mp3',
...
...
simulators/ursina/entities/body_trail.py
浏览文件 @
10a5eca8
...
@@ -90,7 +90,7 @@ class BodyTrail(Entity):
...
@@ -90,7 +90,7 @@ class BodyTrail(Entity):
if
vel_value
<
0.00000001
:
if
vel_value
<
0.00000001
:
label
=
create_label
(
parent
=
self
,
label
=
vel_info
,
pos
=
Vec3
(
-
0.5
,
-
0.5
,
-
0.5
),
label
=
create_label
(
parent
=
self
,
label
=
vel_info
,
pos
=
Vec3
(
-
0.5
,
-
0.5
,
-
0.5
),
color
=
color
.
red
).
set_light_off
()
label_
color
=
color
.
red
).
set_light_off
()
self
.
info_entities
.
append
(
label
)
self
.
info_entities
.
append
(
label
)
# label.infos = vel_info
# label.infos = vel_info
# v_text.parent = self
# v_text.parent = self
...
@@ -106,7 +106,7 @@ class BodyTrail(Entity):
...
@@ -106,7 +106,7 @@ class BodyTrail(Entity):
if
acc_m
<
0.00000001
:
if
acc_m
<
0.00000001
:
label
=
create_label
(
parent
=
self
,
label
=
acc_info
,
pos
=
Vec3
(
0.5
,
0.5
,
0.5
),
label
=
create_label
(
parent
=
self
,
label
=
acc_info
,
pos
=
Vec3
(
0.5
,
0.5
,
0.5
),
color
=
color
.
green
).
set_light_off
()
label_
color
=
color
.
green
).
set_light_off
()
self
.
info_entities
.
append
(
label
)
self
.
info_entities
.
append
(
label
)
# label.infos = acc_info
# label.infos = acc_info
# a_text.parent = self
# a_text.parent = self
...
...
simulators/ursina/entities/planet.py
浏览文件 @
10a5eca8
...
@@ -363,5 +363,5 @@ class Planet(Entity):
...
@@ -363,5 +363,5 @@ class Planet(Entity):
self
.
label_name
=
create_label
(
parent
=
self
,
self
.
label_name
=
create_label
(
parent
=
self
,
label
=
self
.
body
.
name
,
label
=
self
.
body
.
name
,
pos
=
Vec3
(
-
0.5
,
-
0.5
,
-
0.5
),
pos
=
Vec3
(
-
0.5
,
-
0.5
,
-
0.5
),
color
=
color
.
red
)
label_
color
=
color
.
red
)
self
.
label_name
.
set_light_off
()
self
.
label_name
.
set_light_off
()
simulators/ursina/ursina_mesh.py
浏览文件 @
10a5eca8
...
@@ -194,17 +194,35 @@ def create_arrow(height=0.5, width=0.1):
...
@@ -194,17 +194,35 @@ def create_arrow(height=0.5, width=0.1):
return
arrow_mesh
return
arrow_mesh
def
create_label
(
parent
,
label
,
pos
,
color
,
scale
=
50
,
alpha
=
1.0
,
background
=
False
):
def
create_label
(
parent
,
label
,
pos
,
label_
color
,
scale
=
50
,
alpha
=
1.0
,
background
=
False
):
if
isinstance
(
color
,
tuple
)
or
isinstance
(
color
,
list
):
if
isinstance
(
label_color
,
tuple
)
or
isinstance
(
label_
color
,
list
):
color
=
conv_to_vec4_color
(
color
)
label_color
=
conv_to_vec4_color
(
label_
color
)
if
alpha
<
1
:
if
alpha
<
1
:
color
[
3
]
=
alpha
label_
color
[
3
]
=
alpha
text
=
Text
(
label
,
parent
=
parent
,
scale
=
scale
,
billboard
=
True
,
color
=
color
,
text
=
Text
(
label
,
parent
=
parent
,
scale
=
scale
,
billboard
=
True
,
color
=
label_
color
,
position
=
Vec3
(
pos
)
+
Vec3
(
1
,
1
,
1
),
alpha
=
alpha
,
position
=
Vec3
(
pos
)
+
Vec3
(
1
,
1
,
1
),
alpha
=
alpha
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
background
)
font
=
UrsinaConfig
.
CN_FONT
,
background
=
background
)
return
text
return
text
def
create_label__
(
parent
,
label
,
pos
,
label_color
,
scale
=
50
,
alpha
=
1.0
,
bg_color
=
None
):
if
isinstance
(
label_color
,
tuple
)
or
isinstance
(
label_color
,
list
):
label_color
=
conv_to_vec4_color
(
label_color
)
if
alpha
<
1
:
label_color
[
3
]
=
alpha
text
=
Text
(
label
,
parent
=
parent
,
scale
=
scale
,
billboard
=
True
,
color
=
label_color
,
position
=
Vec3
(
pos
)
+
Vec3
(
1
,
1
,
1
),
alpha
=
alpha
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
bg_color
is
not
None
)
if
bg_color
is
not
None
:
b_color
=
conv_to_vec4_color
(
bg_color
)
text
.
background
.
color
=
b_color
# text.background.parent
text
.
background
.
position
=
Vec3
(
0
,
0
,
0
)
text
.
background
.
model
.
radius
/=
2
text
.
set_light_off
(
True
)
return
text
def
create_line
(
from_pos
,
to_pos
,
parent
=
None
,
alpha
=
1.0
,
len_scale
=
1
,
set_light_off
=
True
,
def
create_line
(
from_pos
,
to_pos
,
parent
=
None
,
alpha
=
1.0
,
len_scale
=
1
,
set_light_off
=
True
,
color
=
color
.
white
,
thickness
=
1
):
color
=
color
.
white
,
thickness
=
1
):
line
=
Entity
(
parent
=
parent
,
line
=
Entity
(
parent
=
parent
,
...
@@ -290,7 +308,7 @@ def create_arrow_line(from_pos, to_pos, parent=None, label=None,
...
@@ -290,7 +308,7 @@ def create_arrow_line(from_pos, to_pos, parent=None, label=None,
if
label
is
not
None
:
if
label
is
not
None
:
text
=
create_label
(
parent
=
line
,
label
=
label
,
pos
=
Vec3
(
to_pos
)
*
len_scale
*
1.2
,
text
=
create_label
(
parent
=
line
,
label
=
label
,
pos
=
Vec3
(
to_pos
)
*
len_scale
*
1.2
,
color
=
color
,
scale
=
text_scale
,
alpha
=
alpha
)
label_
color
=
color
,
scale
=
text_scale
,
alpha
=
alpha
)
if
set_light_off
:
if
set_light_off
:
text
.
set_light_off
()
text
.
set_light_off
()
else
:
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录