This commit is contained in:
Crispy 2021-10-16 19:37:39 +02:00
parent 9eea2a7c28
commit 08cb7dc283
4 changed files with 22 additions and 13 deletions

View file

@ -16,6 +16,8 @@ var click := {
"right": false,
"left": false,
}
var active_side := ""
var cursor_nodes := {
"right": preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance(),
"left": preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance(),
@ -61,17 +63,12 @@ func _update_cursors():
func _send_move_event():
var active: String
if click.right:
active = "right"
elif click.left:
active = "left"
else:
if not active_side:
return# only send move events while a cursor is held down
var event = InputEventMouseMotion.new()
event.position = prev_pos[active]
event.relative = cursor_pos[active] - prev_pos[active]
event.position = prev_pos[active_side]
event.relative = cursor_pos[active_side] - prev_pos[active_side]
event.speed = event.relative
viewport.input(event)
@ -80,6 +77,7 @@ func _send_click_event(state: bool, controller: String):
if click[controller] == state:
return # already in that state
click[controller] = state
_update_active_side()
var click_event = InputEventMouseButton.new()
click_event.position = cursor_pos[controller]
click_event.pressed = state
@ -96,3 +94,10 @@ func _trigger_on(controller):
func _trigger_off(controller):
_send_click_event(false, controller)
func _update_active_side() -> void:
if click.right:
active_side = "right"
elif click.left:
active_side = "left"
else:
active_side = ""

View file

@ -147,6 +147,8 @@ func _update_target():
# make area only detect colliders of a different hand
_overlay_area.get_node("AreaNear").collision_mask = int(t!="right")*2 # detect right hand
_overlay_area.get_node("AreaNear").collision_mask += int(t!="left")*4 # detect left hand
_overlay_area.get_node("AreaNear").collision_mask = int(t!="right")*8 # detect right hand
_overlay_area.get_node("AreaNear").collision_mask += int(t!="left")*16 # detect left hand
func _update_modules():

View file

@ -22,7 +22,7 @@ var trackers = {
func _init() -> void:
# OS.window_minimized = true
ovr_config.set_application_type(2) # Set to OVERLAY MODE = 2, NORMAL MODE = 1
ovr_config.set_application_type(2) # Set to OVERLAY MODE
ovr_config.set_tracking_universe(1) # Set to SEATED MODE = 0, STANDING MODE = 1, RAW MODE = 2
# Find the OpenVR interface and initialise it

View file

@ -5,24 +5,26 @@ const OVERLAY_PROPERTIES = {
"has_touch": true,
}
var ihandler
var grabber
var clicker
var oinst
func _ready() -> void:
oinst = get_viewport().get_parent()
ihandler = get_viewport().get_node("../OverlayInteraction/OverlayGrab")
clicker = get_viewport().get_node("../OverlayInteraction/OverlayCursor")
grabber = get_viewport().get_node("../OverlayInteraction/OverlayGrab")
for t in oinst.TARGETS:
$OptionButton.add_item(t)
$OptionButton.selected = oinst.TARGETS.find(oinst.target)
func _on_DragButton_button_down() -> void:
ihandler.begin_move()
grabber.begin_move(clicker.active_side)
func _on_DragButton_button_up() -> void:
ihandler.finish_move()
grabber.finish_move()
func _on_OptionButton_item_selected(index: int) -> void: