Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
f5929e9d
宇宙模拟器
项目概览
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看板
提交
f5929e9d
编写于
4月 08, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
24d43dc6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
6 deletion
+14
-6
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+14
-6
未找到文件。
simulators/ursina/entities/body_timer.py
浏览文件 @
f5929e9d
...
@@ -18,12 +18,15 @@ from simulators.ursina.ursina_event import UrsinaEvent
...
@@ -18,12 +18,15 @@ from simulators.ursina.ursina_event import UrsinaEvent
class
BodyTimer
(
Singleton
):
class
BodyTimer
(
Singleton
):
"""
"""
天体计时器
天体计时器,原理就是:
以 BodyTimer 为一个天体在宇宙中运行,以速度 self.velocity_inc 递增。
通过公式: 速度 * 时间 = 距离,获取到累计距离, self.position_sum += self.velocity_inc * dt
最后通过公式: 时间 = 距离 / 速度, 从而得到天体运行了多长时间
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
if
not
hasattr
(
self
,
"inited"
):
if
not
hasattr
(
self
,
"inited"
):
self
.
velocity_inc
=
0.00001
self
.
velocity_inc
=
1e-30
# 理论上数值越小越好,可以使用 1e-300 ,但建议使用:1e-30 #
0.00001
UrsinaEvent
.
on_reset_subscription
(
self
.
reset
)
UrsinaEvent
.
on_reset_subscription
(
self
.
reset
)
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
...
@@ -36,14 +39,19 @@ class BodyTimer(Singleton):
...
@@ -36,14 +39,19 @@ class BodyTimer(Singleton):
pass
pass
def
reset
(
self
):
def
reset
(
self
):
# 累计距离置零
self
.
position_sum
=
0.0
self
.
position_sum
=
0.0
def
calc_time
(
self
,
dt
):
def
calc_time
(
self
,
dt
):
if
not
hasattr
(
self
,
"position_sum"
):
if
not
hasattr
(
self
,
"position_sum"
):
# 累计距离置零
self
.
position_sum
=
0.0
self
.
position_sum
=
0.0
# 通过公式: 速度 * 时间 = 距离,获取到累计距离
self
.
position_sum
+=
self
.
velocity_inc
*
dt
self
.
position_sum
+=
self
.
velocity_inc
*
dt
# 距离(km) / 速度(km/s) = 时间(s)
# 距离(km) / 速度(km/s) = 时间(s)
seconds
=
round
(
self
.
position_sum
/
self
.
velocity_inc
)
seconds
=
round
(
self
.
position_sum
/
self
.
velocity_inc
)
# 获取到 seconds 后,通过下面的计算得到时分秒、年、天
hours
,
remainder
=
divmod
(
seconds
,
3600
)
hours
,
remainder
=
divmod
(
seconds
,
3600
)
minutes
,
seconds
=
divmod
(
remainder
,
60
)
minutes
,
seconds
=
divmod
(
remainder
,
60
)
days
,
hours
=
divmod
(
hours
,
24
)
days
,
hours
=
divmod
(
hours
,
24
)
...
@@ -52,14 +60,14 @@ class BodyTimer(Singleton):
...
@@ -52,14 +60,14 @@ class BodyTimer(Singleton):
if
days
>
1
:
if
days
>
1
:
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
if
days
>=
20
or
years
>=
1
:
if
days
>=
20
or
years
>=
1
:
self
.
text
=
f
'
{
int
(
years
)
}
年
{
s_days
}
天'
time_
text
=
f
'
{
int
(
years
)
}
年
{
s_days
}
天'
else
:
else
:
self
.
text
=
f
'
{
int
(
days
)
}
天
{
int
(
hours
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
time_
text
=
f
'
{
int
(
days
)
}
天
{
int
(
hours
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
else
:
else
:
self
.
text
=
f
'
{
int
(
hours
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
time_
text
=
f
'
{
int
(
hours
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
# print(self.text)
# print(self.text)
UrsinaEvent
.
on_timer_changed
(
self
.
text
,
(
years
,
days
,
hours
,
minutes
,
seconds
))
UrsinaEvent
.
on_timer_changed
(
time_
text
,
(
years
,
days
,
hours
,
minutes
,
seconds
))
def
ignore_gravity
(
self
,
body
):
def
ignore_gravity
(
self
,
body
):
return
True
return
True
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录