This commit is contained in:
Crispy 2021-05-26 23:25:49 +02:00
parent 3999f68b5d
commit 7634b952be
4 changed files with 40 additions and 63 deletions

View file

@ -1,12 +1,12 @@
extends Node
var _cursor_node = preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance()
var cursor_node = preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance()
onready var viewport: Viewport = get_node("../../OverlayViewport")
onready var _i = get_parent()
func _ready() -> void:
viewport.add_child(_cursor_node)
viewport.add_child(cursor_node)
get_parent().connect("trigger_on", self, "_trigger_on")
get_parent().connect("trigger_off", self, "_trigger_off")
@ -17,11 +17,11 @@ func _process(_delta: float) -> void:
#get canvas position of active controller
func get_canvas_pos() -> Vector2:
if _i._active_controller == "":
if not _i.active_controller:
return Vector2(-1000, 1000) # offscreen
var controller_local_pos = _i._overlay_area.global_transform.xform_inv(\
_i.tracker_nodes[_i._active_controller].translation)
_i.tracker_nodes[_i.active_controller].translation)
var pos = Vector2(controller_local_pos.x, controller_local_pos.y)
var overlay_size = OverlayInit.ovr_interface.get_render_targetsize()
@ -35,7 +35,7 @@ func get_canvas_pos() -> Vector2:
func _update_cursor():
_cursor_node.rect_position = get_canvas_pos()
cursor_node.rect_position = get_canvas_pos()
func _send_click_event(state: bool):

View file

@ -5,17 +5,14 @@ var _pre_move_target = ""# what offset is being changed
var _mover_hand_name = ""# left or right, which hand is grabbing (/active controller)
var _mover_hand_offsets = {"pos": Vector3(), "rot": Quat()} # original offsets for grabbing hand
onready var _i = get_parent()
onready var _overlay = get_node("../..") # overlay instance
onready var _interaction = get_parent() # interaction handler
onready var tracker_nodes = {
"head": $"../VR/head",
"left": $"../VR/left",
"right": $"../VR/right",
"world": $"../VR"
}
onready var _overlay_area = _i._overlay_area
onready var _overlay = get_node("../..")
func _ready() -> void:
@ -23,42 +20,42 @@ func _ready() -> void:
func begin_move():
if not _i._active_controller:
print("Could not begin moving overlay, no controller active. ", _overlay.name)
if not _interaction.active_controller:
print("Could not begin moving overlay, no controller is touching overlay. <", _overlay.name, ">")
return
_i.pause_triggers = true
_interaction.pause_triggers = true
# store current states to revert after move
_pre_move_target = _overlay.current_target
_mover_hand_name = _i._active_controller
_mover_hand_offsets = _overlay.get_offset_dict(_mover_hand_name)
_mover_hand_name = _interaction.active_controller
_mover_hand_offsets = _overlay.get_offset(_mover_hand_name)
# calculate offsets from active controller to overlay
var controller_t = tracker_nodes[_i._active_controller].transform
var overlay_t = _i._overlay_area.global_transform
var controller_t = tracker_nodes[_mover_hand_name].transform
var overlay_t = _interaction._overlay_area.global_transform
var new_pos = controller_t.xform_inv(overlay_t.origin)
var new_rot = Quat(controller_t.basis).inverse() * Quat(overlay_t.basis)
_overlay.set_offset(_mover_hand_name, new_pos, new_rot)
_overlay.current_target = _mover_hand_name
func finish_move():
# calculate and apply the new offsets
var new_target_t = tracker_nodes[_pre_move_target].transform
var ovelay_t = _overlay_area.global_transform
var ovelay_t = _interaction._overlay_area.global_transform
var new_pos = new_target_t.xform_inv(ovelay_t.origin)
var new_rot = Quat(new_target_t.basis).inverse() * Quat(ovelay_t.basis)
_overlay.set_offset(_pre_move_target, new_pos, new_rot)
# revert the grabbing hands offsets in case it's used as a fallback
_overlay.set_offset_dict(_mover_hand_name, _mover_hand_offsets)
# revert the grabbing hands offsets
_overlay.set_offset(_mover_hand_name, _mover_hand_offsets.pos, _mover_hand_offsets.rot)
# reset current_target (parent handles fallback)
# revert target
_overlay.update_current_target()
_overlay.save_settings()
_i._update_target()
_i.pause_triggers = false
_interaction._update_target()
_interaction.pause_triggers = false

