main.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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():lookAt(vec3(x, y, z), vec3(0, 0, 0))
  6. view = lovr.math.newMat4(camera):invert()
  7. end
  8. local renderScene
  9. -- Render to the mirror window using the camera perspective
  10. function lovr.mirror()
  11. lovr.graphics.clear()
  12. lovr.graphics.origin()
  13. lovr.graphics.transform(view)
  14. renderScene(true)
  15. end
  16. -- Render to the headset using the headset perspective
  17. function lovr.draw()
  18. renderScene(false)
  19. end
  20. renderScene = function(isCamera)
  21. local t = lovr.timer.getTime()
  22. -- Draw the ground
  23. lovr.graphics.setColor(.15, .15, .15)
  24. lovr.graphics.plane('fill', 0, 0, 0, 4, 4, math.pi / 2, 1, 0, 0)
  25. -- Draw some cubes
  26. lovr.graphics.setColor(1, 0, 0)
  27. for i = -3, 3 do
  28. local ax, ay, az = lovr.math.noise(i + t), lovr.math.noise(i + t * .3), lovr.math.noise(i + t * .7)
  29. lovr.graphics.cube('fill', i, 2 + math.sin(i + t), -1, .2, (t * .1) ^ 2 * math.pi, ax, ay, az)
  30. end
  31. -- Draw the headset or the camera, depending on the viewer
  32. if isCamera then
  33. lovr.graphics.setColor(1, 1, 1)
  34. local x, y, z, angle, ax, ay, az = lovr.headset.getPose()
  35. lovr.graphics.cube('fill', x, y, z, .2, angle, ax, ay, az)
  36. else
  37. lovr.graphics.setColor(1, 1, 1)
  38. lovr.graphics.cube('fill', camera)
  39. end
  40. -- Always draw the controllers
  41. for i, hand in ipairs(lovr.headset.getHands()) do
  42. local x, y, z, angle, ax, ay, az = lovr.headset.getPose(hand)
  43. lovr.graphics.cube('fill', x, y, z, .06, angle, ax, ay, az)
  44. end
  45. end