Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
太阳系三体模拟器
提交
74450e58
太阳系三体模拟器
项目概览
Python_超人
/
太阳系三体模拟器
通知
1471
Star
137
Fork
134
代码
文件
提交
分支
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看板
提交
74450e58
编写于
3月 02, 2023
作者:
M
march3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
太阳系三体模拟器
上级
3316b505
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
13 deletion
+43
-13
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+23
-7
simulators/views/ursina_view.py
simulators/views/ursina_view.py
+20
-6
未找到文件。
simulators/ursina_simulator.py
浏览文件 @
74450e58
...
...
@@ -93,14 +93,16 @@ from simulators.views.ursina_view import UrsinaView, UrsinaPlayer
from
simulators.simulator
import
Simulator
from
common.system
import
System
import
time
import
datetime
ursina_views
=
[]
player
=
None
class
UrsinaSimulator
(
Simulator
):
def
__init__
(
self
,
bodies_sys
:
System
):
self
.
app
=
Ursina
()
self
.
ursina_views
=
[]
window
.
color
=
color
.
black
super
().
__init__
(
bodies_sys
,
UrsinaView
)
...
...
@@ -112,17 +114,31 @@ class UrsinaSimulator(Simulator):
# pos = tuple(body.position)
# ursina_view = UrsinaView(body)
view
.
update
()
ursina_views
.
append
(
view
)
self
.
ursina_views
.
append
(
view
)
# planets.append(newPlanet)
# x += cp[i] * 10
def
check_elapsed_time
(
self
):
"""检查时间间隔是否已过"""
now
=
datetime
.
datetime
.
now
()
elapsed_time
=
now
-
self
.
last_time
return
elapsed_time
>=
self
.
interval
def
check_and_evolve
(
self
):
if
self
.
check_elapsed_time
():
super
().
evolve
(
self
.
evolve_dt
)
def
run
(
self
,
dt
,
**
kwargs
):
self
.
evolve_dt
=
dt
# 设定时间间隔为1秒
self
.
interval
=
datetime
.
timedelta
(
seconds
=
1
)
self
.
last_time
=
datetime
.
datetime
.
now
()
self
.
app
.
run
()
if
__name__
==
'__main__'
:
from
bodies
import
Sun
,
Earth
from
common.consts
import
SECONDS_PER_WEEK
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
"""
3个太阳、1个地球
...
...
@@ -151,16 +167,16 @@ if __name__ == '__main__':
body_sys
=
System
(
bodies
)
simulator
=
UrsinaSimulator
(
body_sys
)
player
=
UrsinaPlayer
((
0
,
-
849597870.700
,
0
)
)
player
=
UrsinaPlayer
((
0
,
0
,
849597870.700
),
simulator
.
ursina_views
)
def
update
():
# print('OK')
global
ursina_views
,
player
for
ursina_view
in
ursina_views
:
for
ursina_view
in
simulator
.
ursina_views
:
simulator
.
check_and_evolve
()
ursina_view
.
update
()
# ursina_view.entity.turn(ursina_view.entity.angle)
player
.
_update
()
simulator
.
run
(
SECONDS_PER_
WEEK
)
simulator
.
run
(
SECONDS_PER_
DAY
)
simulators/views/ursina_view.py
浏览文件 @
74450e58
...
...
@@ -7,7 +7,7 @@
# python_version :3.8
# ==============================================================================
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
from
ursina
import
Ursina
,
window
,
Entity
,
camera
,
color
,
mouse
,
Vec2
,
Vec3
,
load_texture
,
held_keys
from
ursina
import
Ursina
,
window
,
Entity
,
SmoothFollow
,
camera
,
color
,
mouse
,
Vec2
,
Vec3
,
load_texture
,
held_keys
from
math
import
sin
,
cos
,
radians
from
ursina.prefabs.first_person_controller
import
FirstPersonController
import
sys
...
...
@@ -20,21 +20,35 @@ import numpy as np
from
math
import
sin
,
cos
,
radians
import
os
SCALE_FACTOR
=
1e-
6
SCALE_FACTOR
=
1e-
7
class
UrsinaPlayer
(
FirstPersonController
):
def
__init__
(
self
,
position
):
def
__init__
(
self
,
position
,
targets
=
None
):
# global planets
super
().
__init__
()
# pos = planets[0].position
camera
.
fov
=
100
if
targets
is
not
None
:
# planets = []
# targets = [view.planet.parent for view in targets]
targets_parent
=
Entity
()
for
view
in
targets
:
view
.
planet
.
parent
=
targets_parent
# planets.append(view.planet)
camera
.
add_script
(
SmoothFollow
(
targets_parent
,
offset
=
(
0
,
8
,
-
20
)))
pos
=
np
.
array
(
position
)
*
SCALE_FACTOR
self
.
position
=
Vec3
(
pos
[
0
],
pos
[
1
],
pos
[
2
])
# self.position = Vec3(pos[0], pos[1], pos[2])
# 将摄像机位置设置为 x=0、y=1、z=0 的位置
# camera.position = Vec3(pos[0], pos[1], pos[2])
self
.
position
=
Vec3
(
pos
[
0
],
pos
[
1
],
pos
[
2
])
# 将摄像机的观察角度绕 x 轴旋转 45 度,绕 y 轴旋转 0 度,绕 z 轴旋转 0 度
camera
.
rotation
=
Vec3
(
45
,
90
,
0
)
self
.
gravity
=
0
self
.
vspeed
=
40
self
.
speed
=
100
self
.
vspeed
=
40
00
self
.
speed
=
100
00
self
.
mouse_sensitivity
=
Vec2
(
160
,
160
)
self
.
on_enable
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录