-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
86 lines (69 loc) · 2.26 KB
/
main.lua
File metadata and controls
86 lines (69 loc) · 2.26 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require "camera"
require "utility"
local dir_light = require "directionalLight.directionalLight"
local scene = {
size = 150, height = 2
}
time = 1
-- in main.lua this would be: local dir_light = require('dir_light')
dir_light.load(2048)
monkey = lovr.graphics.newModel('monkey.obj')
function lovr.load()
lovr.graphics.setBackgroundColor(.1, .1, .1)
loadCamera(scene)
aimCameraXZ(0, 400, 0) --set where to look
end
function DrawScene(pass)
-- box
addBoxes(scene, pass, monkey)
pass:setColor(1, 1, 1)
pass:box(vec3(0), vec3(1.6))
local ss = scene.size/2
local sh = scene.height*.7
pass:box(vec3(ss-sh,0,0), vec3(sh))
pass:box(vec3(-ss+sh,0,0), vec3(sh))
pass:box(vec3(0,0,ss-sh), vec3(sh))
pass:box(vec3(-0,0,-ss+sh), vec3(sh))
--box is like a filled in so using it instead of plane
pass:setColor(0.8, 0.8, 0.8)
-- pass:box(vec3(0, 0, 0), vec3(10, 0.01, 10))
pass:plane(vec3(0, 0, 0), vec2(scene.size, scene.size), quat(math.pi * 0.5, -1, 0, 0))
--pass:plane(vec3(0, -0.1, 0), vec2(scene.size, scene.size), quat(math.pi * 0.5, 1, 0, 0))
-- pass:box(vec3(0,-1.5,0), vec3(scene.size,0.1,scene.size))
end
function lovr.update(dt)
updateCamera(dt)
if lovr.system.isKeyDown('t') then
time = time + dt*2
end
end
function lovr.draw(pass)
local t = time * 0.004
local tDeg = math.deg(t)-3+math.pi/2
-- tDeg = 45
local xPos = math.sin(tDeg)*scene.size/2
local yPos = math.cos(tDeg)*scene.size/2
drawCamera(pass)
-- Flip depth clear/test when using regular perspective matrix for camera
pass:setClear({ depth = 1 })
pass:setDepthTest('lequal')
local lightPosition = vec3(xPos,yPos,0)
local lightTarget = vec3(0,0,0)
local lightDirection = (lightTarget - lightPosition):normalize()
local view = pass:getViewPose(1, mat4(), true)
local proj = pass:getProjection(1, mat4())
dir_light.setLightMatrix(lightDirection, view, proj)
-- the most important part:
local gpass = dir_light.getPass()
DrawScene(gpass)
dir_light.setShader(pass)
DrawScene(pass)
pass:setShader()
pass:setColor(1, 0.8, 0.5)
pass:cone(lightPosition, lightPosition - lightDirection * 10, 10)
dir_light.debugDraw(pass)
return lovr.graphics.submit(gpass, pass)
end
function lovr.keypressed(key)
moveCamera(key)
end