Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
11659848
宇宙模拟器
项目概览
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看板
提交
11659848
编写于
4月 02, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
adbe521e
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
43 addition
and
152 deletion
+43
-152
sim_scenes/solar_system/earth_moon6.py
sim_scenes/solar_system/earth_moon6.py
+35
-0
simulators/ursina/entities/body_trail.py
simulators/ursina/entities/body_trail.py
+1
-92
simulators/ursina/entities/entity_utils.py
simulators/ursina/entities/entity_utils.py
+0
-57
simulators/ursina/entities/planet.py
simulators/ursina/entities/planet.py
+1
-1
simulators/ursina/ursina_mesh.py
simulators/ursina/ursina_mesh.py
+1
-1
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+5
-1
未找到文件。
sim_scenes/solar_system/earth_moon6.py
0 → 100644
浏览文件 @
11659848
# -*- coding:utf-8 -*-
# title :地月场景模拟
# description :地月场景模拟
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Moon
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
bodies.body
import
AU
if
__name__
==
'__main__'
:
"""
地球、6个月球
"""
# 地球的Y方向初始速度
EARTH_INIT_VELOCITY
=
0
# 地球在中心位置
e
=
Earth
(
init_position
=
[
0
,
0
,
0
],
texture
=
"earth_hd.jpg"
,
init_velocity
=
[
0
,
0
,
0
])
bodies
=
[
e
,
Moon
(
init_position
=
[
e
.
diameter
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球前面
Moon
(
init_position
=
[
-
e
.
diameter
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球后面
Moon
(
init_position
=
[
0
,
e
.
diameter
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球左面
Moon
(
init_position
=
[
0
,
-
e
.
diameter
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球右面
Moon
(
init_position
=
[
0
,
0
,
e
.
diameter
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球上面
Moon
(
init_position
=
[
0
,
0
,
-
e
.
diameter
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球下面
]
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
60
,
position
=
(
0
,
0
,
0
),
show_trail
=
True
,
view_closely
=
0.001
)
simulators/ursina/entities/body_trail.py
浏览文件 @
11659848
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
from
ursina
import
Entity
,
Mesh
,
Text
,
color
,
destroy
,
Vec3
from
ursina
import
Entity
,
Mesh
,
Text
,
color
,
destroy
,
Vec3
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_mesh
import
create_arrow_line
from
simulators.ursina.ursina_mesh
import
create_arrow_line
...
@@ -23,12 +22,6 @@ class BodyTrail(Entity):
...
@@ -23,12 +22,6 @@ class BodyTrail(Entity):
)
)
def
input
(
self
,
key
):
def
input
(
self
,
key
):
# if self.hovered:
# if key == 'left mouse down':
# print(f"{self} was clicked!")
# self.text.enabled = True
# elif key == 'left mouse up':
# self.text.enabled = False
if
self
.
hovered
:
if
self
.
hovered
:
if
key
==
'left mouse down'
:
if
key
==
'left mouse down'
:
# print(key, self)
# print(key, self)
...
@@ -41,95 +34,11 @@ class BodyTrail(Entity):
...
@@ -41,95 +34,11 @@ class BodyTrail(Entity):
for
c
in
self
.
children
:
for
c
in
self
.
children
:
destroy
(
c
)
destroy
(
c
)
return
return
# entity_infos = {"velocity": [vel_info, vel_direction, vel_position],
# "acceleration": [acc_info, acc_direction, acc_position]}
vel_info
,
vel_direction
,
vel_position
=
self
.
entity_infos
[
"velocity"
]
vel_info
,
vel_direction
,
vel_position
=
self
.
entity_infos
[
"velocity"
]
acc_info
,
acc_direction
,
acc_position
=
self
.
entity_infos
[
"acceleration"
]
acc_info
,
acc_direction
,
acc_position
=
self
.
entity_infos
[
"acceleration"
]
#
# verts_acc = [(0, 0, 0), tuple(acc_direction)]
# verts_vel = [(0, 0, 0), tuple(vel_direction)]
# acc_arrow = Arrow(parent=self,from_pos=Vec3((0, 0, 0)), to_pos=Vec3(tuple(acc_direction)),color=color.yellow, alpha=0.5)
# acc_arrow.set_light_off()
v_arrow
,
v_line
,
v_text
=
create_arrow_line
((
0
,
0
,
0
),
tuple
(
vel_direction
),
parent
=
self
,
v_arrow
,
v_line
,
v_text
=
create_arrow_line
((
0
,
0
,
0
),
tuple
(
vel_direction
),
parent
=
self
,
label
=
vel_info
,
color
=
color
.
red
,
alpha
=
0.8
,
arrow_scale
=
0.5
)
label
=
vel_info
,
color
=
color
.
red
,
alpha
=
0.8
,
arrow_scale
=
0.5
)
a_arrow
,
a_line
,
a_text
=
create_arrow_line
((
0
,
0
,
0
),
tuple
(
acc_direction
),
parent
=
self
,
a_arrow
,
a_line
,
a_text
=
create_arrow_line
((
0
,
0
,
0
),
tuple
(
acc_direction
),
parent
=
self
,
label
=
acc_info
,
color
=
color
.
yellow
,
alpha
=
0.8
,
arrow_scale
=
0.5
)
label
=
acc_info
,
color
=
color
.
yellow
,
alpha
=
0.8
,
arrow_scale
=
0.5
)
# acc_line = Entity(parent=self, model=Mesh(vertices=verts_acc, mode='line', thickness=3),
# color=color.yellow, alpha=0.5)
# acc_line.set_light_off()
#
# # vel_arrow = Arrow(parent=self,from_pos=Vec3((0, 0, 0)), to_pos=Vec3(tuple(vel_direction)),color=color.red, alpha=0.5)
# # vel_arrow.set_light_off()
#
# vel_line = Entity(parent=self, model=Mesh(vertices=verts_vel, mode='line', thickness=3),
# color=color.red, alpha=0.5)
# vel_line.set_light_off()
#
# vel_text = Text(vel_info, scale=50, billboard=True, parent=self,
# font=UrsinaConfig.CN_FONT, background=False, color=color.red,
# position=vel_position, alpha=0.5)
# vel_text.set_light_off()
#
# acc_text = Text(acc_info, scale=50, billboard=True, parent=self,
# font=UrsinaConfig.CN_FONT, background=False, color=color.yellow,
# position=acc_position, alpha=0.5)
# acc_text.set_light_off()
class
Arrow
(
Entity
):
def
__init__
(
self
,
parent
,
from_pos
=
(
0
,
0
,
0
),
to_pos
=
(
1
,
0
,
0
),
**
kwargs
):
from_pos
=
to_pos
/
2
super
().
__init__
(
parent
=
parent
,
model
=
'arrow'
,
position
=
from_pos
,
**
kwargs
)
# self.x = -pos[1]
# self.y = pos[2]
# self.z = pos[0]
to_pos
=
1000
*
to_pos
# to_pos = -to_pos[2],-to_pos[1],to_pos[0]
# to_pos = -to_pos[2],-to_pos[0],to_pos[1]
# to_pos = to_pos[0],to_pos[2],to_pos[1]
# to_pos = -to_pos[0],to_pos[1],to_pos[2]
# to_pos = to_pos[1], -to_pos[0], -to_pos[2]
# to_pos = to_pos[1], -to_pos[0], -to_pos[2]
self
.
rotation
=
(
0
,
0
,
0
)
self
.
look_at
(
to_pos
)
print
(
self
.
rotation
)
# self.model = Mesh(vertices=[
# from_pos,
# from_pos + (to_pos - from_pos) * 0.9,
# from_pos + (to_pos - from_pos) * 0.9 + Vec3(0, 0.1, 0),
# to_pos,
# from_pos + (to_pos - from_pos) * 0.9 - Vec3(0, 0.1, 0),
# from_pos + (to_pos - from_pos) * 0.9
# ], mode='triangle', thickness=thickness)
#
# self.color = color
# self.look_at(to_pos)
# self.scale_z = (to_pos - from_pos).length()
# class Arrow(Entity):
# def __init__(self,parent, from_pos, to_pos, **kwargs):
# super().__init__(parent=parent, model='arrow', **kwargs)
# self.position = from_pos
# self.look_at(to_pos)
# import numpy as np
# def draw_arrow(parent, from_pos, to_pos, color, alpha):
# # 计算方向向量和长度
# p1 = np.array(from_pos)
# p2 = np.array(to_pos)
# direction = p2 - p1
# length = np.linalg.norm(direction)
#
# # 创建箭头实体
# arrow = Entity(parent=parent, model="arrow", scale=(1, 1, length),color=color,alpha=alpha)
#
# # 设置箭头位置和方向
# arrow_position = p1 + direction/2
# arrow.position = arrow_position
# arrow.look_at(p2)
#
# return arrow
simulators/ursina/entities/entity_utils.py
浏览文件 @
11659848
...
@@ -255,9 +255,6 @@ def create_trail_info(body, trail):
...
@@ -255,9 +255,6 @@ def create_trail_info(body, trail):
acc_direction
=
acceleration
[
1
]
acc_direction
=
acceleration
[
1
]
acc_direction
=
np
.
array
(
acc_direction
)
*
2
acc_direction
=
np
.
array
(
acc_direction
)
*
2
verts_acc
=
[(
0
,
0
,
0
),
tuple
(
acc_direction
)]
verts_vel
=
[(
0
,
0
,
0
),
tuple
(
vel_direction
)]
vel_position
=
vel_direction
vel_position
=
vel_direction
vel_position
=
(
vel_position
[
0
],
vel_position
[
1
],
vel_position
[
2
])
vel_position
=
(
vel_position
[
0
],
vel_position
[
1
],
vel_position
[
2
])
...
@@ -267,57 +264,3 @@ def create_trail_info(body, trail):
...
@@ -267,57 +264,3 @@ def create_trail_info(body, trail):
trail
.
entity_infos
=
{
"velocity"
:
[
vel_info
,
vel_direction
,
vel_position
],
trail
.
entity_infos
=
{
"velocity"
:
[
vel_info
,
vel_direction
,
vel_position
],
"acceleration"
:
[
acc_info
,
acc_direction
,
acc_position
]}
"acceleration"
:
[
acc_info
,
acc_direction
,
acc_position
]}
def
create_trail_text_xxx
(
body
,
trail
):
velocity
=
merge_vectors
(
body
.
velocity
)
acceleration
=
merge_vectors
(
body
.
acceleration
)
vel_info
=
"%.2fkm/s"
%
(
velocity
[
0
])
acc_m
=
acceleration
[
0
]
*
1000
if
acc_m
>=
0.01
:
acc_info
=
"%.2fm/s²"
%
(
acc_m
)
else
:
acc_info
=
"%.2fmm/s²"
%
(
acc_m
*
1000
)
vel_direction
=
velocity
[
1
]
vel_direction
=
np
.
array
(
vel_direction
)
*
5
acc_direction
=
acceleration
[
1
]
acc_direction
=
np
.
array
(
acc_direction
)
*
2
# acc_direction = np.array(acc_direction)*UrsinaConfig.SCALE_FACTOR
# vertsyz = [tuple(body.position),tuple(acc_direction)] # [(0, 0, 0), (0, 10, 0), (0, 0, 0), (0, 0, 10)]
verts_acc
=
[(
0
,
0
,
0
),
tuple
(
acc_direction
)]
acc_line
=
Entity
(
parent
=
trail
,
model
=
Mesh
(
vertices
=
verts_acc
,
mode
=
'line'
,
thickness
=
3
),
color
=
color
.
yellow
,
alpha
=
0.5
)
acc_line
.
set_light_off
()
verts_vel
=
[(
0
,
0
,
0
),
tuple
(
vel_direction
)]
vel_line
=
Entity
(
parent
=
trail
,
model
=
Mesh
(
vertices
=
verts_vel
,
mode
=
'line'
,
thickness
=
3
),
color
=
color
.
red
,
alpha
=
0.5
)
vel_line
.
set_light_off
()
vel_position
=
vel_direction
vel_position
=
(
vel_position
[
0
],
vel_position
[
1
],
vel_position
[
2
])
vel_text
=
Text
(
vel_info
,
scale
=
50
,
billboard
=
True
,
parent
=
trail
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
False
,
color
=
color
.
red
,
position
=
vel_position
,
alpha
=
0.5
)
vel_text
.
set_light_off
()
acc_position
=
acc_direction
acc_position
=
(
acc_position
[
0
],
acc_position
[
1
],
acc_position
[
2
])
acc_text
=
Text
(
acc_info
,
scale
=
50
,
billboard
=
True
,
parent
=
trail
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
False
,
color
=
color
.
yellow
,
position
=
acc_position
,
alpha
=
0.5
)
acc_text
.
set_light_off
()
# self.name_text.background.color = color.rgba(b_color[0], b_color[1], b_color[2], 0.3)
# # self.name_text.scale = self.scale
# inverse_color = get_inverse_color(b_color)
# self.name_text.color = color.rgba(inverse_color[0], inverse_color[1], inverse_color[2], 1)
# acc_line.enabled = False
# vel_line.enabled = False
# vel_text.enabled = False
# acc_text.enabled = False
trail
.
entity_infos
=
[
acc_line
,
vel_line
,
vel_text
,
acc_text
]
return
acc_line
,
vel_line
,
vel_text
,
acc_text
simulators/ursina/entities/planet.py
浏览文件 @
11659848
...
@@ -62,7 +62,7 @@ class Planet(Entity):
...
@@ -62,7 +62,7 @@ class Planet(Entity):
subdivisions
=
self
.
body
.
resolution
subdivisions
=
self
.
body
.
resolution
model
=
create_sphere
(
0.5
,
subdivisions
)
model
=
create_sphere
(
0.5
,
subdivisions
)
rotation
=
(
0
,
self
.
body
.
rotate_angle
,
0
)
rotation
=
(
0
,
0
,
0
)
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
...
...
simulators/ursina/ursina_mesh.py
浏览文件 @
11659848
...
@@ -307,7 +307,7 @@ if __name__ == '__main__':
...
@@ -307,7 +307,7 @@ if __name__ == '__main__':
# arrow = Entity(model=create_arrow(), color=color.yellow)
# arrow = Entity(model=create_arrow(), color=color.yellow)
# arrow.set_light_off()
# arrow.set_light_off()
arrow
,
line
=
create_arrow_line
((
0
,
0
,
0
),
(
10
,
0
,
0
))
arrow
,
line
,
text
=
create_arrow_line
((
0
,
0
,
0
),
(
10
,
0
,
0
))
EditorCamera
()
EditorCamera
()
app
.
run
()
app
.
run
()
simulators/ursina_simulator.py
浏览文件 @
11659848
...
@@ -37,7 +37,11 @@ class WorldGrid(Entity):
...
@@ -37,7 +37,11 @@ class WorldGrid(Entity):
"""
"""
def
draw_axises
(
self
):
def
draw_axises
(
self
):
# 坐标轴
"""
画坐标轴
@return:
"""
arrow_x
,
line_x
,
text_x
=
create_arrow_line
((
0
,
0
,
0
),
(
10
,
0
,
0
),
label
=
"X"
,
color
=
color
.
red
)
arrow_x
,
line_x
,
text_x
=
create_arrow_line
((
0
,
0
,
0
),
(
10
,
0
,
0
),
label
=
"X"
,
color
=
color
.
red
)
arrow_y
,
line_y
,
text_y
=
create_arrow_line
((
0
,
0
,
0
),
(
0
,
10
,
0
),
label
=
"Y"
,
color
=
color
.
green
)
arrow_y
,
line_y
,
text_y
=
create_arrow_line
((
0
,
0
,
0
),
(
0
,
10
,
0
),
label
=
"Y"
,
color
=
color
.
green
)
arrow_z
,
line_z
,
text_z
=
create_arrow_line
((
0
,
0
,
0
),
(
0
,
0
,
10
),
label
=
"Z"
,
color
=
color
.
yellow
)
arrow_z
,
line_z
,
text_z
=
create_arrow_line
((
0
,
0
,
0
),
(
0
,
0
,
10
),
label
=
"Z"
,
color
=
color
.
yellow
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录