Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
太阳系三体模拟器
提交
560fc950
太阳系三体模拟器
项目概览
Python_超人
/
太阳系三体模拟器
通知
1094
Star
131
Fork
128
代码
文件
提交
分支
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看板
提交
560fc950
编写于
3月 17, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
太阳系三体模拟器
上级
47cb71fb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
5 deletion
+61
-5
scenes/func.py
scenes/func.py
+24
-1
simulators/ursina/ursina_ui.py
simulators/ursina/ursina_ui.py
+29
-4
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+8
-0
未找到文件。
scenes/func.py
浏览文件 @
560fc950
...
...
@@ -66,12 +66,35 @@ def ursina_run(bodies,
"""
from
simulators.ursina_simulator
import
UrsinaSimulator
,
UrsinaPlayer
from
ursina
import
application
,
Sequence
from
ursina
import
application
,
Sequence
,
camera
,
held_keys
,
time
,
clamp
,
Entity
,
Text
body_sys
=
System
(
bodies
)
simulator
=
UrsinaSimulator
(
body_sys
)
player
=
UrsinaPlayer
(
position
,
simulator
.
ursina_views
)
# # 创建一个实体(在屏幕中央)和一个摄像机
# TODO: 未使用
# entity = Entity(model='cube', position=(0, 0, 5), scale=2)
# camera = Camera()
#
# # 设置初始的 FOV 值(默认值为 90)
# camera.fov = 60
#
# # 创建一个用于显示当前 FOV 值的文本
# fov_text = Text(text=f'FOV: {camera.fov}', position=(-0.5, 0.4), scale=2)
# # 每一帧更新摄像机 FOV 值
# def update():
# # 通过鼠标滚轮来调整 FOV 值
# camera.fov -= held_keys['scroll'] * 10 * time.dt
# # 限制 FOV 值的范围(1 到 120 之间)
# camera.fov = clamp(camera.fov, 1, 120)
# # 更新文本内容
# fov_text.text = f'FOV: {camera.fov:.2f}' # 保留两位小数
#
# # 将摄像机移到实体旁边,并对着它
# camera.position = entity.position + (0, 0, -5)
# camera.look_at(entity.position)
def
callback_update
():
for
ursina_view
in
simulator
.
ursina_views
:
simulator
.
check_and_evolve
()
...
...
simulators/ursina/ursina_ui.py
浏览文件 @
560fc950
...
...
@@ -7,9 +7,10 @@
# python_version :3.8
# ==============================================================================
from
ursina
import
Ursina
,
window
,
Entity
,
Grid
,
Mesh
,
camera
,
Text
,
application
,
color
,
mouse
,
Vec2
,
Vec3
,
\
load_texture
,
held_keys
,
Button
,
ButtonList
,
destroy
load_texture
,
held_keys
,
Button
,
ButtonList
,
destroy
,
scene
,
distance
from
ursina.prefabs.first_person_controller
import
FirstPersonController
from
common.consts
import
AU
from
simulators.ursina.ui_component
import
UiSlider
,
SwithButton
,
UiButton
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
...
...
@@ -128,23 +129,45 @@ class UrsinaUI:
def
bodies_button_list_click
(
self
,
item
):
if
item
is
not
None
:
print
(
"select->"
,
item
)
# TODO: 先找到位置,确定摄像机的位置
# print("select->", item)
# UrsinaConfig.SCALE_FACTOR
x
=
item
.
planet
.
scale_x
*
10
camera
.
position
=
item
.
planet
.
position
+
Vec3
(
-
x
,
0
,
0
)
camera
.
look_at
(
item
.
planet
)
camera
.
rotation
=
(
0
,
90
,
0
)
# camera.forward = (1, 0, 0) # 设置相机的方向向量为x轴方向
destroy
(
self
.
bodies_button_list
)
# my_entity = Entity(model='cube', color=color.red, position=(0, 1, 5))
#
# # 获取当前摄像机
# camera = scene.camera
#
# # 计算 Entity 和摄像机之间的距离
# distance_to_entity = distance(my_entity, camera)
#
# print('距离:', distance_to_entity)
def
on_searching_bodies_click
(
self
):
results
=
UrsinaEvent
.
on_searching_bodies
()
if
len
(
results
)
>
0
:
sub_name
,
bodies
=
results
[
0
]
# print(results[0])
button_dict
=
{
"[关闭]"
:
lambda
:
self
.
bodies_button_list_click
(
None
)}
camera
=
scene
.
camera
for
body
in
bodies
:
def
callback_action
(
b
=
body
):
self
.
bodies_button_list_click
(
b
)
button_dict
[
body
.
name
]
=
callback_action
distance_to_entity
=
distance
(
body
.
planet
,
camera
)
d
=
distance_to_entity
/
UrsinaConfig
.
SCALE_FACTOR
/
AU
name
=
f
"
{
body
.
name
}
\t
距离:
{
d
:.
4
f
}
天文单位"
button_dict
[
name
]
=
callback_action
if
hasattr
(
self
,
"bodies_button_list"
):
destroy
(
self
.
bodies_button_list
)
self
.
bodies_button_list
=
ButtonList
(
button_dict
,
font
=
UrsinaConfig
.
CN_FONT
,
button_height
=
1.5
)
# self.bodies_button_list.input = self.bodies_button_list_input
...
...
@@ -205,6 +228,8 @@ class UrsinaUI:
# print(key)
elif
key
==
'space'
:
self
.
wp
.
enabled
=
not
self
.
wp
.
enabled
elif
key
==
'left mouse down'
:
print
(
key
)
# application.paused = not application.paused # Pause/unpause the game.
# elif key == 'tab':
# # application.time_scale 属性控制游戏时间流逝的速度。
...
...
simulators/ursina_simulator.py
浏览文件 @
560fc950
...
...
@@ -155,6 +155,8 @@ class UrsinaSimulator(Simulator):
return
lights
def
run
(
self
,
dt
,
**
kwargs
):
window
.
title
=
'宇宙模拟器'
# 设定时间间隔为0.01秒
interval
=
0.01
self
.
evolve_dt
=
dt
*
interval
...
...
@@ -181,6 +183,12 @@ class UrsinaSimulator(Simulator):
if
cosmic_bg
is
not
None
and
os
.
path
.
exists
(
cosmic_bg
):
self
.
cosmic_background
(
cosmic_bg
)
# 设置 camera 的裁剪面和位置
camera
.
clip_plane_near
=
0.1
# camera.clip_plane_far = 1000
# camera.position = (0, 10, -20)
# camera.rotation_x = -30
ui
=
UrsinaUI
()
EditorCamera
(
ignore_paused
=
True
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录