From 9d88369fa888086e16fc998cab6f832d30babd85 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 23 Oct 2023 16:12:51 -0700 Subject: [PATCH] Physics_Pointer uses World:raycastClosest; And left hand; --- examples/Interaction/Physics_Pointer/main.lua | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/examples/Interaction/Physics_Pointer/main.lua b/examples/Interaction/Physics_Pointer/main.lua index fe6cde68..49293b98 100644 --- a/examples/Interaction/Physics_Pointer/main.lua +++ b/examples/Interaction/Physics_Pointer/main.lua @@ -26,17 +26,14 @@ function lovr.update(dt) world:update(dt) - local ox, oy, oz = lovr.headset.getPosition('hand/right/point') - local dx, dy, dz = quat(lovr.headset.getOrientation('hand/right/point')):direction():mul(50):unpack() - local closest = math.huge - world:raycast(ox, oy, oz, ox + dx, oy + dy, oz + dz, function(shape, x, y, z) - local distance = vec3(x, y, z):distance(vec3(ox, oy, oz)) - if distance < closest then - selectedBox = shape:getCollider() - hitpoint:set(x, y, z) - closest = distance - end - end) + local ox, oy, oz = lovr.headset.getPosition('hand/left/point') + local dx, dy, dz = quat(lovr.headset.getOrientation('hand/left/point')):direction():mul(50):unpack() + local shape, x, y, z = world:raycastClosest(ox, oy, oz, ox + dx, oy + dy, dz + dz) + + if shape then + selectedBox = shape:getCollider() + hitpoint:set(x, y, z) + end end function lovr.draw(pass) @@ -53,8 +50,8 @@ function lovr.draw(pass) end -- Laser pointer - local hand = vec3(lovr.headset.getPosition('hand/right/point')) - local direction = quat(lovr.headset.getOrientation('hand/right/point')):direction() + local hand = vec3(lovr.headset.getPosition('hand/left/point')) + local direction = quat(lovr.headset.getOrientation('hand/left/point')):direction() pass:setColor(1, 1, 1) pass:line(hand, selectedBox and hitpoint or (hand + direction * 50)) end