diff --git a/simulators/ursina/entities/body_trail.py b/simulators/ursina/entities/body_trail.py index 2e6d88ea0a2f7030edfd30aa442f131e3a5f5b2f..ee7405366929f27f9feb3a592a229f6a3767adac 100644 --- a/simulators/ursina/entities/body_trail.py +++ b/simulators/ursina/entities/body_trail.py @@ -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 Entity, Mesh, Text, color, destroy +from ursina import Entity, Mesh, Text, color, destroy, Vec3 from simulators.ursina.ursina_config import UrsinaConfig @@ -48,10 +48,16 @@ class BodyTrail(Entity): 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() + 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() @@ -65,3 +71,62 @@ class BodyTrail(Entity): 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 \ No newline at end of file diff --git a/simulators/ursina/entities/planet.py b/simulators/ursina/entities/planet.py index 83ce810646a8b998fa98a4f943d10668d50f18ba..e0e18af2a5aaa3d6b18d908295f472db25b0fee3 100644 --- a/simulators/ursina/entities/planet.py +++ b/simulators/ursina/entities/planet.py @@ -109,6 +109,7 @@ class Planet(Entity): pos = self.body_view.position * UrsinaConfig.SCALE_FACTOR if self.body.parent is None: + # TODO: ???????? self.x = -pos[1] self.y = pos[2] self.z = pos[0] @@ -175,6 +176,7 @@ class Planet(Entity): self.f_parent = b break pos = self.f_parent.position * UrsinaConfig.SCALE_FACTOR + # TODO: ???????? self.x = -pos[1] self.y = pos[2] self.z = pos[0] diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index 1bb72ff03d1701f30ae63ec960160bd1673bd7ca..a11bc885383dda601d31638484ac7ef00d65a65f 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -40,13 +40,17 @@ class WorldGrid(Entity): s = 100 grid = Entity(model=Grid(s, s), scale=s * 20, color=color.rgba(255, 255, 255, 20), rotation_x=90, 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() + # 坐标轴 + # 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): """