diff options
author | sanine-a <sanine.not@pm.me> | 2020-11-01 13:04:05 -0600 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-11-01 13:04:05 -0600 |
commit | 8bb877ad57e7e41d928408e81f4e8cca63e171f7 (patch) | |
tree | 5cc4a79a492bd3c7224070b3bd00aba512a9b053 /demo/Node.lua | |
parent | cf75cc42cd11c31ff9402751bec98ba607fd820f (diff) |
add basic node types
Diffstat (limited to 'demo/Node.lua')
-rw-r--r-- | demo/Node.lua | 47 |
1 files changed, 47 insertions, 0 deletions
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 |