-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
72 lines (55 loc) · 1.62 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
shader = require 'shader'
function lovr.load()
camx, camy, camz = 0,2,5
tx,ty,tz = 0,0,0
lx,ly,lz = 0,-0.5,3
ldist=2
angle = 0
anglel = 0
local camfrom = lovr.math.vec3(camx,camy,camz)
local camto = lovr.math.vec3(tx,ty,tz)
local camup = lovr.math.vec3(0,1,0)
local cammat = lovr.math.mat4()
cammat:lookAt(camfrom,camto,camup)
local camme = lovr.math.mat4()
camme:target(camfrom,camto,camup)
lovr.graphics.setViewPose(1,cammat,true)
shader:send('lightPos', {camx,camy,camz})
matrix = camme
keypress = false
end
function lovr.keypressed(key)
if key=='space' then keypress = true end
end
function lovr.keyreleased(key)
if key=='space' then keypress = false end
end
function lovr.update(dt)
if keypress then
angle = angle + dt
end
anglel = anglel + dt
lz = ldist * math.sin(anglel) * -1.0
ly = -.5
lx = ldist * math.cos(anglel)
shader:send('lightPos', {lx,ly,lz})
shader:send('viewPos',{camx,camy,camz})
end
function lovr.draw()
lovr.graphics.setShader(shader)
lovr.graphics.setColor(1,1,1,1)
lovr.graphics.cube('fill',
tx,ty,tz,
2,
angle,0,1,0)
lovr.graphics.setColor(0.5,0.5,1,1)
lovr.graphics.cube('fill',
tx,ty-6,tz-3,
8,
0,0,1,0)
lovr.graphics.setColor(1,1,1,1)
lovr.graphics.cube('fill',
lx,ly,lz,
.25,
anglel,0,1,0)
end