Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
2c8eb08f
宇宙模拟器
项目概览
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看板
提交
2c8eb08f
编写于
4月 16, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
ce911879
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
24 deletion
+31
-24
objs/satellite.py
objs/satellite.py
+1
-1
sim_scenes/earth/earth_satellites.py
sim_scenes/earth/earth_satellites.py
+12
-5
simulators/ursina/entities/entity_utils.py
simulators/ursina/entities/entity_utils.py
+18
-18
未找到文件。
objs/satellite.py
浏览文件 @
2c8eb08f
...
@@ -19,7 +19,7 @@ class Satellite(Obj):
...
@@ -19,7 +19,7 @@ class Satellite(Obj):
init_velocity
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
texture
=
"satelite.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
texture
=
"satelite.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
7
,
0
,
162
),
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
7
,
0
,
162
),
trail_color
=
None
,
show_name
=
False
,
trail_color
=
(
255
,
255
,
255
)
,
show_name
=
False
,
model
=
"satelite.obj"
,
model
=
"satelite.obj"
,
parent
=
None
,
gravity_only_for
=
[]):
parent
=
None
,
gravity_only_for
=
[]):
params
=
{
params
=
{
...
...
sim_scenes/earth/earth_satellites.py
浏览文件 @
2c8eb08f
...
@@ -103,12 +103,12 @@ if __name__ == '__main__':
...
@@ -103,12 +103,12 @@ if __name__ == '__main__':
# 北斗卫星高度为2.13-2.15万千米。GPS卫星平均轨道高度2.02万千米。
# 北斗卫星高度为2.13-2.15万千米。GPS卫星平均轨道高度2.02万千米。
bodies
=
[
earth
]
bodies
=
[
earth
]
satellite_infos
=
[
satellite_infos
=
[
{
"position"
:
[
0
,
0
,
1000
0
],
"velocity"
:
[
-
6.3
,
0
,
0
]},
{
"position"
:
[
0
,
0
,
1000
2
],
"velocity"
:
[
6.3
,
0
,
0
]},
{
"position"
:
[
0
,
0
,
-
12000
],
"velocity"
:
[
5.75
,
0
,
0
]},
{
"position"
:
[
0
,
0
,
-
12000
],
"velocity"
:
[
5.75
,
0
,
0
]},
{
"position"
:
[
0
,
8000
,
0
],
"velocity"
:
[
7.05
,
0
,
0
]},
{
"position"
:
[
0
,
8000
,
0
],
"velocity"
:
[
7.05
,
0
,
0
]},
{
"position"
:
[
0
,
-
1200
0
,
0
],
"velocity"
:
[
-
5.75
,
0
,
0
]},
{
"position"
:
[
0
,
-
1200
2
,
0
],
"velocity"
:
[
5.75
,
0
,
0
]},
{
"position"
:
[
0
,
0
,
800
0
],
"velocity"
:
[
0
,
7.05
,
0
]},
{
"position"
:
[
0
,
0
,
800
2
],
"velocity"
:
[
0
,
7.05
,
0
]},
{
"position"
:
[
0
,
0
,
-
10000
],
"velocity"
:
[
0
,
-
6.3
,
0
]},
{
"position"
:
[
0
,
0
,
-
10000
],
"velocity"
:
[
0
,
6.3
,
0
]},
]
]
for
i
,
info
in
enumerate
(
satellite_infos
):
for
i
,
info
in
enumerate
(
satellite_infos
):
# altitude = random.randint(4000, 10000)
# altitude = random.randint(4000, 10000)
...
@@ -117,6 +117,7 @@ if __name__ == '__main__':
...
@@ -117,6 +117,7 @@ if __name__ == '__main__':
satellite
=
Satellite
(
name
=
f
'卫星
{
i
+
1
}
'
,
mass
=
4.4e10
,
size_scale
=
2e2
,
color
=
(
255
,
200
,
0
),
satellite
=
Satellite
(
name
=
f
'卫星
{
i
+
1
}
'
,
mass
=
4.4e10
,
size_scale
=
2e2
,
color
=
(
255
,
200
,
0
),
init_position
=
info
[
"position"
],
init_position
=
info
[
"position"
],
init_velocity
=
info
[
"velocity"
])
init_velocity
=
info
[
"velocity"
])
info
[
"satellite"
]
=
satellite
bodies
.
append
(
satellite
)
bodies
.
append
(
satellite
)
...
@@ -126,13 +127,19 @@ if __name__ == '__main__':
...
@@ -126,13 +127,19 @@ if __name__ == '__main__':
UrsinaConfig
.
trail_type
=
"line"
UrsinaConfig
.
trail_type
=
"line"
pass
pass
def
on_timer_changed
(
time_data
:
TimeData
):
for
info
in
satellite_infos
:
info
[
"satellite"
].
planet
.
look_at
(
earth
.
planet
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_HOUR
/
2
,
ursina_run
(
bodies
,
SECONDS_PER_HOUR
/
2
,
position
=
(
30000
,
5000
,
-
3
0000
),
position
=
(
30000
,
10000
,
-
2
0000
),
show_trail
=
True
,
show_trail
=
True
,
show_timer
=
True
,
view_closely
=
0.001
)
view_closely
=
0.001
)
simulators/ursina/entities/entity_utils.py
浏览文件 @
2c8eb08f
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
from
ursina
import
Ursina
,
window
,
Entity
,
Mesh
,
SmoothFollow
,
Texture
,
clamp
,
time
,
\
from
ursina
import
Ursina
,
window
,
Entity
,
Mesh
,
SmoothFollow
,
Texture
,
clamp
,
time
,
\
camera
,
color
,
mouse
,
Vec2
,
Vec3
,
Vec4
,
Text
,
\
camera
,
color
,
mouse
,
Vec2
,
Vec3
,
Vec4
,
Text
,
\
load_texture
,
held_keys
,
destroy
,
PointLight
load_texture
,
held_keys
,
destroy
,
PointLight
,
distance
from
simulators.ursina.entities.body_trail
import
BodyTrail
,
BodyTrailLine
from
simulators.ursina.entities.body_trail
import
BodyTrail
,
BodyTrailLine
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
...
@@ -143,14 +143,14 @@ def create_trail_sphere(parent, pos):
...
@@ -143,14 +143,14 @@ def create_trail_sphere(parent, pos):
return
trail
return
trail
def
merge_vectors
(
vectors
):
#
def merge_vectors(vectors):
# 计算速度的大小
#
# 计算速度的大小
x
,
y
,
z
=
vectors
[
0
],
vectors
[
1
],
vectors
[
2
]
#
x, y, z = vectors[0], vectors[1], vectors[2]
value
=
math
.
sqrt
(
x
**
2
+
y
**
2
+
z
**
2
)
#
value = math.sqrt(x ** 2 + y ** 2 + z ** 2)
# 计算速度的方向
#
# 计算速度的方向
direction
=
(
x
/
value
,
y
/
value
,
z
/
value
)
#
direction = (x / value, y / value, z / value)
# 返回速度大小和速度方向
#
# 返回速度大小和速度方向
return
value
,
direction
#
return value, direction
def
create_trail_line
(
parent
,
pos
):
def
create_trail_line
(
parent
,
pos
):
...
@@ -159,16 +159,16 @@ def create_trail_line(parent, pos):
...
@@ -159,16 +159,16 @@ def create_trail_line(parent, pos):
@param pos:
@param pos:
@return:
@return:
"""
"""
trail
=
None
if
hasattr
(
parent
,
"trail_last_pos"
):
if
hasattr
(
parent
,
"trail_last_pos"
):
trail_last_pos
=
parent
.
trail_last_pos
trail_last_pos
=
parent
.
trail_last_pos
value
,
direction
=
merge_vectors
(
pos
-
trail_last_pos
)
if
distance
(
pos
,
trail_last_pos
)
>
0
:
trail
=
BodyTrailLine
(
color
=
parent
.
trail_color
,
scale
=
parent
.
trail_scale
,
position
=
trail_last_pos
,
value
,
direction
=
get_value_direction_vectors
(
pos
-
trail_last_pos
)
direction
=
Vec3
(
direction
))
trail
=
BodyTrailLine
(
color
=
parent
.
trail_color
,
scale
=
parent
.
trail_scale
,
position
=
trail_last_pos
,
trail
.
set_light_off
()
direction
=
Vec3
(
direction
))
trail
.
set_light_off
()
parent
.
last_trail
=
trail
parent
.
last_trail
=
trail
else
:
trail
=
None
parent
.
trail_last_pos
=
pos
parent
.
trail_last_pos
=
pos
return
trail
return
trail
...
@@ -261,7 +261,7 @@ def create_fixed_star_lights(fixed_star):
...
@@ -261,7 +261,7 @@ def create_fixed_star_lights(fixed_star):
light
=
PointLight
(
parent
=
fixed_star
,
intensity
=
10
,
range
=
10
,
color
=
color
.
white
)
light
=
PointLight
(
parent
=
fixed_star
,
intensity
=
10
,
range
=
10
,
color
=
color
.
white
)
def
merge
_vectors
(
vectors
):
def
get_value_direction
_vectors
(
vectors
):
# 计算速度的大小
# 计算速度的大小
x
,
y
,
z
=
vectors
[
0
],
vectors
[
1
],
vectors
[
2
]
x
,
y
,
z
=
vectors
[
0
],
vectors
[
1
],
vectors
[
2
]
value
=
math
.
sqrt
(
x
**
2
+
y
**
2
+
z
**
2
)
value
=
math
.
sqrt
(
x
**
2
+
y
**
2
+
z
**
2
)
...
@@ -276,8 +276,8 @@ def merge_vectors(vectors):
...
@@ -276,8 +276,8 @@ def merge_vectors(vectors):
def
create_trail_info
(
body
,
trail
):
def
create_trail_info
(
body
,
trail
):
velocity
=
merge
_vectors
(
body
.
velocity
)
velocity
=
get_value_direction
_vectors
(
body
.
velocity
)
acceleration
=
merge
_vectors
(
body
.
acceleration
)
acceleration
=
get_value_direction
_vectors
(
body
.
acceleration
)
vel_value
=
velocity
[
0
]
# km/s
vel_value
=
velocity
[
0
]
# km/s
acc_value
=
acceleration
[
0
]
# km/s²
acc_value
=
acceleration
[
0
]
# km/s²
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录