main.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require "camera"
  2. require "utility"
  3. local dir_light = require "directionalLight.directionalLight"
  4. local scene = {
  5. size = 150, height = 4
  6. }
  7. -- in main.lua this would be: local dir_light = require('dir_light')
  8. dir_light.load(2048)
  9. monkey = lovr.graphics.newModel('monkey.obj')
  10. function lovr.load()
  11. lovr.graphics.setBackgroundColor(.1, .1, .1)
  12. loadCamera(scene)
  13. aimCameraXZ(0, 400, 0) --set where to look
  14. end
  15. function DrawScene(pass)
  16. -- box
  17. addBoxes(scene, pass, monkey)
  18. pass:setColor(1, 1, 1)
  19. pass:box(vec3(0), vec3(1.6))
  20. local ss = scene.size/2
  21. local sh = scene.height*.7
  22. pass:box(vec3(ss-sh,0,0), vec3(sh))
  23. pass:box(vec3(-ss+sh,0,0), vec3(sh))
  24. pass:box(vec3(0,0,ss-sh), vec3(sh))
  25. pass:box(vec3(-0,0,-ss+sh), vec3(sh))
  26. --box is like a filled in so using it instead of plane
  27. pass:setColor(0.8, 0.8, 0.8)
  28. -- pass:box(vec3(0, 0, 0), vec3(10, 0.01, 10))
  29. pass:plane(vec3(0, 0, 0), vec2(scene.size, scene.size), quat(math.pi * 0.5, -1, 0, 0))
  30. --pass:plane(vec3(0, -0.1, 0), vec2(scene.size, scene.size), quat(math.pi * 0.5, 1, 0, 0))
  31. -- pass:box(vec3(0,-1.5,0), vec3(scene.size,0.1,scene.size))
  32. end
  33. function lovr.update(dt)
  34. updateCamera(dt)
  35. end
  36. function lovr.draw(pass)
  37. local t = lovr.timer.getTime() * 0.004
  38. local tDeg = math.deg(t)-1.78
  39. -- tDeg = 45
  40. local xPos = math.sin(tDeg)*scene.size/2
  41. local yPos = math.cos(tDeg)*scene.size/2
  42. drawCamera(pass)
  43. local cameraPosition = vec3(xPos,yPos,0)
  44. local cameraTarget = vec3(0,0,0)
  45. dir_light.setOrthographic(scene,tDeg)
  46. dir_light.setPose(cameraPosition,cameraTarget)
  47. --debug mode
  48. --pass:fill(dir_light.texture)
  49. -- the most important part:
  50. local gpass = dir_light.getPass()
  51. --scene(gpass)
  52. DrawScene(gpass)
  53. dir_light.debugDraw(pass)
  54. dir_light.setShader(pass)
  55. --scene(pass)
  56. DrawScene(pass)
  57. --createRotatedBoundingOrthographicView(tDeg,scene,pass)
  58. return lovr.graphics.submit(gpass, pass)
  59. end
  60. function lovr.keypressed(key) moveCamera(key) end
  61. -- this would be end of main.lua improting this lib