Skip to content

Commit 6ca44f7

Browse files
committed
Revise Drag & drop in VR with LÖVR
1 parent 9750d44 commit 6ca44f7

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

content/drag-and-drop-in-vr-with-lovr.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ LÖVR exposes a very simple API for tracking both hands and controllers. The who
3939
We can start by copying the [Tracked Hands](https://lovr.org/docs/Intro/Tracked_Hands) example:
4040

4141

42-
# TODO: check if getHands() works with controllers
43-
4442
```lua
4543
function lovr.draw(pass)
4644
for i, hand in ipairs(lovr.headset.getHands()) do
@@ -54,7 +52,7 @@ end
5452
If you have trouble with hand tracking, you can switch to controllers without changing the code.
5553
</small>
5654

57-
After launching it on your headset, you'll see two 10 centimeters white spheres following your hands positions.
55+
After launching it on your headset, you'll see two white spheres following your hands positions.
5856

5957
To study what exactly the code does, you can check out these pages in the docs:
6058

@@ -126,7 +124,7 @@ If the vector is used only within one frame (it isn't assigned to a variable use
126124
If you use a temporary vector during another frame, you'll get an error saying `'Attempt to use a temporary vector from a previous frame'`.
127125
</details>
128126

129-
No we need to detect whether the hand was touching the cube while the grab event fired.
127+
Now we need to detect whether the hand was touching the cube while the grab event fired.
130128

131129
We'll add an `isActive` property to each box...
132130

@@ -172,7 +170,8 @@ function lovr.draw(pass)
172170
end
173171
end
174172

175-
-- ...
173+
pass:setColor(0xffffff)
174+
pass:sphere(handPosition, .1)
176175
end
177176
end
178177
```
@@ -336,7 +335,13 @@ end
336335
```lua
337336
function lovr.draw(pass)
338337
for i, hand in ipairs(lovr.headset.getHands()) do
339-
-- ...
338+
local handPosition = vec3(lovr.headset.getPosition(hand))
339+
340+
local wasPressed = lovr.headset.wasPressed(hand, 'trigger')
341+
342+
if wasPressed then
343+
-- ...
344+
end
340345

341346
local wasReleased = lovr.headset.wasReleased(hand, 'trigger')
342347

@@ -358,7 +363,17 @@ function lovr.draw(pass)
358363
for i, hand in ipairs(lovr.headset.getHands()) do
359364
local handPosition = vec3(lovr.headset.getPosition(hand))
360365

361-
-- ...
366+
local wasPressed = lovr.headset.wasPressed(hand, 'trigger')
367+
368+
if wasPressed then
369+
-- ...
370+
end
371+
372+
local wasReleased = lovr.headset.wasReleased(hand, 'trigger')
373+
374+
if wasReleased then
375+
grabbedBoxes[hand] = nil
376+
end
362377

363378
local grabbedBox = grabbedBoxes[hand]
364379

@@ -377,7 +392,9 @@ To highlight a grabbed box, we'll change its color:
377392

378393
```lua
379394
function lovr.draw(pass)
380-
-- ...
395+
for i, hand in ipairs(lovr.headset.getHands()) do
396+
-- ...
397+
end
381398

382399
for _, box in ipairs(boxes) do
383400
local isGrabbed = (

0 commit comments

Comments
 (0)