Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
f0602b49
宇宙模拟器
项目概览
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看板
提交
f0602b49
编写于
8月 27, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
92b65ae6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
113 addition
and
36 deletion
+113
-36
sim_scenes/solar_system/earth_moon_reality.py
sim_scenes/solar_system/earth_moon_reality.py
+101
-35
simulators/ursina/entities/planet.py
simulators/ursina/entities/planet.py
+12
-1
未找到文件。
sim_scenes/solar_system/earth_moon_reality.py
浏览文件 @
f0602b49
...
...
@@ -14,8 +14,9 @@ from bodies import Sun, Mercury, Venus, Earth, Mars, Asteroids, Jupiter, Saturn,
from
common.celestial_data_service
import
get_body_posvel
,
recalc_moon_position
,
calc_solar_acceleration
,
\
set_solar_system_celestial_position
,
set_earth_rotation
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
AU
from
sim_scenes.func
import
ursina_run
,
camera_look_at
from
sim_scenes.func
import
ursina_run
,
camera_look_at
,
create_text_panel
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.entities.entity_utils
import
clear_trails
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
...
...
@@ -28,9 +29,7 @@ class SolarSystemRealitySim:
@param debug_mode: 是否为调试模式
"""
self
.
show_asteroids
=
False
self
.
clock_position_center
=
False
self
.
show_earth_clouds
=
False
self
.
debug_mode
=
False
self
.
recalc_moon_pos
=
True
...
...
@@ -44,15 +43,15 @@ class SolarSystemRealitySim:
# 地月缩放比例
# 为了更好的展示效果,需要对月球的位置重新计算(使得地月距离放大,月球相对地球方向不变),重新计算位置后,地球和月球可以放大1000倍以上
if
self
.
recalc_moon_pos
:
# 重新计算月球位置
self
.
earth_size_scale
=
10e3
if
self
.
debug_mode
else
1e3
self
.
sun_size_scale
=
0.04e2
if
self
.
debug_mode
else
0.4e2
self
.
moon_size_scale
=
2e3
else
:
# 不重新计算,则地月的距离相对整个太阳系会非常近,因此,月球只放大了30倍
self
.
earth_size_scale
=
2.5e1
self
.
moon_size_scale
=
5e1
self
.
sun_size_scale
=
1e1
#
if self.recalc_moon_pos: # 重新计算月球位置
#
self.earth_size_scale = 10e3 if self.debug_mode else 1e3
#
self.sun_size_scale = 0.04e2 if self.debug_mode else 0.4e2
#
self.moon_size_scale = 2e3
#
else:
#
# 不重新计算,则地月的距离相对整个太阳系会非常近,因此,月球只放大了30倍
#
self.earth_size_scale = 2.5e1
#
self.moon_size_scale = 5e1
#
self.sun_size_scale = 1e1
self
.
earth_size_scale
=
1
self
.
moon_size_scale
=
1
...
...
@@ -70,20 +69,22 @@ class SolarSystemRealitySim:
self
.
earth_camera
.
camera_init_val
=
0
self
.
moon
=
Moon
(
name
=
"月球"
,
size_scale
=
self
.
moon_size_scale
,
rotation_speed
=
0.4065
)
# 月球
self
.
sun
.
show_trail
=
False
self
.
earth
.
trail_scale_factor
=
0.2
self
.
moon
.
trail_scale_factor
=
0.3
# 所有天体
self
.
bodies
=
[
self
.
sun
,
self
.
earth
,
self
.
earth_camera
,
self
.
moon
]
def
init_earth
(
self
):
"""
初始化地球
@return:
"""
# 让地球显示自转轴线
self
.
earth
.
rotate_axis_color
=
(
255
,
255
,
50
)
# 如果为调试模式,则太阳光对地球无效,方便查看
if
self
.
debug_mode
:
self
.
earth
.
set_light_disable
(
True
)
#
def init_earth(self):
#
"""
#
初始化地球
#
@return:
#
"""
#
# 让地球显示自转轴线
#
self.earth.rotate_axis_color = (255, 255, 50)
#
# 如果为调试模式,则太阳光对地球无效,方便查看
#
if self.debug_mode:
#
self.earth.set_light_disable(True)
def
show_clock
(
self
,
dt
):
"""
...
...
@@ -119,10 +120,15 @@ class SolarSystemRealitySim:
"""
# 运行前触发
self
.
text_panel
=
create_text_panel
()
self
.
text_panel
.
text
=
"太阳缩放:1.0
\n
地球缩放:1.0
\n
月球缩放:1.0"
# camera.rotation_z = -20
# if self.debug_mode:
# camera.fov = 30 # 调试时,拉近摄像机距离
# camera.fov = 1
# camera.fov = 40
camera
.
clip_plane_near
=
10
# camera.clip_plane_far = 1000000
camera
.
parent
=
self
.
earth_camera
.
planet
# camera.update = self.camera_update
...
...
@@ -138,6 +144,7 @@ class SolarSystemRealitySim:
# 设置后,可以调整鼠标键盘的控制速度
application
.
time_scale
=
2
#
# def camera_update(self):
# camera.x = -50 # 100
...
...
@@ -147,24 +154,83 @@ class SolarSystemRealitySim:
# # 摄像机看向地球
# camera_look_at(self.earth)
def
body_show
(
self
,
body
):
body
.
planet
.
enabled
=
True
body
.
show_trail
=
True
def
body_hide
(
self
,
body
):
body
.
planet
.
enabled
=
False
body
.
show_trail
=
False
# clear_trails(body.planet)
def
body_scale
(
self
,
body
,
value
):
body
.
planet
.
init_scale
*=
value
if
hasattr
(
body
.
planet
.
main_entity
,
"trail_scale"
):
body
.
planet
.
main_entity
.
trail_scale
*=
value
def
set_camera_pos
(
self
,
time_data
:
TimeData
):
# if time_data.total_days > 120:
# self.earth_camera.camera_init_val = +3000000
# elif time_data.total_days > 90:
# self.earth_camera.camera_init_val = +1200000
# elif time_data.total_days > 90:
# self.earth_camera.camera_init_val += 600000
# elif time_data.total_days > 60:
# self.earth_camera.camera_init_val += 100000
if
time_data
.
total_days
>
120
:
self
.
earth_camera
.
camera_init_val
+=
300000
elif
time_data
.
total_days
>
90
:
self
.
earth_camera
.
camera_init_val
+=
60000
elif
time_data
.
total_days
>
90
:
self
.
earth_camera
.
camera_init_val
+=
20000
elif
time_data
.
total_days
>
30
:
self
.
earth_camera
.
camera_init_val
+=
18000
elif
time_data
.
total_days
>
10
:
self
.
earth_camera
.
camera_init_val
+=
4000
elif
time_data
.
total_days
>
2
:
self
.
earth_camera
.
camera_init_val
+=
500
# if UrsinaConfig.trail_factor < 50:
# self.body_scale(1.002)
if
time_data
.
total_days
<
5
:
self
.
earth
.
show_trail
=
False
self
.
moon
.
show_trail
=
False
if
30
>
time_data
.
total_days
>
5
:
self
.
earth
.
show_trail
=
True
self
.
moon
.
show_trail
=
True
self
.
body_scale
(
self
.
moon
,
1.0025
)
self
.
body_scale
(
self
.
earth
,
1.002
)
elif
60
>
time_data
.
total_days
>
30
:
# self.body_hide(self.moon)
self
.
body_scale
(
self
.
moon
,
1.002
)
self
.
body_scale
(
self
.
earth
,
1.002
)
self
.
body_scale
(
self
.
sun
,
1.002
)
elif
150
>
time_data
.
total_days
>
60
:
self
.
earth
.
planet
.
init_scale
=
0.01
self
.
earth
.
planet
.
main_entity
.
trail_scale
=
0.03
# self.body_scale(self.earth, 0.02)
# self.body_hide(self.earth)
# self.earth.planet.init_scale = 0.01
# self.body_show(self.moon)
# self.body_scale(1.0015)
# self.sun_scale(1.0015)
# else:
# self.body_scale(1.002)
# self.sun_scale(1.0005)
print
(
"%s,%s"
%
(
round
(
self
.
moon
.
planet
.
body_scale
,
1
),
time_data
.
total_days
))
# camera.x = -300 # 100
# camera.z = 200
# camera.y += self.earth_camera.camera_init_val * UrsinaConfig.SCALE_FACTOR
camera
.
x
=
-
6
0
# 100
# camera.x = -8
0 # 100
# camera.z = -10
camera
.
y
=
50
dis_au
=
round
(
camera
.
y
/
UrsinaConfig
.
SCALE_FACTOR
/
AU
,
2
)
if
dis_au
<
400
:
if
self
.
earth_camera
.
camera_init_val
>
0
:
camera
.
y
+=
self
.
earth_camera
.
camera_init_val
*
UrsinaConfig
.
SCALE_FACTOR
else
:
camera
.
y
=
80
self
.
text_panel
.
text
=
"太阳大小缩放:%.1f
\n
地球大小缩放:%.1f
\n
月球大小缩放:%.1f
\n
摄像机距地球:%.2f天文单位"
%
\
(
self
.
sun
.
planet
.
body_scale
,
self
.
earth
.
planet
.
body_scale
,
self
.
moon
.
planet
.
body_scale
,
dis_au
)
# UrsinaConfig.trail_factor = 3 * math.sqrt(camera.y / 250)
pass
...
...
@@ -183,7 +249,7 @@ class SolarSystemRealitySim:
# 调整摄像机的位置
self
.
set_camera_pos
(
time_data
)
# 摄像机看向地球
camera_look_at
(
self
.
earth
)
camera_look_at
(
self
.
sun
)
# 显示时钟
self
.
show_clock
(
dt
)
...
...
simulators/ursina/entities/planet.py
浏览文件 @
f0602b49
...
...
@@ -31,6 +31,15 @@ class Planet(Entity):
clear_trails
(
self
)
self
.
body
.
reset
()
@
property
def
init_scale
(
self
):
return
self
.
__init_scale
@
init_scale
.
setter
def
init_scale
(
self
,
val
):
self
.
body_scale
*=
val
/
self
.
__init_scale
self
.
__init_scale
=
val
def
__init__
(
self
,
body_view
:
BodyView
):
self
.
body_view
=
body_view
if
hasattr
(
self
.
body
,
"rotation_speed"
):
...
...
@@ -45,7 +54,9 @@ class Planet(Entity):
else
:
scale
=
self
.
body
.
size_scale
*
UrsinaConfig
.
SCALE_FACTOR
self
.
init_scale
=
scale
self
.
__init_scale
=
scale
self
.
body_scale
=
1.0
if
hasattr
(
body_view
,
"texture"
):
texture
=
load_texture
(
body_view
.
texture
)
# color.white
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录