-
Notifications
You must be signed in to change notification settings - Fork 0
/
hands.lua
44 lines (40 loc) · 1.36 KB
/
hands.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local hands = {}
function hands:init()
self.models = {}
self.shader = lovr.graphics.newShader([[
vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
return projection * transform * vertex;
}
]], [[
vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
if (int(gl_FragCoord.x) % 10 != 7 || int(gl_FragCoord.y) % 10 != 3) discard;
return vec4(vec3(.08), .5);
}
]], { flags = { animated = true } })
end
function hands:update(dt)
for i, hand in ipairs({ 'left', 'right' }) do
if lovr.headset.isTracked(hand) and not self.models[hand] then
self.models[hand] = lovr.headset.newModel(hand, { animated = true })
end
end
end
function hands:draw()
lovr.graphics.setShader()
for i, hand in ipairs({ 'left', 'right' }) do
if lovr.headset.isTracked(hand) then
if lovr.headset.getDriver() == 'vrapi' and self.models[hand] and lovr.headset.animate(hand, self.models[hand]) then
lovr.graphics.setShader(self.shader)
self.models[hand]:draw(mat4(lovr.headset.getPose(hand)))
else
lovr.graphics.setBlendMode('alpha')
lovr.graphics.setColor(1, 1, 1, .5)
lovr.graphics.sphere(mat4(lovr.headset.getPose(hand)):scale(.015))
lovr.graphics.setColor(1, 1, 1, 1)
lovr.graphics.setBlendMode()
end
end
end
lovr.graphics.setShader()
end
return hands