summaryrefslogtreecommitdiff
path: root/demo/Camera.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-11-01 13:04:05 -0600
committersanine-a <sanine.not@pm.me>2020-11-01 13:04:05 -0600
commit8bb877ad57e7e41d928408e81f4e8cca63e171f7 (patch)
tree5cc4a79a492bd3c7224070b3bd00aba512a9b053 /demo/Camera.lua
parentcf75cc42cd11c31ff9402751bec98ba607fd820f (diff)
add basic node types
Diffstat (limited to 'demo/Camera.lua')
-rw-r--r--demo/Camera.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/demo/Camera.lua b/demo/Camera.lua
new file mode 100644
index 0000000..de14b6c
--- /dev/null
+++ b/demo/Camera.lua
@@ -0,0 +1,34 @@
+local Vector = require('Vector')
+local Matrix = require('Matrix')
+local Node = require('Node')
+
+local Camera = {}
+
+Camera.prototype = {}
+setmetatable(Camera.prototype, { __index = Node.prototype })
+
+Camera.prototype.updateView = function(self)
+ self.basis = self.transform:basis()
+ Matrix.Mat4.look(self.position, self.basis.z, self.basis.y, self.view)
+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 = Matrix.Mat4.new()
+ camera:updateView()
+ camera.projection = Matrix.Mat4.perspective(fov, aspect, near, far)
+
+ return camera
+end
+
+return Camera
+