Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
pointer = require 'pointer'

local function drawBox(box, color)
cubeSize = 0.2

local function drawCube(box, color)
local x, y, z = box:getPosition()
local dx, dy, dz = box:getShapeList()[1]:getDimensions()
lovr.graphics.setColor(color)
lovr.graphics.box('fill', x, y, z, dx, dy, dz, box:getOrientation())
lovr.graphics.cube('fill', x, y, z, cubeSize)
end

local function refreshSource()
pointer:setSource(lovr.headset.getControllers()[1] or lovr.headset)
end

function lovr.load()
-- Make a little physics scene
world = lovr.physics.newWorld()
ground = world:newBoxCollider(0, 0, 0, 5, .001, 5)
ground:setKinematic(true)
box = world:newBoxCollider(0, 1, 0, .5)
box = world:newBoxCollider(0, 1.5, -1, cubeSize)
box:setKinematic(true)

-- Initialize the pointer
pointer:init({ source = lovr.headset, world = world })
pointer:init({ source = pointer.handWrapper.new("hand/left"), world = world })
end

function lovr.update(dt)
Expand All @@ -30,11 +27,9 @@ end
function lovr.draw()
local hit = pointer:getHit()

drawBox(ground, { 30, 30, 30 })

-- Highlight that darn box if we're pointing at it
local boxColor = (hit and hit.collider == box) and { 50, 100, 200 } or { 20, 70, 170 }
drawBox(box, boxColor)
local boxColor = (hit and hit.collider == box) and { 0.50, 0.100, 0.200 } or { 0.20, 0.70, 0.170 }
drawCube(box, boxColor)

lovr.graphics.setColor(255, 255, 255)

Expand All @@ -50,6 +45,3 @@ function lovr.draw()
lovr.graphics.line(hit.x, hit.y, hit.z, hit.x + hit.nx * .1, hit.y + hit.ny * .1, hit.z + hit.nz * .1)
end
end

lovr.controlleradded = refreshSource
lovr.controllerremoved = refreshSource
18 changes: 18 additions & 0 deletions pointer.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
local pointer = {}
pointer.__index = pointer

pointer.handWrapper = {}
pointer.handWrapper.__index = pointer.handWrapper

function pointer.handWrapper.new(hand)
local self = setmetatable({}, pointer.handWrapper)
self.hand = hand
return self
end

function pointer.handWrapper:getPosition()
return lovr.headset.getPosition(self.hand)
end

function pointer.handWrapper:getOrientation()
return lovr.headset.getOrientation(self.hand)
end


local unpack = unpack or table.unpack

function pointer.new(options)
Expand Down