summaryrefslogtreecommitdiff
path: root/demo/Camera.lua
blob: 4f5c1fe0eddbc43940b0b014111d0ecb47d21c78 (plain)
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
local Node = require('Node')

local Camera = {}

Camera.prototype = {}
setmetatable(Camera.prototype, { __index = Node.prototype })

Camera.prototype.updateView = function(self)
   self.basis = self.transform:basis()
   self.view:look(self.position, self.basis.z, self.basis.y)
end

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Camera.mt = {}
Camera.mt.__index = Camera.prototype

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Camera.new = function(parent, position, rotation, scale, fov, aspect, near, far)
   local camera = Node.new(parent, position, rotation, scale)
   setmetatable(camera, Camera.mt)

   camera.view = honey.glm.mat4()
   camera:updateView()
   camera.projection = honey.glm.mat4()
   camera.projection:perspective(fov, aspect, near, far)

   return camera
end

return Camera