diff options
author | sanine-a <sanine.not@pm.me> | 2020-11-08 09:46:02 -0600 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-11-08 09:46:02 -0600 |
commit | c00400ce832f2ab81fdef0ecdf6820a08e596eae (patch) | |
tree | c3afc529f43949c800e774b114ebffa10a37d3f2 /demo/Node.lua | |
parent | 94572182ea873d5dadbc8428330d4c00eead2c80 (diff) |
fix transform order and add drawing cascade
Diffstat (limited to 'demo/Node.lua')
-rw-r--r-- | demo/Node.lua | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/demo/Node.lua b/demo/Node.lua index 08916dd..ffb2aa5 100644 --- a/demo/Node.lua +++ b/demo/Node.lua @@ -8,16 +8,16 @@ Node.prototype = {} Node.prototype.updateTransform = function(self) honey.cglm.mat4.identity(self.transform.array) - self.transform:scale(self.scale) + self.transform:translate(self.position) 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) + self.transform:scale(self.scale) if self.parent ~= nil then - self.transform:mul(self.parent.transform, self.transform) + self.parent.transform:mul(self.transform, self.transform) end for _, child in ipairs(self.children) do @@ -25,20 +25,27 @@ Node.prototype.updateTransform = function(self) end end +Node.prototype.draw = function(self, camera, shader) + -- do not draw base nodes, but recursively draw children. + for _, child in ipairs(self.children) do + child:draw(camera, shader) + end +end + Node.prototype.translate = function(self, translation) self.position:add(translation, self.position) end Node.prototype.pitch = function(self, angle) - self.rotation:setAt(0, angle) + self.rotation:setAt(0, self.rotation:at(0) + angle) end Node.prototype.yaw = function(self, angle) - self.rotation:setAt(1, angle) + self.rotation:setAt(1, self.rotation:at(1) + angle) end Node.prototype.roll = function(self, angle) - self.rotation:setAt(2, angle) + self.rotation:setAt(2, self.rotation:at(2) + angle) end -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |