summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua22
1 files changed, 18 insertions, 4 deletions
diff --git a/main.lua b/main.lua
index f5512b0..5ef09dd 100644
--- a/main.lua
+++ b/main.lua
@@ -43,9 +43,18 @@ package.loaded['baseRotationScript'] = function(db, id, dt)
transform.matrix:rotateZ(math.pi * dt)
end
package.loaded['cameraRotationScript'] = function(db, id, dt)
- local transform = db:getComponent(id, "transform")
- transform.matrix:identity():translate(Vec3{0, 0, -6 + math.sin(math.pi * glfw.GetTime())})
+ local transform = db:getComponent(id, "transform")
+ transform.matrix:identity():translate(Vec3{0, 0, -6 + math.sin(math.pi * glfw.GetTime())})
+end
+
+
+function transmitMessage(msg, data)
+ local query = db:queryComponent(msg)
+ for id, handler in pairs(query) do
+ local f = require(handler.scriptName)
+ f(db, id, data)
end
+end
local id = db:createEntity()
@@ -87,11 +96,16 @@ end)
-- resize window correctly
window:setFramebufferSizeCallback(function(_, width, height)
gl.Viewport(0, 0, width, height)
- local cameraParams = db:getComponent(camera, "camera")
- cameraParams.projection:perspectiveResize(width/height)
vw, vh = width, height
+ transmitMessage("onWindowResize", { width=width, height=height })
end)
+package.loaded["cameraHandleResize"] = function(db, id, data)
+ local camera = db:getComponent(id, "camera")
+ camera.projection:perspectiveResize(data.width/data.height)
+end
+db:addComponent(camera, "onWindowResize", { scriptName = "cameraHandleResize" })
+
-- averager (for fps)
function averager(memory)
local buf = {}