From 4b383f74c551c43f95f18e997a195ba30a91b792 Mon Sep 17 00:00:00 2001 From: immortalx74 Date: Tue, 1 Nov 2022 18:37:16 +0200 Subject: [PATCH] More comfortable pointer angle. Also user configurable. --- README.md | 5 +++-- ui/ui.lua | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f3c2568..a84f316 100644 --- a/README.md +++ b/README.md @@ -222,15 +222,16 @@ NOTE: Useful if you want to set interaction on/off programmatically, without pre --- -`UI.Init(interaction_toggle_device, interaction_toggle_button, enabled)` +`UI.Init(interaction_toggle_device, interaction_toggle_button, enabled, pointer_rotation)` |Argument|Type|Description |:---|:---|:---| |`interaction_toggle_device` _[opt]_|Device|controller |`interaction_toggle_button` _[opt]_|DeviceButton|controller button that toggles interaction on/off |`enabled` _[opt]_|boolean|initial state of interaction +|`pointer_rotation` _[opt]_|number|pointer rotation angle (default value is similar to SteamVR/Oculus). Returns: `nothing` -NOTE: Should be called on `lovr.load()`. Defaults are `hand/left`, `thumbstick`, `true` respectively. +NOTE: Should be called on `lovr.load()`. Defaults are `hand/left`, `thumbstick`, `true`, `math.pi / 3` respectively. --- `UI.InputInfo()` diff --git a/ui/ui.lua b/ui/ui.lua index 896b0e6..b25a487 100644 --- a/ui/ui.lua +++ b/ui/ui.lua @@ -52,7 +52,8 @@ local image_buttons = {} local color_themes = {} local window_drag = { id = nil, is_dragging = false, offset = lovr.math.newMat4() } local layout = { prev_x = 0, prev_y = 0, prev_w = 0, prev_h = 0, row_h = 0, total_w = 0, total_h = 0, same_line = false } -local input = { interaction_toggle_device = "hand/left", interaction_toggle_button = "thumbstick", interaction_enabled = true, trigger = e_trigger.idle } +local input = { interaction_toggle_device = "hand/left", interaction_toggle_button = "thumbstick", interaction_enabled = true, trigger = e_trigger.idle, + pointer_rotation = math.pi / 3 } local osk = { textures = {}, visible = false, prev_frame_visible = false, transform = lovr.math.newMat4(), mode = {}, cur_mode = 1, last_key = nil } color_themes.dark = @@ -593,7 +594,8 @@ function UI.InputInfo() ray.pos = vec3( lovr.headset.getPosition( dominant_hand ) ) ray.ori = quat( lovr.headset.getOrientation( dominant_hand ) ) - ray.dir = ray.ori:direction() + local m = mat4( vec3( 0, 0, 0 ), ray.ori ):rotate( -input.pointer_rotation, 1, 0, 0 ) + ray.dir = quat( m ):direction() caret.counter = caret.counter + 1 if caret.counter > caret.blink_rate then caret.counter = 0 end @@ -602,10 +604,11 @@ function UI.InputInfo() end end -function UI.Init( interaction_toggle_device, interaction_toggle_button, enabled ) +function UI.Init( interaction_toggle_device, interaction_toggle_button, enabled, pointer_rotation ) input.interaction_toggle_device = interaction_toggle_device or input.interaction_toggle_device input.interaction_toggle_button = interaction_toggle_button or input.interaction_toggle_button input.interaction_enabled = (enabled ~= false) + input.pointer_rotation = pointer_rotation or input.pointer_rotation font.handle = lovr.graphics.newFont( root .. "DejaVuSansMono.ttf" ) osk.textures[ 1 ] = lovr.graphics.newTexture( 640, 320, { mipmaps = false } ) osk.textures[ 2 ] = lovr.graphics.newTexture( 640, 320, { mipmaps = false } )