summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
Diffstat (limited to 'demo')
-rw-r--r--demo/Camera.lua6
-rw-r--r--demo/MeshInstance.lua6
-rw-r--r--demo/Node.lua37
-rw-r--r--demo/SignalManager.lua24
-rw-r--r--demo/main.lua9
5 files changed, 54 insertions, 28 deletions
diff --git a/demo/Camera.lua b/demo/Camera.lua
index fda23f2..4f5c1fe 100644
--- a/demo/Camera.lua
+++ b/demo/Camera.lua
@@ -1,7 +1,9 @@
+local Node = require('Node')
+
local Camera = {}
Camera.prototype = {}
-setmetatable(Camera.prototype, { __index = honey.nodeMetatable.__index })
+setmetatable(Camera.prototype, { __index = Node.prototype })
Camera.prototype.updateView = function(self)
self.basis = self.transform:basis()
@@ -16,7 +18,7 @@ Camera.mt.__index = Camera.prototype
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Camera.new = function(parent, position, rotation, scale, fov, aspect, near, far)
- local camera = honey.node(parent, position, rotation, scale)
+ local camera = Node.new(parent, position, rotation, scale)
setmetatable(camera, Camera.mt)
camera.view = honey.glm.mat4()
diff --git a/demo/MeshInstance.lua b/demo/MeshInstance.lua
index eceec5d..3e879e1 100644
--- a/demo/MeshInstance.lua
+++ b/demo/MeshInstance.lua
@@ -1,7 +1,9 @@
+local Node = require('Node')
+
local MeshInstance = {}
MeshInstance.prototype = {}
-setmetatable(MeshInstance.prototype, { __index = honey.nodeMetatable.__index })
+setmetatable(MeshInstance.prototype, { __index = Node.prototype })
MeshInstance.prototype.draw = function(self, camera, shader)
local shader = shader or self.shader
@@ -18,7 +20,7 @@ MeshInstance.mt.__index = MeshInstance.prototype
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MeshInstance.new = function(parent, position, rotation, scale, mesh, shader)
- local meshinstance = honey.node(parent, position, rotation, scale)
+ local meshinstance = Node.new(parent, position, rotation, scale)
meshinstance.mesh = mesh
meshinstance.shader = shader
diff --git a/demo/Node.lua b/demo/Node.lua
index 5af745b..bfbfddd 100644
--- a/demo/Node.lua
+++ b/demo/Node.lua
@@ -1,6 +1,3 @@
-local Vector = require('Vector')
-local Matrix = require('Matrix')
-
local Node = {}
Node.prototype = {}
@@ -10,11 +7,11 @@ Node.prototype.updateTransform = function(self)
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:rotateZ(self.rotation:get(2))
+ self.transform:rotateY(self.rotation:get(1))
+ self.transform:rotateX(self.rotation:get(0))
- self.transform:scale(self.scale)
+ self.transform:scalev(self.scale)
if self.parent ~= nil then
self.parent.transform:mul(self.transform, self.transform)
@@ -50,16 +47,13 @@ Node.prototype.translate = function(self, translation)
self.position:add(translation, self.position)
end
-Node.prototype.pitch = function(self, angle)
- self.rotation:setAt(0, self.rotation:at(0) + angle)
-end
-
-Node.prototype.yaw = function(self, angle)
- self.rotation:setAt(1, self.rotation:at(1) + angle)
-end
+local rotationAxes = { x=0, y=1, z=2 }
-Node.prototype.roll = function(self, angle)
- self.rotation:setAt(2, self.rotation:at(2) + angle)
+function Node.prototype.rotate(self, axis, angle)
+ local index = rotationAxes[axis]
+ print(index)
+ local oldAngle = self.rotation:get(index)
+ self.rotation:set(index, oldAngle + angle)
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -76,9 +70,14 @@ Node.new = function(parent, position, rotation, scale)
node.parent = parent
- node.position = position
- node.rotation = rotation
- node.scale = scale
+ if not position then node.position = honey.glm.vec3{0,0,0}
+ else node.position = position end
+
+ if not rotation then node.rotation = honey.glm.vec3{0,0,0}
+ else node.rotation = rotation end
+
+ if not scale then node.scale = honey.glm.vec3{1,1,1}
+ else node.scale = scale end
node.children = {}
diff --git a/demo/SignalManager.lua b/demo/SignalManager.lua
new file mode 100644
index 0000000..b7e9d6b
--- /dev/null
+++ b/demo/SignalManager.lua
@@ -0,0 +1,24 @@
+local SignalManager = {}
+SignalManager.signals = {}
+
+function SignalManager.addCallback(self, signal, func)
+ if not self.signals[signal] then self.signals[signal] = {} end
+ self.signals[signal][func] = true
+end
+
+function SignalManager.removeCallback(self, signal, func)
+ if self.signals[signal] then
+ self.signals[signal][func] = nil
+ end
+end
+
+function SignalManager.emit(self, signal, argtable)
+ local sig = self.signals[signal]
+ if not sig then return end
+
+ for f, _ in pairs(sig) do
+ f(argtable)
+ end
+end
+
+return SignalManager
diff --git a/demo/main.lua b/demo/main.lua
index 3382d8d..d0695a6 100644
--- a/demo/main.lua
+++ b/demo/main.lua
@@ -1,3 +1,4 @@
+local Node = require('Node')
local FPSCamera = require('FPSCamera')
local SpatialShader = require('SpatialShader')
local ScreenQuad = require('ScreenQuad')
@@ -12,10 +13,7 @@ honey.input.key.bind(honey.input.key.f, function(action) if action == 1 then buf
local tex = honey.texture.new()
honey.texture.load(tex, 'checkerboard.png', false)
-local sceneRoot = honey.node(nil,
- honey.glm.vec3(),
- honey.glm.vec3(),
- honey.glm.vec3{1,1,1})
+local sceneRoot = Node.new()
local shader = SpatialShader.new(tex)
local lightDirection = honey.glm.vec3{1,1,1}
@@ -43,7 +41,8 @@ local plane2 = MeshInstance.new(suzanne,
shader)
suzanne.update = function(self, dt)
- self:rotate('y', dt)
+ self:rotate('y', 10*dt)
+ print(self.rotation)
end
local total_frames = 0