Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
124a3b58
宇宙模拟器
项目概览
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看板
提交
124a3b58
编写于
10月 28, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
b811bd66
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
53 addition
and
3 deletion
+53
-3
sim_scenes/solar_system/halley_comet_sim_03.py
sim_scenes/solar_system/halley_comet_sim_03.py
+32
-2
simulators/ursina/entities/body_trail.py
simulators/ursina/entities/body_trail.py
+4
-1
simulators/ursina/ursina_event.py
simulators/ursina/ursina_event.py
+17
-0
未找到文件。
sim_scenes/solar_system/halley_comet_sim_03.py
浏览文件 @
124a3b58
...
@@ -21,6 +21,7 @@ from objs import HalleComet
...
@@ -21,6 +21,7 @@ from objs import HalleComet
from
sim_scenes.func
import
create_text_panel
from
sim_scenes.func
import
create_text_panel
from
sim_scenes.func
import
ursina_run
,
create_sphere_sky
from
sim_scenes.func
import
ursina_run
,
create_sphere_sky
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.entities.entity_utils
import
get_value_direction_vectors
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
...
@@ -192,8 +193,23 @@ class HalleyCometSim:
...
@@ -192,8 +193,23 @@ class HalleyCometSim:
if
self
.
halley_comet
.
planet
.
enabled
:
if
self
.
halley_comet
.
planet
.
enabled
:
self
.
halley_comet
.
planet
.
rotation_x
+=
0.1
self
.
halley_comet
.
planet
.
rotation_x
+=
0.1
self
.
halley_comet
.
planet
.
rotation_y
+=
1
self
.
halley_comet
.
planet
.
rotation_y
+=
1
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
self
.
text_panel
.
text
=
"哈雷彗星距离太阳:%.3f AU"
%
(
d
/
AU
)
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
last_trail
=
list
(
trail_keys
)[
-
1
]
# self.halley_comet.planet.trails[list(trail_keys)[-1]]
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_earth"
]
=
d_earth
last_trail
.
entity_infos
[
"time"
]
=
dt
.
strftime
(
"%Y-%m-%d"
)
# print(last_trail.entity_infos)
panel_text
=
"哈雷彗星:
\n
距离太阳:%.3f AU"
%
(
d_sun
/
AU
)
panel_text
+=
"
\n
距离地球:%.3f AU"
%
(
d_earth
/
AU
)
velocity
,
_
=
get_value_direction_vectors
(
self
.
halley_comet
.
velocity
)
panel_text
+=
"
\n
当前速度:%.3f km/s"
%
velocity
self
.
text_panel
.
text
=
panel_text
self
.
set_bodies_position
(
time_data
)
self
.
set_bodies_position
(
time_data
)
...
@@ -202,6 +218,18 @@ class HalleyCometSim:
...
@@ -202,6 +218,18 @@ class HalleyCometSim:
for
i
,
orbit_line
in
enumerate
(
self
.
orbit_lines
):
for
i
,
orbit_line
in
enumerate
(
self
.
orbit_lines
):
orbit_line
.
position
=
self
.
sun
.
planet
.
position
orbit_line
.
position
=
self
.
sun
.
planet
.
position
def
on_body_trail_clicked
(
self
,
e
):
if
e
[
"key"
]
==
"right mouse up"
:
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__'
:
"""
"""
...
@@ -228,6 +256,8 @@ if __name__ == '__main__':
...
@@ -228,6 +256,8 @@ 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 = 左-右+、上+下-、前+后-
...
...
simulators/ursina/entities/body_trail.py
浏览文件 @
124a3b58
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
from
ursina
import
Entity
,
Mesh
,
Text
,
color
,
destroy
,
Vec3
from
ursina
import
Entity
,
Mesh
,
Text
,
color
,
destroy
,
Vec3
from
common.color_utils
import
get_inverse_color
from
common.color_utils
import
get_inverse_color
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_mesh
import
create_label
from
simulators.ursina.ursina_mesh
import
create_label
from
simulators.ursina.ursina_mesh
import
create_arrow_line
from
simulators.ursina.ursina_mesh
import
create_arrow_line
...
@@ -42,6 +43,8 @@ class BodyTrail(Entity):
...
@@ -42,6 +43,8 @@ class BodyTrail(Entity):
# print(key, self)
# print(key, self)
self
.
show_infos
()
self
.
show_infos
()
UrsinaEvent
.
on_body_trail_clicked
({
"sender"
:
self
,
"key"
:
key
})
def
show_infos
(
self
):
def
show_infos
(
self
):
if
not
hasattr
(
self
,
"entity_infos"
):
if
not
hasattr
(
self
,
"entity_infos"
):
return
return
...
@@ -133,7 +136,7 @@ class BodyTrailLine(Entity):
...
@@ -133,7 +136,7 @@ class BodyTrailLine(Entity):
super
().
__init__
(
super
().
__init__
(
# model='line',
# model='line',
model
=
Mesh
(
vertices
=
((
0
,
0
,
0
),
direction
),
mode
=
'line'
,
thickness
=
2
*
thickness
),
model
=
Mesh
(
vertices
=
((
0
,
0
,
0
),
direction
),
mode
=
'line'
,
thickness
=
2
*
thickness
),
ignore_paused
=
True
,
ignore_paused
=
True
,
**
kwargs
**
kwargs
)
)
simulators/ursina/ursina_event.py
浏览文件 @
124a3b58
...
@@ -40,6 +40,23 @@ class UrsinaEvent:
...
@@ -40,6 +40,23 @@ class UrsinaEvent:
UrsinaEvent
.
on_before_evolving_callback
=
[]
UrsinaEvent
.
on_before_evolving_callback
=
[]
# 计时器触发的订阅事件
# 计时器触发的订阅事件
UrsinaEvent
.
on_timer_changed_callback
=
[]
UrsinaEvent
.
on_timer_changed_callback
=
[]
# 点击天体拖尾触发的订阅事件
UrsinaEvent
.
on_body_trail_clicked_callback
=
[]
@
staticmethod
def
on_body_trail_clicked_subscription
(
fun
):
UrsinaEvent
.
on_body_trail_clicked_callback
.
append
(
fun
)
@
staticmethod
def
on_body_trail_clicked_unsubscription
(
fun
):
UrsinaEvent
.
on_body_trail_clicked_callback
.
remove
(
fun
)
@
staticmethod
def
on_body_trail_clicked
(
e
):
for
f
in
UrsinaEvent
.
on_body_trail_clicked_callback
:
f
(
e
)
@
staticmethod
@
staticmethod
def
on_body_size_changed_subscription
(
fun
):
def
on_body_size_changed_subscription
(
fun
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录