View file

@ -5,17 +5,17 @@ signal touch_off # a controller exited
signal trigger_on # trigger pushed while touching
signal trigger_off# trigger released
var _touch_state = false
var _trigger_state = false
var touch_state = false
var trigger_state = false
# controller that currently the trigger down
var _active_controller: String = ""
var active_controller := ""
# reference to the area node thats used for touch
var _overlay_area = preload("res://addons/openvr_overlay/interaction/OverlayArea.tscn").instance()
var _right_is_activator := false
var _right_is_activator := false # this hand has a collider on it to trigger things on the overlay
var _left_is_activator := false
var pause_triggers := false
var pause_triggers := false # disable triggers updating
onready var tracker_nodes = {
"head": $VR/head,
@ -26,7 +26,6 @@ onready var tracker_nodes = {
func _ready() -> void:
add_child(_overlay_area)
_overlay_area.connect("body_entered", self, "_on_OverlayArea_entered")
_overlay_area.connect("body_exited", self, "_on_OverlayArea_exited")
@ -41,31 +40,31 @@ func _ready() -> void:
func _trigger_on(controller):
if _touch_state:
_active_controller = controller
_trigger_state = true
if touch_state:
active_controller = controller
trigger_state = true
emit_signal("trigger_on")
func _trigger_off():
_trigger_state = false
trigger_state = false
emit_signal("trigger_off")
func _on_OverlayArea_entered(body: Node) -> void:
if body.get_node("../../..") != self or pause_triggers:
return
_touch_state = true
_active_controller = body.get_parent().name
touch_state = true
active_controller = body.get_parent().name
emit_signal("touch_on")
func _on_OverlayArea_exited(body: Node) -> void:
if body.get_node("../../..") != self or pause_triggers:
return
# TEMP
_active_controller = "" # TODO revert to other controller if both were touching (edge case)
_touch_state = false
# TODO revert to other controller if both were touching (edge case)
active_controller = ""
touch_state = false
emit_signal("touch_off")
@ -85,7 +84,6 @@ func _update_target():
_overlay_area.get_parent().remove_child(_overlay_area)
tracker_nodes[get_parent().current_target].add_child(_overlay_area)
_left_is_activator = get_parent().current_target != "left"
_right_is_activator = get_parent().current_target != "right"
# toggle appropriate colliders
@ -99,7 +97,7 @@ func _on_RightHand_button_pressed(button: int) -> void:
func _on_RightHand_button_release(button: int) -> void:
if button == JOY_VR_TRIGGER and _active_controller == "right":
if button == JOY_VR_TRIGGER and active_controller == "right":
_trigger_off()
@ -109,18 +107,5 @@ func _on_LeftHand_button_pressed(button: int) -> void:
func _on_LeftHand_button_release(button: int) -> void:
if button == JOY_VR_TRIGGER and _active_controller == "left":
if button == JOY_VR_TRIGGER and active_controller == "left":
_trigger_off()
func get_touch_state():
return _touch_state
func get_trigger_state():
return _trigger_state
func get_active_controller():
return _active_controller

View file

@ -133,6 +133,7 @@ func set_target(new: String):
target = new
call_deferred("update_offset")
update_current_target()
save_settings()
func _set_current_target(new: String): # overrides target
@ -142,16 +143,10 @@ func _set_current_target(new: String): # overrides target
emit_signal("target_changed")
func get_offset_dict(offset_target: String) -> Dictionary:
func get_offset(offset_target: String) -> Dictionary:
return _offsets[offset_target].duplicate()
func set_offset_dict(offset_target: String, new: Dictionary) -> void:
_offsets[offset_target].pos = new.pos
_offsets[offset_target].rot = new.rot
update_offset()
func set_offset(offset_target: String, pos: Vector3, rot: Quat) -> void:
_offsets[offset_target].pos = pos
_offsets[offset_target].rot = rot