-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.lua
More file actions
82 lines (74 loc) · 2.33 KB
/
camera.lua
File metadata and controls
82 lines (74 loc) · 2.33 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
local flux = require "libs.flux"
local camera = lovr.math.newMat4()
local defaultY = 22
local target = { x = 0, y = defaultY, z = 0 }
local scene = { width = 10, size = 10 }
local far = 555
local near = 222
function loadCamera(sceneImport)
scene = sceneImport
end
function aimCameraXZ(x,y, z)
target.x = x or 0
target.y = y or 0
target.z = z or 0
end
function updateCamera(dt)
flux.update(dt)
camera:identity()
camera:translate(lovr.math.vec3(target.x, 0, target.z))
camera:rotate(math.rad(180), 0, 1, 0)
camera:rotate(math.rad(45), 0, -1, 0)
camera:rotate(math.rad(-60), 1, 0, 0)
camera:translate(lovr.math.vec3(0, target.y, 0))
camera:target(vec3(camera), vec3(target.x, 0, target.z), vec3(0, 1, 0))
end
function drawCamera(pass)
local width, height = lovr.system.getWindowDimensions()
local ratio = width / height
local fov = math.rad(20)
local aspect = ratio
local light_projection = lovr.math.mat4():perspective(fov, aspect,near,far)
pass:setProjection(1, light_projection)
pass:setViewPose(1, camera)
end
function moveCamera(key)
local size = scene.size
local newPos = nil
local distanceFromEdge = 4
if key == "a" or key == "left" then
newPos = { x = -size / 2+distanceFromEdge, y = defaultY, z = -size / 2 +distanceFromEdge}
near =11
far = 35
end
if key == "d" or key == "right" then
newPos = { x = size / 2 -distanceFromEdge, y = defaultY, z = size / 2 -distanceFromEdge }
near = 11
far = 35
end
if key == "w" or key == "up" then
newPos = { x = size / 2 -distanceFromEdge, y = defaultY, z = -size / 2 +distanceFromEdge}
near = 11
far = 35
end
if key == "s" or key == "down" then
newPos = { x = -size / 2 +distanceFromEdge, y = defaultY, z = size / 2 -distanceFromEdge }
near = 11
far = 35
end
if key == "space" then
newPos = { x = 0, y = defaultY, z = 0 }
near = 11
far = 35
end
if key == "q" then
newPos = { x = 0, y = size * 3, z = 0 }
near = 222
far = 555
end
if newPos then
local speed = 44
local distance = vec3(target.x, target.y, target.z):distance(newPos.x,newPos.y,newPos.z)
flux.to(target, speed/distance, newPos)
end
end