Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
686226a1
宇宙模拟器
项目概览
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看板
提交
686226a1
编写于
10月 29, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
ec6c1c55
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
20 deletion
+63
-20
sim_scenes/solar_system/halley_comet_sim_03.py
sim_scenes/solar_system/halley_comet_sim_03.py
+32
-18
simulators/ursina/entities/label.py
simulators/ursina/entities/label.py
+19
-0
simulators/ursina/ursina_mesh.py
simulators/ursina/ursina_mesh.py
+12
-2
未找到文件。
sim_scenes/solar_system/halley_comet_sim_03.py
浏览文件 @
686226a1
...
@@ -25,7 +25,7 @@ from simulators.ursina.entities.entity_utils import get_value_direction_vectors
...
@@ -25,7 +25,7 @@ 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
from
simulators.ursina.ursina_mesh
import
create_orbit_by_points
from
simulators.ursina.ursina_mesh
import
create_orbit_by_points
,
create_label
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
dataclasses
import
field
from
dataclasses
import
field
...
@@ -181,6 +181,11 @@ class HalleyCometSim:
...
@@ -181,6 +181,11 @@ class HalleyCometSim:
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
):
label
=
create_label
(
trail
,
label
=
year
,
pos
=
(
0
,
0
,
0
),
color
=
(
255
,
255
,
255
),
scale
=
40
,
alpha
=
1.0
)
# label.udpate
label
.
set_light_off
()
def
on_timer_changed
(
self
,
time_data
):
def
on_timer_changed
(
self
,
time_data
):
"""
"""
...
@@ -188,6 +193,8 @@ class HalleyCometSim:
...
@@ -188,6 +193,8 @@ class HalleyCometSim:
@return:
@return:
"""
"""
dt
=
time_data
.
get_datetime
(
str
(
self
.
start_time
))
dt
=
time_data
.
get_datetime
(
str
(
self
.
start_time
))
year
=
dt
.
strftime
(
"%Y"
)
if
hasattr
(
self
,
"halley_comet"
):
if
hasattr
(
self
,
"halley_comet"
):
# 哈雷彗星飞行的翻转效果
# 哈雷彗星飞行的翻转效果
if
self
.
halley_comet
.
planet
.
enabled
:
if
self
.
halley_comet
.
planet
.
enabled
:
...
@@ -195,23 +202,30 @@ class HalleyCometSim:
...
@@ -195,23 +202,30 @@ class HalleyCometSim:
# self.halley_comet.planet.rotation_y += 1
# self.halley_comet.planet.rotation_y += 1
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
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
()
last_trail
=
list
(
trail_keys
)[
-
1
]
# self.halley_comet.planet.trails[list(trail_keys)[-1]]
last_trail
=
list
(
trail_keys
)[
-
1
]
# self.halley_comet.planet.trails[list(trail_keys)[-1]]
if
hasattr
(
last_trail
,
"entity_infos"
):
if
hasattr
(
last_trail
,
"entity_infos"
):
# print(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)
# print(last_trail.entity_infos)
panel_text
=
"哈雷彗星:
\n
距离太阳:%.3f AU"
%
(
d_sun
/
AU
)
if
not
hasattr
(
self
,
"last_year"
):
panel_text
+=
"
\n
距离地球:%.3f AU"
%
(
d_earth
/
AU
)
self
.
create_year_label
(
last_trail
,
year
,
self
.
halley_comet
.
planet
.
position
)
velocity
,
_
=
get_value_direction_vectors
(
self
.
halley_comet
.
velocity
)
elif
self
.
last_year
!=
year
:
panel_text
+=
"
\n
当前速度:%.3f km/s"
%
velocity
self
.
create_year_label
(
last_trail
,
year
,
self
.
halley_comet
.
planet
.
position
)
self
.
text_panel
.
text
=
panel_text
self
.
last_year
=
year
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
)
...
...
simulators/ursina/entities/label.py
0 → 100644
浏览文件 @
686226a1
# -*- coding:utf-8 -*-
# title :标签对象
# description :标签对象
# author :Python超人
# date :2023-10-29
# link :https://gitcode.net/pythoncr/
# python_version :3.9
# ==============================================================================
from
ursina
import
Text
,
color
class
Label
(
Text
):
def
__init__
(
self
,
text
=
''
,
position
=
(
0
,
0
,
0
),
**
kwargs
):
# def __init__(self, text='', start_tag=start_tag, end_tag=end_tag, ignore=True, **kwargs):
super
().
__init__
(
text
=
text
,
position
=
position
,
**
kwargs
)
simulators/ursina/ursina_mesh.py
浏览文件 @
686226a1
...
@@ -18,6 +18,7 @@ from common.color_utils import conv_to_vec4_color
...
@@ -18,6 +18,7 @@ from common.color_utils import conv_to_vec4_color
from
common.func
import
calculate_distance
from
common.func
import
calculate_distance
from
simulators.ursina.entities.circle_line
import
CircleLine
from
simulators.ursina.entities.circle_line
import
CircleLine
from
simulators.ursina.entities.orbit_line
import
OrbitLine
from
simulators.ursina.entities.orbit_line
import
OrbitLine
from
simulators.ursina.entities.label
import
Label
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
...
@@ -69,6 +70,11 @@ def create_sphere(radius, subdivisions):
...
@@ -69,6 +70,11 @@ def create_sphere(radius, subdivisions):
return
Mesh
(
vertices
=
verts
,
triangles
=
tris
,
normals
=
normals
,
uvs
=
uvs
,
mode
=
'triangle'
)
return
Mesh
(
vertices
=
verts
,
triangles
=
tris
,
normals
=
normals
,
uvs
=
uvs
,
mode
=
'triangle'
)
# def create_label(text, position=(0, 0, 0)):
# label = Label(text=text, position=position)
# return label
def
create_cone
(
radius
,
height
,
subdivisions
,
r
=
0.1
):
def
create_cone
(
radius
,
height
,
subdivisions
,
r
=
0.1
):
"""
"""
创建一个圆锥
创建一个圆锥
...
@@ -82,8 +88,8 @@ def create_cone(radius, height, subdivisions, r=0.1):
...
@@ -82,8 +88,8 @@ def create_cone(radius, height, subdivisions, r=0.1):
normals
=
[]
# 法线列表
normals
=
[]
# 法线列表
uvs
=
[]
# UV坐标列表
uvs
=
[]
# UV坐标列表
p_h
=
r
*
height
p_h
=
r
*
height
d_h
=
(
1
-
r
)
*
height
d_h
=
(
1
-
r
)
*
height
# 生成圆锥底部的顶点和UV坐标
# 生成圆锥底部的顶点和UV坐标
for
i
in
range
(
subdivisions
):
for
i
in
range
(
subdivisions
):
...
@@ -189,6 +195,10 @@ def create_arrow(height=0.5, width=0.1):
...
@@ -189,6 +195,10 @@ def create_arrow(height=0.5, width=0.1):
def
create_label
(
parent
,
label
,
pos
,
color
,
scale
=
50
,
alpha
=
1.0
):
def
create_label
(
parent
,
label
,
pos
,
color
,
scale
=
50
,
alpha
=
1.0
):
if
isinstance
(
color
,
tuple
)
or
isinstance
(
color
,
list
):
color
=
conv_to_vec4_color
(
color
)
if
alpha
<
1
:
color
[
3
]
=
alpha
text
=
Text
(
label
,
parent
=
parent
,
scale
=
scale
,
billboard
=
True
,
color
=
color
,
text
=
Text
(
label
,
parent
=
parent
,
scale
=
scale
,
billboard
=
True
,
color
=
color
,
position
=
Vec3
(
pos
)
+
Vec3
(
1
,
1
,
1
),
alpha
=
alpha
,
position
=
Vec3
(
pos
)
+
Vec3
(
1
,
1
,
1
),
alpha
=
alpha
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
False
)
font
=
UrsinaConfig
.
CN_FONT
,
background
=
False
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录