Skip to content

Commit

Permalink
More comfortable pointer angle. Also user configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
immortalx74 committed Nov 1, 2022
1 parent dd73a01 commit 4b383f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

<span style="color:DeepSkyBlue">Returns:</span> `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()`
Expand Down
9 changes: 6 additions & 3 deletions ui/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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 } )
Expand Down

0 comments on commit 4b383f7

Please sign in to comment.