Browse Source

Port locomotion examples;

bjorn 3 years ago
parent
commit
f88fcd0fee

+ 9 - 8
examples/Locomotion/Basic_Thumbsticks/main.lua

@@ -20,6 +20,8 @@ local motion = {
   walkingSpeed = 4,
   walkingSpeed = 4,
 }
 }
 
 
+lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
+
 function motion.smooth(dt)
 function motion.smooth(dt)
   if lovr.headset.isTracked('right') then
   if lovr.headset.isTracked('right') then
     local x, y = lovr.headset.getAxis('right', 'thumbstick')
     local x, y = lovr.headset.getAxis('right', 'thumbstick')
@@ -88,18 +90,17 @@ function lovr.update(dt)
   end
   end
 end
 end
 
 
-function lovr.draw()
-  lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
-  lovr.graphics.transform(mat4(motion.pose):invert())
+function lovr.draw(pass)
+  pass:transform(mat4(motion.pose):invert())
   -- Render hands
   -- Render hands
-  lovr.graphics.setColor(1,1,1)
+  pass:setColor(1,1,1)
   local radius = 0.05
   local radius = 0.05
   for _, hand in ipairs(lovr.headset.getHands()) do
   for _, hand in ipairs(lovr.headset.getHands()) do
     -- Whenever pose of hand or head is used, need to account for VR movement
     -- Whenever pose of hand or head is used, need to account for VR movement
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseVR = mat4(motion.pose):mul(poseRW)
     local poseVR = mat4(motion.pose):mul(poseRW)
     poseVR:scale(radius)
     poseVR:scale(radius)
-    lovr.graphics.sphere(poseVR)
+    pass:sphere(poseVR)
   end
   end
   -- Some scenery
   -- Some scenery
   lovr.math.setRandomSeed(0)
   lovr.math.setRandomSeed(0)
@@ -111,11 +112,11 @@ function lovr.draw()
     local x = math.cos(goldenAngle * i) * r
     local x = math.cos(goldenAngle * i) * r
     local y = math.sin(goldenAngle * i) * r
     local y = math.sin(goldenAngle * i) * r
     if lovr.math.random() < 0.05 then
     if lovr.math.random() < 0.05 then
-      lovr.graphics.setColor(0.5, 0, 0)
+      pass:setColor(0.5, 0, 0)
     else
     else
       local shade = 0.1 + 0.3 * lovr.math.random()
       local shade = 0.1 + 0.3 * lovr.math.random()
-      lovr.graphics.setColor(shade, shade, shade)
+      pass:setColor(shade, shade, shade)
     end
     end
-    lovr.graphics.cylinder(x, 0, y,  0.05, math.pi / 2, 1,0,0, 1, 1)
+    pass:cylinder(x, 0, y,  1,0.05, math.pi / 2, 1,0,0)
   end
   end
 end
 end

+ 9 - 9
examples/Locomotion/Space_Stretch/main.lua

@@ -8,6 +8,7 @@ local motion = {
 }
 }
 
 
 local palette = {0x0d2b45, 0x203c56, 0x544e68, 0x8d697a, 0xd08159, 0xffaa5e, 0xffd4a3, 0xffecd6}
 local palette = {0x0d2b45, 0x203c56, 0x544e68, 0x8d697a, 0xd08159, 0xffaa5e, 0xffd4a3, 0xffecd6}
+lovr.graphics.setBackgroundColor(palette[1])
 
 
 
 
 function lovr.update(dt)
 function lovr.update(dt)
@@ -57,31 +58,30 @@ function lovr.update(dt)
 end
 end
 
 
 
 
-function lovr.draw()
-  lovr.graphics.setBackgroundColor(palette[1])
-  lovr.graphics.transform(mat4(motion.pose):invert())
+function lovr.draw(pass)
+  pass:transform(mat4(motion.pose):invert())
   -- Render hands
   -- Render hands
   for _, hand in ipairs(lovr.headset.getHands()) do
   for _, hand in ipairs(lovr.headset.getHands()) do
     -- Whenever pose of hand or head is used, need to account for VR movement
     -- Whenever pose of hand or head is used, need to account for VR movement
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseVR = mat4(motion.pose):mul(poseRW)
     local poseVR = mat4(motion.pose):mul(poseRW)
     if lovr.headset.isDown(hand, 'grip') then
     if lovr.headset.isDown(hand, 'grip') then
-      lovr.graphics.setColor(palette[6])
+      pass:setColor(palette[6])
     else
     else
-      lovr.graphics.setColor(palette[8])
+      pass:setColor(palette[8])
     end
     end
     poseVR:scale(0.02)
     poseVR:scale(0.02)
