From 8bb877ad57e7e41d928408e81f4e8cca63e171f7 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Sun, 1 Nov 2020 13:04:05 -0600 Subject: add basic node types --- demo/Node.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 demo/Node.lua (limited to 'demo/Node.lua') diff --git a/demo/Node.lua b/demo/Node.lua new file mode 100644 index 0000000..46c372a --- /dev/null +++ b/demo/Node.lua @@ -0,0 +1,47 @@ +local Vector = require('Vector') +local Matrix = require('Matrix') + +local Node = {} + +Node.prototype = {} +Node.prototype.updateTransform = function(self) + honey.cglm.mat4.identity(self.transform.array) + + self.transform:scale(self.scale) + + self.transform:rotate(Vector.Vec3.ZERO, Vector.Vec3.Z_UNIT, self.rotation:at(2)) + self.transform:rotate(Vector.Vec3.ZERO, Vector.Vec3.Y_UNIT, self.rotation:at(1)) + self.transform:rotate(Vector.Vec3.ZERO, Vector.Vec3.X_UNIT, self.rotation:at(0)) + + self.transform:translate(self.position) + + if parent ~= nil then + self.transform:mul(self.parent.transform) + end +end + +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Node.mt = {} +Node.mt.__index = Node.prototype + +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Node.new = function(parent, position, rotation, scale) + local node = {} + + setmetatable(node, Node.mt) + + node.parent = parent + + node.position = position + node.rotation = rotation + node.scale = scale + + node.transform = Matrix.Mat4.eye() + node:updateTransform() + + return node +end + +return Node -- cgit v1.2.1