@@ -39,8 +39,6 @@ LÖVR exposes a very simple API for tracking both hands and controllers. The who
39
39
We can start by copying the [ Tracked Hands] ( https://lovr.org/docs/Intro/Tracked_Hands ) example:
40
40
41
41
42
- # TODO: check if getHands() works with controllers
43
-
44
42
``` lua
45
43
function lovr .draw (pass )
46
44
for i , hand in ipairs (lovr .headset .getHands ()) do
54
52
If you have trouble with hand tracking, you can switch to controllers without changing the code.
55
53
</small >
56
54
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.
58
56
59
57
To study what exactly the code does, you can check out these pages in the docs:
60
58
@@ -126,7 +124,7 @@ If the vector is used only within one frame (it isn't assigned to a variable use
126
124
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' ` .
127
125
</details >
128
126
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.
130
128
131
129
We'll add an ` isActive ` property to each box...
132
130
@@ -172,7 +170,8 @@ function lovr.draw(pass)
172
170
end
173
171
end
174
172
175
- -- ...
173
+ pass :setColor (0xffffff )
174
+ pass :sphere (handPosition , .1 )
176
175
end
177
176
end
178
177
```
336
335
``` lua
337
336
function lovr .draw (pass )
338
337
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
340
345
341
346
local wasReleased = lovr .headset .wasReleased (hand , ' trigger' )
342
347
@@ -358,7 +363,17 @@ function lovr.draw(pass)
358
363
for i , hand in ipairs (lovr .headset .getHands ()) do
359
364
local handPosition = vec3 (lovr .headset .getPosition (hand ))
360
365
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
362
377
363
378
local grabbedBox = grabbedBoxes [hand ]
364
379
@@ -377,7 +392,9 @@ To highlight a grabbed box, we'll change its color:
377
392
378
393
``` lua
379
394
function lovr .draw (pass )
380
- -- ...
395
+ for i , hand in ipairs (lovr .headset .getHands ()) do
396
+ -- ...
397
+ end
381
398
382
399
for _ , box in ipairs (boxes ) do
383
400
local isGrabbed = (
0 commit comments