提交 cce82fd6 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 d159c082
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# python_version :3.8 # python_version :3.8
# ============================================================================== # ==============================================================================
# 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 from ursina import Entity, Mesh, Text, color, destroy, Vec3
from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_config import UrsinaConfig
...@@ -48,10 +48,16 @@ class BodyTrail(Entity): ...@@ -48,10 +48,16 @@ class BodyTrail(Entity):
verts_acc = [(0, 0, 0), tuple(acc_direction)] verts_acc = [(0, 0, 0), tuple(acc_direction)]
verts_vel = [(0, 0, 0), tuple(vel_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()
acc_line = Entity(parent=self, model=Mesh(vertices=verts_acc, mode='line', thickness=3), acc_line = Entity(parent=self, model=Mesh(vertices=verts_acc, mode='line', thickness=3),
color=color.yellow, alpha=0.5) color=color.yellow, alpha=0.5)
acc_line.set_light_off() 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), vel_line = Entity(parent=self, model=Mesh(vertices=verts_vel, mode='line', thickness=3),
color=color.red, alpha=0.5) color=color.red, alpha=0.5)
vel_line.set_light_off() vel_line.set_light_off()
...@@ -65,3 +71,62 @@ class BodyTrail(Entity): ...@@ -65,3 +71,62 @@ class BodyTrail(Entity):
font=UrsinaConfig.CN_FONT, background=False, color=color.yellow, font=UrsinaConfig.CN_FONT, background=False, color=color.yellow,
position=acc_position, alpha=0.5) position=acc_position, alpha=0.5)
acc_text.set_light_off() 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
\ No newline at end of file
...@@ -109,6 +109,7 @@ class Planet(Entity): ...@@ -109,6 +109,7 @@ class Planet(Entity):
pos = self.body_view.position * UrsinaConfig.SCALE_FACTOR pos = self.body_view.position * UrsinaConfig.SCALE_FACTOR
if self.body.parent is None: if self.body.parent is None:
# TODO: ????????
self.x = -pos[1] self.x = -pos[1]
self.y = pos[2] self.y = pos[2]
self.z = pos[0] self.z = pos[0]
...@@ -175,6 +176,7 @@ class Planet(Entity): ...@@ -175,6 +176,7 @@ class Planet(Entity):
self.f_parent = b self.f_parent = b
break break
pos = self.f_parent.position * UrsinaConfig.SCALE_FACTOR pos = self.f_parent.position * UrsinaConfig.SCALE_FACTOR
# TODO: ????????
self.x = -pos[1] self.x = -pos[1]
self.y = pos[2] self.y = pos[2]
self.z = pos[0] self.z = pos[0]
......
...@@ -40,13 +40,17 @@ class WorldGrid(Entity): ...@@ -40,13 +40,17 @@ class WorldGrid(Entity):
s = 100 s = 100
grid = Entity(model=Grid(s, s), scale=s * 20, color=color.rgba(255, 255, 255, 20), rotation_x=90, grid = Entity(model=Grid(s, s), scale=s * 20, color=color.rgba(255, 255, 255, 20), rotation_x=90,
position=(0, -80, 0)) position=(0, -80, 0))
# 坐标轴
# vertsx = ((0, 0, 0), (10, 0, 0))
# Entity(model=Mesh(vertices=vertsx, mode='line', thickness=3), color=color.cyan).set_light_off()
# vertsyz = [(0, 0, 0), (0, 10, 0), (0, 0, 0), (0, 0, 10)]
# Entity(model=Mesh(vertices=vertsyz, mode='line', thickness=3), color=color.yellow).set_light_off()
grid.set_light_off() grid.set_light_off()
# 坐标轴
# vertsx = ((0, 0, 0), (10, 0, 0))
# Entity(model=Mesh(vertices=vertsx, mode='line', thickness=3), color=color.red).set_light_off()
#
# vertsy = [(0, 0, 0), (0, 10, 0)]
# Entity(model=Mesh(vertices=vertsy, mode='line', thickness=3), color=color.green).set_light_off()
#
# vertsz = [(0, 0, 0), (0, 0, 10)]
# Entity(model=Mesh(vertices=vertsz, mode='line', thickness=3), color=color.blue).set_light_off()
class UrsinaSimulator(Simulator): class UrsinaSimulator(Simulator):
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册