main.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. local mirrorPose = lovr.math.newMat4(0, 1.65, -0.75)
  2. local inverseMirrorPose = lovr.math.newMat4(mirrorPose):invert()
  3. local mirrorSize = vector(0.6, 1.2, 1)
  4. local function draw_mirror(pass, outline)
  5. pass:push()
  6. pass:transform(mirrorPose)
  7. pass:scale(mirrorSize)
  8. pass:plane(nil, outline and 'line' or 'fill')
  9. pass:pop()
  10. end
  11. local function draw_scene(pass)
  12. pass:setColor(0x203c56)
  13. pass:box(0, 0, 0, 4, 0.05, 4) -- floor
  14. pass:setColor(0x544e68)
  15. pass:box(0, 1, -0.5, 1, 0.1, 0.4) -- a table
  16. pass:setColor(0xffaa5e)
  17. pass:cylinder(0.2, 1.2, -0.4, .06,0.3, math.pi/2, 1,0,0, true, 0,2*math.pi, 8) -- a vase
  18. pass:setColor(0xffd4a3)
  19. pass:box(0.1, 1.1, -0.6, 0.12, 0.1, 0.12) -- a jewelry box
  20. pass:push()
  21. pass:transform(lovr.headset.getPose())
  22. pass:push()
  23. pass:scale(.09, .12, .11)
  24. pass:setColor(0x8d697a)
  25. pass:sphere() -- head
  26. pass:pop()
  27. pass:push()
  28. pass:translate(0, -0.02, -0.15)
  29. pass:rotate(-0.2, 1,0,0)
  30. pass:scale(0.015, 0.02, 0.03)
  31. pass:setColor(0xd08159)
  32. pass:cylinder() -- nose
  33. pass:pop()
  34. pass:pop()
  35. for _, hand in ipairs(lovr.headset.getHands()) do
  36. local skeleton = lovr.headset.getSkeleton(hand)
  37. if skeleton then
  38. for _, bone in ipairs(skeleton) do
  39. local x, y, z, _, angle, ax, ay, az = unpack(bone)
  40. pass:box(x, y, z, 0.017, 0.012, 0.019, angle, ax, ay, az) -- hand bone
  41. end
  42. else
  43. pass:push()
  44. pass:transform(lovr.headset.getPose(hand))
  45. pass:scale(.03, .07, .09)
  46. pass:box() -- palm
  47. pass:pop()
  48. end
  49. end
  50. end
  51. function lovr.load()
  52. lovr.graphics.setBackgroundColor(0x0d2b45)
  53. end
  54. function lovr.draw(pass)
  55. pass:setCullMode('back')
  56. draw_scene(pass)
  57. pass:setColor(0xffecd6)
  58. draw_mirror(pass, true) -- mirror frame
  59. pass:push()
  60. pass:setStencilWrite('replace', 1)
  61. pass:setColorWrite(false)
  62. pass:setDepthWrite(false)
  63. draw_mirror(pass)
  64. pass:setDepthWrite(true)
  65. pass:setColorWrite(true)
  66. pass:setStencilWrite()
  67. pass:setStencilTest('equal', 1)
  68. pass:transform(mirrorPose)
  69. pass:scale(1, 1, -1) -- after Z-flip all triangles will change their windings
  70. pass:transform(inverseMirrorPose)
  71. pass:setWinding('clockwise') -- invert the winding to account for the flip
  72. draw_scene(pass)
  73. pass:setWinding('counterclockwise')
  74. pass:setStencilTest()
  75. pass:pop()
  76. pass:setColor(0x000000, 0.3)
  77. draw_mirror(pass, false) -- glass tint
  78. end