Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
6b46c28c
宇宙模拟器
项目概览
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看板
提交
6b46c28c
编写于
4月 16, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
56f5a2b4
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
18738 addition
and
34 deletion
+18738
-34
objs/__init__.py
objs/__init__.py
+1
-0
objs/models/space_ship.obj
objs/models/space_ship.obj
+18616
-0
objs/obj.py
objs/obj.py
+2
-0
objs/space_ship.py
objs/space_ship.py
+48
-0
sim_scenes/func.py
sim_scenes/func.py
+14
-0
sim_scenes/solar_system/speed_of_light.py
sim_scenes/solar_system/speed_of_light.py
+4
-4
sim_scenes/solar_system/speed_of_light_init.py
sim_scenes/solar_system/speed_of_light_init.py
+48
-29
simulators/ursina/entities/planet.py
simulators/ursina/entities/planet.py
+5
-1
textures/space_ship.png
textures/space_ship.png
+0
-0
未找到文件。
objs/__init__.py
浏览文件 @
6b46c28c
from
objs.diamond
import
Diamond
from
objs.diamond
import
Diamond
from
objs.football
import
Football
from
objs.football
import
Football
from
objs.satellite
import
Satellite
from
objs.satellite
import
Satellite
from
objs.space_ship
import
SpaceShip
objs/models/space_ship.obj
0 → 100644
浏览文件 @
6b46c28c
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
objs/obj.py
浏览文件 @
6b46c28c
...
@@ -25,6 +25,7 @@ class Obj(metaclass=ABCMeta):
...
@@ -25,6 +25,7 @@ class Obj(metaclass=ABCMeta):
texture
=
None
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
texture
=
None
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
parent
=
None
,
ignore_mass
=
False
,
parent
=
None
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
,
trail_color
=
None
,
show_name
=
False
,
rotation
=
None
,
gravity_only_for
=
[],
model
=
None
):
gravity_only_for
=
[],
model
=
None
):
"""
"""
对象类
对象类
...
@@ -49,6 +50,7 @@ class Obj(metaclass=ABCMeta):
...
@@ -49,6 +50,7 @@ class Obj(metaclass=ABCMeta):
self
.
__his_reserved_num
=
200
self
.
__his_reserved_num
=
200
self
.
gravity_only_for
=
gravity_only_for
self
.
gravity_only_for
=
gravity_only_for
self
.
model
=
self
.
find_model
(
model
)
self
.
model
=
self
.
find_model
(
model
)
self
.
rotation
=
rotation
if
name
is
None
:
if
name
is
None
:
name
=
getattr
(
self
.
__class__
,
'__name__'
)
name
=
getattr
(
self
.
__class__
,
'__name__'
)
...
...
objs/space_ship.py
0 → 100644
浏览文件 @
6b46c28c
# -*- coding:utf-8 -*-
# title :地球
# description :地球
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
objs.obj
import
Obj
class
SpaceShip
(
Obj
):
"""
太空飞船
"""
def
__init__
(
self
,
name
=
"太空飞船"
,
mass
=
5.97237e24
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
texture
=
"space_ship.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
7
,
0
,
162
),
trail_color
=
None
,
show_name
=
False
,
model
=
"space_ship.obj"
,
rotation
=
(
0
,
0
,
0
),
parent
=
None
,
gravity_only_for
=
[]):
params
=
{
"name"
:
name
,
"mass"
:
mass
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
density
,
"color"
:
color
,
"texture"
:
texture
,
"size_scale"
:
size_scale
,
"distance_scale"
:
distance_scale
,
"ignore_mass"
:
ignore_mass
,
"trail_color"
:
trail_color
,
"show_name"
:
show_name
,
"parent"
:
parent
,
"rotation"
:
rotation
,
"gravity_only_for"
:
gravity_only_for
,
"model"
:
model
}
super
().
__init__
(
**
params
)
if
__name__
==
'__main__'
:
spaceship
=
SpaceShip
()
print
(
spaceship
)
sim_scenes/func.py
浏览文件 @
6b46c28c
...
@@ -225,6 +225,20 @@ def create_light_body(size_scale, init_position, speed=LIGHT_SPEED):
...
@@ -225,6 +225,20 @@ def create_light_body(size_scale, init_position, speed=LIGHT_SPEED):
init_velocity
=
[
0
,
0
,
speed
]).
set_light_disable
(
True
)
init_velocity
=
[
0
,
0
,
speed
]).
set_light_disable
(
True
)
def
create_light_ship
(
size_scale
,
init_position
,
speed
=
LIGHT_SPEED
):
"""
用天体模拟一个光速飞船
@param size_scale: 光速飞船的大小
@param init_position: 光速飞船的初始位置
@param speed: 光速飞船的速度->1光速=299792.458 千米/秒(km/秒)
@return:
"""
from
objs.space_ship
import
SpaceShip
return
SpaceShip
(
name
=
'光速飞船'
,
mass
=
0
,
size_scale
=
size_scale
,
color
=
(
255
,
110
,
0
),
init_position
=
init_position
,
init_velocity
=
[
0
,
0
,
speed
]).
set_light_disable
(
True
)
def
create_text_panel
(
width
=
0.35
,
height
=
.
5
):
def
create_text_panel
(
width
=
0.35
,
height
=
.
5
):
# 创建一个 Panel 组件
# 创建一个 Panel 组件
from
ursina
import
Text
,
Panel
,
color
,
camera
,
Vec3
from
ursina
import
Text
,
Panel
,
color
,
camera
,
Vec3
...
...
sim_scenes/solar_system/speed_of_light.py
浏览文件 @
6b46c28c
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
# link :https://gitcode.net/pythoncr/
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# python_version :3.8
# ==============================================================================
# ==============================================================================
from
sim_scenes.func
import
ursina_run
,
create_solar_system_bodies
,
create_light_
body
from
sim_scenes.func
import
ursina_run
,
create_solar_system_bodies
,
create_light_
ship
from
common.consts
import
LIGHT_SPEED
from
common.consts
import
LIGHT_SPEED
from
sim_scenes.solar_system.speed_of_light_init
import
SpeedOfLightInit
from
sim_scenes.solar_system.speed_of_light_init
import
SpeedOfLightInit
...
@@ -25,12 +25,12 @@ bodies = create_solar_system_bodies(ignore_mass=True, init_velocity=[0, 0, 0])
...
@@ -25,12 +25,12 @@ bodies = create_solar_system_bodies(ignore_mass=True, init_velocity=[0, 0, 0])
# 从 init 对象中获取 光体的大小(light_size_scale),光体的位置(light_init_position)
# 从 init 对象中获取 光体的大小(light_size_scale),光体的位置(light_init_position)
# 创建一个以光速前进的天体(模拟一个光子) speed=1光速=299792.458千米/秒,注意:质量为0才能达到光速,虽然如此,但也可以试试超光速
# 创建一个以光速前进的天体(模拟一个光子) speed=1光速=299792.458千米/秒,注意:质量为0才能达到光速,虽然如此,但也可以试试超光速
light_
body
=
create_light_body
(
init
.
light_size_scale
,
init
.
light_init_position
,
speed
=
LIGHT_SPEED
*
1
)
light_
ship
=
create_light_ship
(
init
.
light_size_scale
,
init
.
light_init_position
,
speed
=
LIGHT_SPEED
*
1
)
# 增加光速天体到天体集合
# 增加光速天体到天体集合
bodies
.
append
(
light_
body
)
bodies
.
append
(
light_
ship
)
# 运行前指定bodies、light_body并订阅事件
# 运行前指定bodies、light_body并订阅事件
init
.
light_
body
=
light_body
init
.
light_
ship
=
light_ship
init
.
bodies
=
bodies
init
.
bodies
=
bodies
init
.
event_subscription
()
init
.
event_subscription
()
...
...
sim_scenes/solar_system/speed_of_light_init.py
浏览文件 @
6b46c28c
...
@@ -33,35 +33,42 @@ class SpeedOfLightInit:
...
@@ -33,35 +33,42 @@ class SpeedOfLightInit:
self
.
arrived_info
=
""
self
.
arrived_info
=
""
self
.
__camera_follow_light
=
camera_follow_light
self
.
__camera_follow_light
=
camera_follow_light
self
.
__light_
body
=
None
self
.
__light_
ship
=
None
self
.
__bodies
=
None
self
.
__bodies
=
None
self
.
view_closely
=
False
self
.
view_closely
=
False
if
self
.
__camera_follow_light
in
[
"SideView"
,
"SideViewActualSize"
]:
if
self
.
__camera_follow_light
in
[
"SideView"
]:
# 摄像机位置 = 前-后+、上+下-、左-右+、
# 摄像机位置 = 前-后+、上+下-、左-右+、
self
.
camera_position
=
(
AU
,
0
,
0
)
self
.
camera_position
=
(
AU
/
5
,
0
,
0
)
self
.
show_trail
=
True
self
.
show_trail
=
True
self
.
light_size_scale
=
1e3
self
.
light_size_scale
=
2e6
self
.
light_init_position
=
[
AU
/
3
,
0
,
0
]
self
.
light_init_position
=
[
AU
,
0
,
0
]
elif
self
.
__camera_follow_light
in
[
"SideViewActualSize"
]:
# 摄像机位置 = 前-后+、上+下-、左-右+、
# self.camera_position = (0, AU, 0)
self
.
show_trail
=
True
self
.
light_size_scale
=
2e6
self
.
light_init_position
=
[
AU
,
0
,
0
]
elif
self
.
__camera_follow_light
==
"ForwardView"
:
elif
self
.
__camera_follow_light
==
"ForwardView"
:
# 摄像机位置 = 左-右+、上+下-、前+后-
# 摄像机位置 = 左-右+、前+后-、上-下+
self
.
camera_position
=
(
0
,
AU
/
10
,
-
AU
)
# self.camera_position = (0, AU / 10, -AU)
self
.
camera_position
=
(
0
,
-
AU
/
25
,
-
AU
/
50
)
self
.
show_trail
=
True
self
.
show_trail
=
True
self
.
light_size_scale
=
1e2
self
.
light_size_scale
=
2e6
self
.
light_init_position
=
[
AU
/
12
,
0
,
0
]
self
.
light_init_position
=
[
AU
/
12
,
0
,
0
]
else
:
else
:
# 摄像机位置 = 左-右+、上+下-、前+后-
# 摄像机位置 = 左-右+、上+下-、前+后-
self
.
camera_position
=
(
0
,
AU
,
-
6
*
AU
)
self
.
camera_position
=
(
0
,
AU
,
-
6
*
AU
)
self
.
show_trail
=
True
self
.
show_trail
=
True
self
.
light_size_scale
=
2e3
self
.
light_size_scale
=
1e7
self
.
light_init_position
=
[
AU
/
3
,
0
,
0
]
self
.
light_init_position
=
[
AU
/
3
,
0
,
0
]
@
property
@
property
def
light_
body
(
self
):
def
light_
ship
(
self
):
return
self
.
__light_
body
return
self
.
__light_
ship
@
light_
body
.
setter
@
light_
ship
.
setter
def
light_
body
(
self
,
value
):
def
light_
ship
(
self
,
value
):
self
.
__light_
body
=
value
self
.
__light_
ship
=
value
@
property
@
property
def
bodies
(
self
):
def
bodies
(
self
):
...
@@ -73,10 +80,10 @@ class SpeedOfLightInit:
...
@@ -73,10 +80,10 @@ class SpeedOfLightInit:
if
self
.
__camera_follow_light
==
"SideViewActualSize"
:
if
self
.
__camera_follow_light
==
"SideViewActualSize"
:
# TODO: 将天体的大小不进行缩放
# TODO: 将天体的大小不进行缩放
for
body
in
self
.
__bodies
:
for
body
in
self
.
__bodies
:
if
body
is
self
.
light_
body
:
if
body
is
self
.
light_
ship
:
continue
continue
body
.
size_scale
=
1
body
.
size_scale
=
1
self
.
camera_position
=
[
-
self
.
light_init_position
[
0
]
/
1.
3
5
,
0
,
0
]
self
.
camera_position
=
[
-
self
.
light_init_position
[
0
]
/
1.
00
5
,
0
,
0
]
self
.
view_closely
=
True
self
.
view_closely
=
True
def
on_reset
(
self
):
def
on_reset
(
self
):
...
@@ -97,7 +104,7 @@ class SpeedOfLightInit:
...
@@ -97,7 +104,7 @@ class SpeedOfLightInit:
订阅事件
订阅事件
@return:
@return:
"""
"""
if
self
.
light_
body
is
None
:
if
self
.
light_
ship
is
None
:
raise
Exception
(
"请指定 SpeedOfLightInit.light_body"
)
raise
Exception
(
"请指定 SpeedOfLightInit.light_body"
)
if
self
.
bodies
is
None
:
if
self
.
bodies
is
None
:
...
@@ -136,14 +143,26 @@ class SpeedOfLightInit:
...
@@ -136,14 +143,26 @@ class SpeedOfLightInit:
self
.
text_panel
=
create_text_panel
()
self
.
text_panel
=
create_text_panel
()
self
.
text_panel
.
text
=
self
.
arrived_info
.
replace
(
"${distance}"
,
"0 AU"
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
replace
(
"${distance}"
,
"0 AU"
)
if
self
.
__camera_follow_light
in
[
"SideView"
,
"SideViewActualSize"
]:
self
.
light_ship
.
planet
.
rotation_x
=
90
camera
.
parent
=
self
.
light_body
.
planet
if
self
.
__camera_follow_light
in
[
"SideView"
]:
camera
.
rotation_z
=
-
90
camera
.
rotation_y
=
-
85
elif
self
.
__camera_follow_light
in
[
"ForwardView"
]:
camera
.
rotation_x
=
-
75
elif
self
.
__camera_follow_light
in
[
"SideViewActualSize"
]:
self
.
light_ship
.
planet
.
rotation_x
=
0
# camera.rotation_z = -90
camera
.
rotation_y
=
-
85
camera
.
rotation_y
=
-
85
if
self
.
__camera_follow_light
in
[
"SideView"
,
"SideViewActualSize"
]:
camera
.
parent
=
self
.
light_ship
.
planet
elif
self
.
__camera_follow_light
==
"ForwardView"
:
elif
self
.
__camera_follow_light
==
"ForwardView"
:
# self.light_body.planet.enabled = False
# self.light_body.planet.enabled = False
camera
.
parent
=
self
.
light_
body
.
planet
camera
.
parent
=
self
.
light_
ship
.
planet
self
.
light_
body
.
planet
.
input
=
self
.
light_body_input
self
.
light_
ship
.
planet
.
input
=
self
.
light_body_input
camera
.
rotation_y
=
-
15
#
camera.rotation_y = -15
if
hasattr
(
camera
,
"sky"
):
if
hasattr
(
camera
,
"sky"
):
# 摄像机跟随地球后,需要对深空背景进行调整,否则看到的是黑色背景
# 摄像机跟随地球后,需要对深空背景进行调整,否则看到的是黑色背景
camera
.
sky
.
scale
=
800
camera
.
sky
.
scale
=
800
...
@@ -151,7 +170,7 @@ class SpeedOfLightInit:
...
@@ -151,7 +170,7 @@ class SpeedOfLightInit:
camera
.
clip_plane_far
=
1000000
camera
.
clip_plane_far
=
1000000
# 取消订阅(防止 光体 的大小进行变化影响摄像机的视角)
# 取消订阅(防止 光体 的大小进行变化影响摄像机的视角)
UrsinaEvent
.
on_body_size_changed_unsubscription
(
self
.
light_
body
.
planet
.
change_body_scale
)
UrsinaEvent
.
on_body_size_changed_unsubscription
(
self
.
light_
ship
.
planet
.
change_body_scale
)
# def on_body_size(self):
# def on_body_size(self):
# self.light_body.planet.scale = self.light_body.planet_scale
# self.light_body.planet.scale = self.light_body.planet_scale
...
@@ -201,7 +220,7 @@ class SpeedOfLightInit:
...
@@ -201,7 +220,7 @@ class SpeedOfLightInit:
run_speed_maps
=
smooth_speed_transition
(
run_speed_maps
)
run_speed_maps
=
smooth_speed_transition
(
run_speed_maps
)
self
.
run_speed_maps
=
run_speed_maps
self
.
run_speed_maps
=
run_speed_maps
light_distance
=
self
.
light_
body
.
position
[
2
]
light_distance
=
self
.
light_
ship
.
position
[
2
]
current_idx
=
0
current_idx
=
0
for
i
,
m
in
enumerate
(
self
.
run_speed_maps
):
for
i
,
m
in
enumerate
(
self
.
run_speed_maps
):
if
i
==
0
:
if
i
==
0
:
...
@@ -246,19 +265,19 @@ class SpeedOfLightInit:
...
@@ -246,19 +265,19 @@ class SpeedOfLightInit:
self
.
auto_run_speed
()
self
.
auto_run_speed
()
for
body
in
self
.
bodies
:
for
body
in
self
.
bodies
:
if
body
is
self
.
light_
body
or
isinstance
(
body
,
Sun
)
\
if
body
is
self
.
light_
ship
or
isinstance
(
body
,
Sun
)
\
or
body
in
self
.
arrived_bodies
or
isinstance
(
body
,
Asteroids
):
or
body
in
self
.
arrived_bodies
or
isinstance
(
body
,
Asteroids
):
# 对于光速天体、太阳、小行星群、“已到达天体列表”中的天体无需计算
# 对于光速天体、太阳、小行星群、“已到达天体列表”中的天体无需计算
continue
continue
# 计算判断,如果光速天体距离到达了某个天体,就记录到“已到达天体列表”中
# 计算判断,如果光速天体距离到达了某个天体,就记录到“已到达天体列表”中
if
self
.
light_
body
.
position
[
2
]
>=
body
.
position
[
2
]:
if
self
.
light_
ship
.
position
[
2
]
>=
body
.
position
[
2
]:
self
.
arrived_bodies
.
append
(
body
)
self
.
arrived_bodies
.
append
(
body
)
if
self
.
text_panel
is
not
None
:
if
self
.
text_panel
is
not
None
:
self
.
arrived_info
+=
f
"[
{
time_data
.
time_text
}
]
\t
到达
\t
[
{
body
.
name
}
]
\n\n
"
self
.
arrived_info
+=
f
"[
{
time_data
.
time_text
}
]
\t
到达
\t
[
{
body
.
name
}
]
\n\n
"
# distance = round(self.light_body.position[2] / AU, 4)
# distance = round(self.light_body.position[2] / AU, 4)
# # print("浮点数保留两位小数,宽5位,不足补0:%05.5f " % 2.222)
# # print("浮点数保留两位小数,宽5位,不足补0:%05.5f " % 2.222)
# self.text_panel.text = self.arrived_info.replace("${distance}", "%.4f AU" % distance)
# self.text_panel.text = self.arrived_info.replace("${distance}", "%.4f AU" % distance)
print
(
f
"[
{
time_data
.
time_text
}
] 到达 [
{
body
.
name
}
]
{
round
(
self
.
light_
body
.
position
[
2
]
/
AU
,
4
)
}
AU"
)
print
(
f
"[
{
time_data
.
time_text
}
] 到达 [
{
body
.
name
}
]
{
round
(
self
.
light_
ship
.
position
[
2
]
/
AU
,
4
)
}
AU"
)
return
return
if
not
hasattr
(
self
,
"last_time"
):
if
not
hasattr
(
self
,
"last_time"
):
...
@@ -269,5 +288,5 @@ class SpeedOfLightInit:
...
@@ -269,5 +288,5 @@ class SpeedOfLightInit:
# self.text_panel.text = self.arrived_info.replace("${distance}", "%.4f AU" % distance)
# self.text_panel.text = self.arrived_info.replace("${distance}", "%.4f AU" % distance)
self
.
last_time
=
datetime
.
datetime
.
now
()
self
.
last_time
=
datetime
.
datetime
.
now
()
distance
=
round
(
self
.
light_body
.
position
[
2
]
/
AU
,
4
)
distance
=
round
(
self
.
light_ship
.
position
[
2
]
/
AU
,
4
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
replace
(
"${distance}"
,
"%.4f AU"
%
distance
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
replace
(
"${distance}"
,
"%.4f AU"
%
distance
)
\ No newline at end of file
simulators/ursina/entities/planet.py
浏览文件 @
6b46c28c
...
@@ -74,7 +74,11 @@ class Planet(Entity):
...
@@ -74,7 +74,11 @@ class Planet(Entity):
model
=
self
.
body
.
model
model
=
self
.
body
.
model
else
:
else
:
model
=
self
.
body
.
model
model
=
self
.
body
.
model
rotation
=
(
0
,
0
,
0
)
if
hasattr
(
self
.
body
,
"rotation"
):
if
self
.
body
.
rotation
is
None
:
rotation
=
(
0
,
0
,
0
)
else
:
rotation
=
tuple
(
self
.
body
.
rotation
)
else
:
else
:
model
=
create_sphere
(
0.5
,
subdivisions
)
model
=
create_sphere
(
0.5
,
subdivisions
)
rotation
=
(
0
,
0
,
0
)
rotation
=
(
0
,
0
,
0
)
...
...
textures/space_ship.png
0 → 100644
浏览文件 @
6b46c28c
5.7 MB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录