main.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. box = {
  2. position = lovr.math.newVec3(0, 1, -.25),
  3. size = .25
  4. }
  5. function lovr.load()
  6. drag = {
  7. active = false,
  8. hand = nil,
  9. offset = lovr.math.newVec3()
  10. }
  11. end
  12. function lovr.update(dt)
  13. for i, hand in ipairs(lovr.headset.getHands()) do
  14. if lovr.headset.wasPressed(hand, 'trigger') then
  15. local offset = box.position - vec3(lovr.headset.getPosition(hand))
  16. local halfSize = box.size / 2
  17. local x, y, z = offset:unpack()
  18. if math.abs(x) < halfSize and math.abs(y) < halfSize and math.abs(z) < halfSize then
  19. drag.active = true
  20. drag.hand = hand
  21. drag.offset:set(offset)
  22. end
  23. end
  24. end
  25. if drag.active then
  26. local handPosition = vec3(lovr.headset.getPosition(drag.hand))
  27. box.position:set(handPosition + drag.offset)
  28. if lovr.headset.wasReleased(drag.hand, 'trigger') then
  29. drag.active = false
  30. end
  31. end
  32. end
  33. function lovr.draw(pass)
  34. pass:setColor(drag.active and 0x80ee80 or 0xee8080)
  35. pass:cube(box.position, box.size, quat(), 'line')
  36. for i, hand in ipairs(lovr.headset.getHands()) do
  37. pass:setColor(0xffffff)
  38. pass:cube(mat4(lovr.headset.getPose(hand)):scale(.01))
  39. end
  40. end