-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteleporter.py
More file actions
78 lines (60 loc) · 2.37 KB
/
teleporter.py
File metadata and controls
78 lines (60 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import harfang as hg
import math
from helpers import draw_spline
def update_teleporter_pos(controller, actor_pos, head_pos, teleporter_pos, playground=None):
if controller.IsConnected():
world = controller.World()
T = hg.GetT(world)
Z = hg.GetZ(world)
min_Vy = -0.1
if Z.y < min_Vy:
if playground is not None:
teleport_I = T + Z * (playground[0].y - T.y) / Z.y
teleport_I = hg.Clamp(teleport_I, playground[0], playground[1])
else:
teleport_I = T + Z * (0 - T.y) / Z.y
# detect trigger
if controller.Pressed(hg.VRCB_Axis1):
new_actor_pos = teleport_I + (actor_pos - head_pos)
actor_diff = new_actor_pos - actor_pos
teleporter_pos = teleport_I + actor_diff
actor_pos = new_actor_pos
else:
teleporter_pos = teleport_I
return actor_pos, teleporter_pos
def update_teleporter_node(controller, actor_pos, head_pos, teleporter_node, playground=None):
if controller.IsConnected():
world = controller.World()
T = hg.GetT(world)
Z = hg.GetZ(world)
min_Vy = -0.1
if Z.y < min_Vy:
if playground is not None:
teleport_I = T + Z * (playground[0].y - T.y) / Z.y
teleport_I = hg.Clamp(teleport_I, playground[0], playground[1])
else:
teleport_I = T + Z * (0 - T.y) / Z.y
# detect trigger
if controller.Pressed(hg.VRCB_Axis1):
new_actor_pos = teleport_I + (actor_pos - head_pos)
actor_diff = new_actor_pos - actor_pos
teleporter_pos = teleport_I + actor_diff
actor_pos = new_actor_pos
else:
teleporter_pos = teleport_I
teleporter_node.GetTransform().SetPos(teleporter_pos)
teleporter_node.Enable()
else:
teleporter_node.Disable()
return actor_pos
def get_head_pos(vr_state, actor_pos):
headT = hg.GetT(vr_state.head)
return hg.Vec3(headT.x, actor_pos.y, headT.z)
def draw_teleporter_spline(controller_mtx, ground_mtx, vid, vtx_layout_spline, line_shader):
dir_teleporter = hg.GetZ(controller_mtx)
pos_start = hg.GetT(controller_mtx)
cos_angle = hg.Dot(dir_teleporter, hg.Normalize(hg.Vec3(dir_teleporter.x, 0, dir_teleporter.z)))
cos_angle = min(1.0, max(cos_angle, -1))
angle = math.acos(cos_angle)
strength_force = pow((math.sin(angle) + 1) / 2, 2) * 2
draw_spline(pos_start, pos_start + dir_teleporter * strength_force, ground_mtx + hg.Vec3(0, -strength_force, 0), ground_mtx, vid, vtx_layout_spline, line_shader)