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

Python超人-宇宙模拟器

上级 3df3827c
...@@ -799,6 +799,31 @@ def get_run_speed_factor(run_speed_factor=1 / 8): ...@@ -799,6 +799,31 @@ def get_run_speed_factor(run_speed_factor=1 / 8):
return run_speed_factor * control_speed_factor return run_speed_factor * control_speed_factor
def camera_to_target(info):
from ursina import camera, Vec3, lerp, slerp, time
import inspect
t = info.get("to")
ct_id = t["ct_id"]
from objs import CameraTarget
ct = CameraTarget.targets.get(ct_id, None)
if ct is None:
print("没有发现 CameraTarget ct_id = ", ct_id)
return
target_position = ct.planet.position
direction = (target_position - camera.position).normalized() # 计算摄像机移动的方向
distance = (target_position - camera.position).length() # 计算摄像机到目标位置的距离
if distance > 0: # 如果摄像机还没有到达目标位置
camera.position += direction * t.get("t", 0.1) * time.dt # 让摄像机匀速移动
else:
print("摄像机已到达目标位置")
# camera_position = lerp(camera.position, ct.planet.position, t.get("t", 0.1))
# camera.look_at(ct.planet)
# camera.position = camera_position # Vec3(camera_position[0],camera_position[1], 0)
print("camera_to_target", ct.planet.position, camera.position, t)
# camera.position = p
def camera_move_control(camera_move_infos, cond_cb, value_conv=None, smooth=None): def camera_move_control(camera_move_infos, cond_cb, value_conv=None, smooth=None):
""" """
...@@ -835,7 +860,13 @@ def camera_move_control(camera_move_infos, cond_cb, value_conv=None, smooth=None ...@@ -835,7 +860,13 @@ def camera_move_control(camera_move_infos, cond_cb, value_conv=None, smooth=None
next_cond = camera_move_infos[idx + 1][0] next_cond = camera_move_infos[idx + 1][0]
next_info = camera_move_infos[idx + 1][1] next_info = camera_move_infos[idx + 1][1]
cond_cb_params = {"cond": cond, "next_cond": next_cond, "idx": idx, "info": info, "next_info": next_info} cond_cb_params = {"cond": cond, "next_cond": next_cond, "idx": idx, "info": info, "next_info": next_info}
if cond_cb(cond_cb_params): if cond_cb(cond_cb_params):
t = info.get("to", None)
if t is not None:
camera_to_target(info)
continue
p = camera.position p = camera.position
x, y, z = [info.get("x", 0), info.get("y", 0), info.get("z", 0)] x, y, z = [info.get("x", 0), info.get("y", 0), info.get("z", 0)]
mis = [info.get("f", 0), info.get("b", 0), info.get("l", 0), info.get("r", 0), \ mis = [info.get("f", 0), info.get("b", 0), info.get("l", 0), info.get("r", 0), \
...@@ -867,16 +898,6 @@ def camera_move_control(camera_move_infos, cond_cb, value_conv=None, smooth=None ...@@ -867,16 +898,6 @@ def camera_move_control(camera_move_infos, cond_cb, value_conv=None, smooth=None
if abs(diff[_i + 3]) < 0.05: if abs(diff[_i + 3]) < 0.05:
mis[_i] = round(last_move_ps[_i + 3] - diff[_i + 3] / 100, 2) mis[_i] = round(last_move_ps[_i + 3] - diff[_i + 3] / 100, 2)
# print(f"{dns[_i]}", mis[_i]) # print(f"{dns[_i]}", mis[_i])
# if diff[4] != 0:
# mis[1] = 0
# if diff[5] != 0:
# z = 0
# if diff[6] != 0:
# x = 0
# if diff[7] != 0:
# y = 0
# if diff[8] != 0:
# z = 0
if x != 0 or y != 0 or z != 0: if x != 0 or y != 0 or z != 0:
p += Vec3(conv_val(x, "x"), conv_val(y, "y"), conv_val(z, "z")) p += Vec3(conv_val(x, "x"), conv_val(y, "y"), conv_val(z, "z"))
......
...@@ -215,6 +215,7 @@ class HalleyCometSim(HalleyCometSimBase): ...@@ -215,6 +215,7 @@ class HalleyCometSim(HalleyCometSimBase):
# 按坐标系方向移动 x:右+左-, y:升+降-, z:前+(接近太阳)后-(远离太阳) # 按坐标系方向移动 x:右+左-, y:升+降-, z:前+(接近太阳)后-(远离太阳)
# 以摄像机视角移动 f:前 b:后 l:左 r:右 u:上 d:下 # 以摄像机视角移动 f:前 b:后 l:左 r:右 u:上 d:下
(1982, {"x": 2, "y": 1}), (1982, {"x": 2, "y": 1}),
# (1983, {"to": {"ct_id": 1, "t": 10}}),
(1986, {"x": 2, "y": -2, "z": -15}), (1986, {"x": 2, "y": -2, "z": -15}),
(1987, {"y": -6, "z": -12}), (1987, {"y": -6, "z": -12}),
(1988, {"y": -3, "z": -12}), (1988, {"y": -3, "z": -12}),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册