main.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function lovr.load()
  2. lovr.graphics.setBackgroundColor(.7, .7, .7)
  3. -- Precompute camera transform (could also be attached to a controller)
  4. local x, y, z = -3, 3, 3
  5. camera = lovr.math.newMat4():target(vec3(x, y, z), vec3(0, 0, 0))
  6. view = lovr.math.newMat4():lookAt(vec3(x, y, z), vec3(0, 0, 0))
  7. end
  8. local renderScene
  9. -- Render to the mirror window using the camera perspective
  10. function lovr.mirror(pass)
  11. pass:transform(view)
  12. renderScene(pass, true)
  13. end
  14. -- Render to the headset using the headset perspective
  15. function lovr.draw(pass)
  16. renderScene(pass, false)
  17. end
  18. renderScene = function(pass, isCamera)
  19. local t = lovr.headset.getTime()
  20. -- Draw the ground
  21. pass:setColor(.15, .15, .15)
  22. pass:plane(0, 0, 0, 4, 4, math.pi / 2, 1, 0, 0)
  23. -- Draw some cubes
  24. pass:setColor(1, 0, 0)
  25. for i = -3, 3 do
  26. local ax, ay, az = lovr.math.noise(i + t), lovr.math.noise(i + t * .3), lovr.math.noise(i + t * .7)
  27. pass:cube(i, 2 + math.sin(i + t), -1, .2, (t * .1) * math.pi, ax, ay, az)
  28. end
  29. -- Draw the headset or the camera, depending on the viewer
  30. if isCamera then
  31. pass:setColor(1, 1, 1)
  32. local x, y, z, angle, ax, ay, az = lovr.headset.getPose()
  33. pass:cube(x, y, z, .2, angle, ax, ay, az)
  34. else
  35. pass:setColor(1, 1, 1)
  36. pass:cube(camera)
  37. end
  38. -- Always draw the controllers
  39. for i, hand in ipairs(lovr.headset.getHands()) do
  40. local x, y, z, angle, ax, ay, az = lovr.headset.getPose(hand)
  41. pass:cube(x, y, z, .06, angle, ax, ay, az)
  42. end
  43. end