main.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. function lovr.load()
  2. world = lovr.physics.newWorld()
  3. world:setLinearDamping(.01)
  4. world:setAngularDamping(.005)
  5. -- Create the ground
  6. world:newBoxCollider(0, 0, 0, 50, .05, 50):setKinematic(true)
  7. -- Create boxes!
  8. boxes = {}
  9. for x = -1, 1, .25 do
  10. for y = .125, 2, .24999 do
  11. local box = world:newBoxCollider(x, y, -2 - y / 5, .25)
  12. table.insert(boxes, box)
  13. end
  14. end
  15. controllerBoxes = {}
  16. lovr.timer.step() -- Reset the timer before the first update
  17. shader = lovr.graphics.newShader('standard')
  18. shader:send('lovrExposure', 2)
  19. end
  20. function lovr.update(dt)
  21. -- Update the physics simulation
  22. world:update(dt)
  23. -- Place boxes on controllers
  24. for i, hand in ipairs(lovr.headset.getHands()) do
  25. if not controllerBoxes[i] then
  26. controllerBoxes[i] = world:newBoxCollider(0, 0, 0, .25)
  27. controllerBoxes[i]:setKinematic(true)
  28. controllerBoxes[i]:setMass(10)
  29. end
  30. controllerBoxes[i]:setPose(lovr.headset.getPose(hand))
  31. end
  32. end
  33. -- A helper function for drawing boxes
  34. function drawBox(box)
  35. local x, y, z = box:getPosition()
  36. lovr.graphics.cube('fill', x, y, z, .25, box:getOrientation())
  37. end
  38. function lovr.draw()
  39. lovr.graphics.setBackgroundColor(.8, .8, .8)
  40. lovr.graphics.setShader(shader)
  41. lovr.graphics.setColor(1, 0, 0)
  42. for i, box in ipairs(boxes) do
  43. drawBox(box)
  44. end
  45. lovr.graphics.setColor(0, 0, 1)
  46. for i, box in ipairs(controllerBoxes) do
  47. drawBox(box)
  48. end
  49. lovr.graphics.setColor(1, 1, 1)
  50. lovr.graphics.setShader()
  51. end