Browse Source

Dragging -- now with Rotation!;

bjorn 3 years ago
parent
commit
6f1133d45d
2 changed files with 30 additions and 0 deletions
  1. 29 0
      examples/Interaction/Dragging_with_Rotation/main.lua
  2. 1 0
      examples/init.lua

+ 29 - 0
examples/Interaction/Dragging_with_Rotation/main.lua

@@ -0,0 +1,29 @@
+function lovr.load()
+  boxMatrix = lovr.math.newMat4() --inialize box
+  boxMatrix:set(
+    vec3(0,1,-1), --global position
+    vec3(0.25,0.25,0.25), --scale
+    quat(0,0,0,0) --global rotation
+  )
+
+  offset = lovr.math.newMat4() --initialize offset matrix
+end
+
+function lovr.update(dt)
+  if lovr.headset.wasPressed('left','trigger') then
+    offset:set(mat4(lovr.headset.getPose('left')):invert() * boxMatrix)
+  end
+
+  if lovr.headset.isDown('left','trigger') then
+    boxMatrix:set(mat4(lovr.headset.getPose('left')) * (offset))
+  end
+end
+
+function lovr.draw()
+  lovr.graphics.box('line', boxMatrix)
+
+  for i, hand in ipairs(lovr.headset.getHands()) do
+    local x, y, z = lovr.headset.getPosition(hand)
+    lovr.graphics.sphere(x, y, z, .01)
+  end
+end

+ 1 - 0
examples/init.lua

@@ -11,6 +11,7 @@ return {
   'Interaction/Pointer_UI',
   'Interaction/Physics_Pointer',
   'Interaction/Dragging',
+  'Interaction/Dragging_with_Rotation',
   'Interaction/Controller_Models',
   'Interaction/Hand_Tracking',
   'Locomotion/Basic_Thumbsticks',