main.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. local cam = require'cam'
  2. -- set limits
  3. cam.polar_lower = math.pi / 2
  4. cam.polar_upper = 0.3
  5. -- see the cam.lua for other limits and speed settings to configure
  6. function lovr.update(dt)
  7. local t = lovr.timer.getTime()
  8. -- apply relative motion to camera
  9. -- note that user controls still work alongside with this scripted control
  10. cam.nudge(
  11. 0.2 * dt, -- orbit clockwise around center at constant speed
  12. 0.003 * math.sin(t), -- bob up and down
  13. 0.01 * math.sin(-t)) -- zoom in and out
  14. end
  15. function lovr.draw(pass)
  16. -- an example scene for testing camera controls
  17. pass:setColor(0x75507b)
  18. pass:box(0, 0.5, 0, 1)
  19. pass:setColor(0x623d53)
  20. pass:torus(0, 1.2, 0, 0.7, 0.3, math.pi/2, 1,0,0)
  21. pass:setColor(0xcba7a4)
  22. pass:torus(0, 1.28, 0, 0.72, 0.25, math.pi/2, 1,0,0)
  23. local tiles = 8
  24. for x = -tiles, tiles, 2 do
  25. for z = -tiles, tiles, 2 do
  26. local shade = math.exp(-0.05 * (x^2 + z^2))
  27. pass:setColor(shade * 0.5, shade * 0.8, shade * 0.7)
  28. pass:roundrect(x, -0.05, z, 1.8, 1.8, 0.1, math.pi / 2, 1,0,0, 0.2)
  29. end
  30. end
  31. pass:setColor(1,1,1)
  32. pass:text({
  33. 0xf0f0f0, 'Hold ',
  34. 0xf06000, 'left click',
  35. 0xf0f0f0, ' to\norbit the camera'
  36. }, 0, 0.5, 0.52, 0.1)
  37. pass:text({
  38. 0xf0f0f0, 'Scroll ',
  39. 0xf06000, 'wheel',
  40. 0xf0f0f0, ' to\nzoom in and out'
  41. }, 0.52, 0.5, 0, 0.1, math.pi/2, 0,1,0)
  42. pass:text({
  43. 0xf0f0f0, 'Hold ',
  44. 0xf06000, 'middle click',
  45. 0xf0f0f0, ' to\npan the camera'
  46. }, -0.52, 0.5, 0, 0.1, -math.pi/2, 0,1,0)
  47. pass:text({
  48. 0xf0f0f0, 'Hold down ',
  49. 0xf06000, 'left+middle',
  50. 0xf0f0f0, '\nto pan up and down'
  51. }, 0, 0.5, -0.52, 0.1, math.pi, 0,1,0)
  52. pass:setWireframe(true)
  53. pass:setColor(1, 1, 1, 0.1)
  54. pass:cube(0, 0.5, 0, 1.05, 0, 0,1,0, 'line')
  55. pass:torus(0, 1.28, 0, 0.75, 0.3, math.pi/2, 1,0,0, 14, 7)
  56. end
  57. cam.integrate() -- a shortcut for quick and dirty activation of orbit camera
  58. -- for a 'proper' integration into user's project, you would forward the callbacks yourself:
  59. --[[
  60. function lovr.draw(pass)
  61. cam.setCamera(pass) -- first action, before drawing the scene
  62. end
  63. function lovr.resize(width, height)
  64. cam.resize(width, height)
  65. end
  66. function lovr.mousemoved(x, y, dx, dy)
  67. cam.mousemoved(x, y, dx, dy)
  68. end
  69. function lovr.wheelmoved(dx, dy)
  70. cam.wheelmoved(dx, dy)
  71. end
  72. --]]