-    lovr.graphics.sphere(poseVR)
+    pass:sphere(poseVR)
   end
   end
   -- An example scene
   -- An example scene
   local t = lovr.timer.getTime()
   local t = lovr.timer.getTime()
-  lovr.graphics.setCullingEnabled(true)
+  pass:setCullMode('back')
   local step = 0.5
   local step = 0.5
   for x = -5, 5, step do
   for x = -5, 5, step do
     for z = -5, 5, step do
     for z = -5, 5, step do
       local y = 0.5 * math.sin(t * 0.2 + (x * 0.5)^2 + (z * 0.5)^2)
       local y = 0.5 * math.sin(t * 0.2 + (x * 0.5)^2 + (z * 0.5)^2)
-      lovr.graphics.setColor(palette[2 + math.floor(y * 10) % (#palette - 1)])
-      lovr.graphics.sphere(x, y, z, step / 2)
+      pass:setColor(palette[2 + math.floor(y * 10) % (#palette - 1)])
+      pass:sphere(x, y, z, step / 2)
     end
     end
   end
   end
 end
 end

+ 20 - 19
examples/Locomotion/Teleportation_Colliders/main.lua

@@ -20,9 +20,11 @@ local motion = {
   teleportCurve = lovr.math.newCurve(3),
   teleportCurve = lovr.math.newCurve(3),
 }
 }
 
 
+lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
+
 function motion.teleport(dt)
 function motion.teleport(dt)
   -- Teleportation determining target position and executing jump when triggered
   -- Teleportation determining target position and executing jump when triggered
-  local handPose = mat4(motion.pose):mul(mat4(lovr.headset.getPose('right')))
+  local handPose = mat4(motion.pose):mul(mat4(lovr.headset.getPose('hand/right/point')))
   local handPosition = vec3(handPose)
   local handPosition = vec3(handPose)
   local handDirection = quat(handPose):direction()
   local handDirection = quat(handPose):direction()
   -- Intersect with world geometry by casting a ray
   -- Intersect with world geometry by casting a ray
@@ -81,22 +83,22 @@ function motion.teleport(dt)
   motion.thumbstickCooldown = motion.thumbstickCooldown - dt
   motion.thumbstickCooldown = motion.thumbstickCooldown - dt
 end
 end
 
 
-function motion.drawTeleport()
+function motion.drawTeleport(pass)
   if lovr.headset.isTracked('right') then
   if lovr.headset.isTracked('right') then
     -- Teleport target and curve
     -- Teleport target and curve
-    lovr.graphics.setColor(1, 1, 1, 0.1)
+    pass:setColor(1, 1, 1, 0.1)
     if motion.teleportValid then
     if motion.teleportValid then
-      lovr.graphics.setColor(1, 1, 0)
-      lovr.graphics.cylinder(motion.targetPosition, 0.05, math.pi/2,  1,0,0,  0.4, 0.4)
-      lovr.graphics.setColor(1, 1, 1)
+      pass:setColor(1, 1, 0)
+      pass:cylinder(motion.targetPosition, .4,0.05, math.pi/2,  1,0,0)
+      pass:setColor(1, 1, 1)
     end
     end
-    lovr.graphics.setLineWidth(4)
-    lovr.graphics.line(motion.teleportCurve:render(30))
+    --pass:setLineWidth(4)
+    pass:line(motion.teleportCurve:render(30))
   end
   end
   -- Teleport blink, modeled as gaussian function
   -- Teleport blink, modeled as gaussian function
   local blinkAlpha = math.exp(-(motion.blinkStopwatch/ 0.25 / motion.blinkTime)^2)
   local blinkAlpha = math.exp(-(motion.blinkStopwatch/ 0.25 / motion.blinkTime)^2)
-  lovr.graphics.setColor(0,0,0, blinkAlpha)
-  lovr.graphics.fill()
+  pass:setColor(0,0,0, blinkAlpha)
+  pass:fill()
 end
 end
 
 
 
 
@@ -141,27 +143,26 @@ function lovr.update(dt)
   motion.teleport(dt)
   motion.teleport(dt)
 end
 end
 
 
-function lovr.draw()
-  lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
-  lovr.graphics.transform(mat4(motion.pose):invert())
+function lovr.draw(pass)
+  pass:transform(mat4(motion.pose):invert())
   -- Render hands
   -- Render hands
-  lovr.graphics.setColor(1, 1, 1)
+  pass:setColor(1, 1, 1)
   local radius = 0.04
   local radius = 0.04
   for _, hand in ipairs(lovr.headset.getHands()) do
   for _, hand in ipairs(lovr.headset.getHands()) do
     -- Whenever pose of hand or head is used, need to account for VR movement
     -- Whenever pose of hand or head is used, need to account for VR movement
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseVR = mat4(motion.pose):mul(poseRW)
     local poseVR = mat4(motion.pose):mul(poseRW)
     poseVR:scale(radius)
     poseVR:scale(radius)
-    lovr.graphics.sphere(poseVR)
+    pass:sphere(poseVR)
   end
   end
   -- Render columns
   -- Render columns
   for i, column in ipairs(columns) do
   for i, column in ipairs(columns) do
     local x,y,z, angle, ax,ay,az = column.collider:getPose()
     local x,y,z, angle, ax,ay,az = column.collider:getPose()
     local l, r = column.shape:getLength(), column.shape:getRadius()
     local l, r = column.shape:getLength(), column.shape:getRadius()
-    lovr.graphics.setColor(unpack(column.color))
-    lovr.graphics.cylinder(x,y,z, l, angle, ax,ay,az, r, r, true, 20)
+    pass:setColor(unpack(column.color))
+    pass:cylinder(x,y,z, r,l, angle, ax,ay,az, true, 0,2*math.pi, 20)
   end
   end
   -- Teleportation curve and target, rendering of blinking overlay
   -- Teleportation curve and target, rendering of blinking overlay
-  motion.drawTeleport()
-  lovr.graphics.setColor(1, 1, 1)
+  motion.drawTeleport(pass)
+  pass:setColor(1, 1, 1)
 end
 end

+ 20 - 19
examples/Locomotion/Teleportation_Flat/main.lua

@@ -17,9 +17,11 @@ local motion = {
   teleportCurve = lovr.math.newCurve(3),
   teleportCurve = lovr.math.newCurve(3),
 }
 }
 
 
+lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
+
 function motion.teleport(dt)
 function motion.teleport(dt)
   -- Teleportation determining target position and executing jump when triggered
   -- Teleportation determining target position and executing jump when triggered
-  local handPose = mat4(motion.pose):mul(mat4(lovr.headset.getPose('right')))
+  local handPose = mat4(motion.pose):mul(mat4(lovr.headset.getPose('hand/right/point')))
   local handPosition = vec3(handPose)
   local handPosition = vec3(handPose)
   local handDirection = quat(handPose):direction()
   local handDirection = quat(handPose):direction()
   -- Intersect with ground plane
   -- Intersect with ground plane
@@ -62,20 +64,20 @@ function motion.teleport(dt)
   motion.thumbstickCooldown = motion.thumbstickCooldown - dt
   motion.thumbstickCooldown = motion.thumbstickCooldown - dt
 end
 end
 
 
-function motion.drawTeleport()
+function motion.drawTeleport(pass)
   -- Teleport target and curve
   -- Teleport target and curve
-  lovr.graphics.setColor(1, 1, 1, 0.1)
+  pass:setColor(1, 1, 1, 0.1)
   if motion.teleportValid then
   if motion.teleportValid then
-    lovr.graphics.setColor(1, 1, 0)
-    lovr.graphics.cylinder(motion.targetPosition, 0.05, math.pi/2,  1,0,0,  0.4, 0.4)
-    lovr.graphics.setColor(1, 1, 1)
+    pass:setColor(1, 1, 0)
+    pass:cylinder(motion.targetPosition, 0.4,0.05, math.pi/2,  1,0,0)
+    pass:setColor(1, 1, 1)
   end
   end
-  lovr.graphics.setLineWidth(4)
-  lovr.graphics.line(motion.teleportCurve:render(30))
+  --lovr.graphics.setLineWidth(4)
+  pass:line(motion.teleportCurve:render(30))
   -- Teleport blink, modeled as gaussian function
   -- Teleport blink, modeled as gaussian function
   local blinkAlpha = math.exp(-(motion.blinkStopwatch/ 0.25 / motion.blinkTime)^2)
   local blinkAlpha = math.exp(-(motion.blinkStopwatch/ 0.25 / motion.blinkTime)^2)
-  lovr.graphics.setColor(0,0,0, blinkAlpha)
-  lovr.graphics.fill()
+  pass:setColor(0,0,0, blinkAlpha)
+  pass:fill()
 end
 end
 
 
 
 
@@ -84,18 +86,17 @@ function lovr.update(dt)
   motion.teleport(dt)
   motion.teleport(dt)
 end
 end
 
 
-function lovr.draw()
-  lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
-  lovr.graphics.transform(mat4(motion.pose):invert())
+function lovr.draw(pass)
+  pass:transform(mat4(motion.pose):invert())
   -- Render hands
   -- Render hands
-  lovr.graphics.setColor(1,1,1)
+  pass:setColor(1,1,1)
   local radius = 0.04
   local radius = 0.04
   for _, hand in ipairs(lovr.headset.getHands()) do
   for _, hand in ipairs(lovr.headset.getHands()) do
     -- Whenever pose of hand or head is used, need to account for VR movement
     -- Whenever pose of hand or head is used, need to account for VR movement
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseVR = mat4(motion.pose):mul(poseRW)
     local poseVR = mat4(motion.pose):mul(poseRW)
     poseVR:scale(radius)
     poseVR:scale(radius)
-    lovr.graphics.sphere(poseVR)
+    pass:sphere(poseVR)
   end
   end
   -- Some scenery
   -- Some scenery
   lovr.math.setRandomSeed(0)
   lovr.math.setRandomSeed(0)
@@ -107,12 +108,12 @@ function lovr.draw()
     local x = math.cos(goldenAngle * i) * r
     local x = math.cos(goldenAngle * i) * r
     local y = math.sin(goldenAngle * i) * r
     local y = math.sin(goldenAngle * i) * r
     if lovr.math.random() < 0.05 then
     if lovr.math.random() < 0.05 then
-      lovr.graphics.setColor(0.8, 0.5, 0)
+      pass:setColor(0.8, 0.5, 0)
     else
     else
       local shade = 0.1 + 0.3 * lovr.math.random()
       local shade = 0.1 + 0.3 * lovr.math.random()
-      lovr.graphics.setColor(shade, shade, shade)
+      pass:setColor(shade, shade, shade)
     end
     end
-    lovr.graphics.cylinder(x, -0.01, y,  0.02, math.pi / 2, 1,0,0, 1, 1)
+    pass:cylinder(x, -0.01, y,  1,0.02, math.pi / 2, 1,0,0)
   end
   end
-  motion.drawTeleport()
+  motion.drawTeleport(pass)
 end
 end

+ 8 - 8
examples/Locomotion/Walking_In_Place/main.lua

@@ -67,19 +67,19 @@ function lovr.update(dt)
   motion.walkinplace(dt)
   motion.walkinplace(dt)
 end
 end
 
 
-function lovr.draw()
+function lovr.draw(pass)
   lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
   lovr.graphics.setBackgroundColor(0.1, 0.1, 0.1)
-  lovr.graphics.print(string.format('%2.3f', motion.speed), 19, 1, -15, 0.05)
-  lovr.graphics.transform(mat4(motion.pose):invert())
+  pass:text(string.format('%2.3f', motion.speed), 19, 1, -15, 0.05)
+  pass:transform(mat4(motion.pose):invert())
   -- Render hands
   -- Render hands
-  lovr.graphics.setColor(1,1,1)
+  pass:setColor(1,1,1)
   local radius = 0.04
   local radius = 0.04
   for _, hand in ipairs(lovr.headset.getHands()) do
   for _, hand in ipairs(lovr.headset.getHands()) do
     -- Whenever pose of hand or head is used, need to account for VR movement
     -- Whenever pose of hand or head is used, need to account for VR movement
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseRW = mat4(lovr.headset.getPose(hand))
     local poseVR = mat4(motion.pose):mul(poseRW)
     local poseVR = mat4(motion.pose):mul(poseRW)
     poseVR:scale(radius)
     poseVR:scale(radius)
-    lovr.graphics.sphere(poseVR)
+    pass:sphere(poseVR)
   end
   end
   -- Some scenery
   -- Some scenery
   lovr.math.setRandomSeed(0)
   lovr.math.setRandomSeed(0)
@@ -91,11 +91,11 @@ function lovr.draw()
     local x = math.cos(goldenAngle * i) * r
     local x = math.cos(goldenAngle * i) * r
     local y = math.sin(goldenAngle * i) * r
     local y = math.sin(goldenAngle * i) * r
     if lovr.math.random() < 0.05 then
     if lovr.math.random() < 0.05 then
-      lovr.graphics.setColor(0.5, 0, 0)
+      pass:setColor(0.5, 0, 0)
     else
     else
       local shade = 0.1 + 0.3 * lovr.math.random()
       local shade = 0.1 + 0.3 * lovr.math.random()
-      lovr.graphics.setColor(shade, shade, shade)
+      pass:setColor(shade, shade, shade)
     end
     end
-    lovr.graphics.cylinder(x, -0.01, y,  0.02, math.pi / 2, 1,0,0, 1, 1)
+    pass:cylinder(x, -0.01, y,  1,0.02, math.pi / 2, 1,0,0)
   end
   end
 end
 end