diff options
author | sanine <sanine.not@pm.me> | 2023-05-09 20:21:25 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-09 20:21:25 -0500 |
commit | 26bfc10ad0e8a355e9b02946dd31642f49a6ec60 (patch) | |
tree | 2c2a92cf81b680f6fb3c705059f15801d9f0224c /main.lua | |
parent | 78d8efa4ac61bc7fd4d1e5bfb41193e9dece5c03 (diff) |
fix camera resizing and move all scripts into separate files
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 38 |
1 files changed, 2 insertions, 36 deletions
@@ -29,17 +29,6 @@ systems:addSystem(honey.ecs.render.system) systems:addSystem(honey.ecs.script.system) systems:addSystem(honey.ecs.collision.system, {space=space}) systems:addSystem(honey.ecs.physics.system, {space=space, world=world}) -package.loaded['baseRotationScript'] = function(entities, id, dt) - local node = entities:getComponent(id, "node") - node.matrix:rotateZ(math.pi * dt) -end -package.loaded['cameraRotationScript'] = function(entities, id, dt) - local node = entities:getComponent(id, "node") - local z = entities:getComponent(id, "z") - node.matrix - :identity() - :translate(Vec3{0, 0, z.value + math.sin(math.pi * glfw.GetTime())}) -end function setupEntities() @@ -164,31 +153,8 @@ function setupEntities() pitch = 0, yaw = 0, }, - onCursorPos = { script = "cameraCursorPos" }, + onCursorPos = { script = "scripts.cameraPivot" }, } - package.loaded["cameraCursorPos"] = (function() - local prevx, prevy - return function(entities, id, data) - if not prevx then - prevx, prevy = data.xpos, data.ypos - end - local dx = data.xpos - prevx - local dy = data.ypos - prevy - prevx, prevy = data.xpos, data.ypos - - local node = entities:getComponent(id, "node") - local py = entities:getComponent(id, "pitchyaw") - py.pitch = py.pitch - dy - py.yaw = py.yaw - dx - if py.pitch > 89.9 then py.pitch = 89.9 end - if py.pitch < -89.9 then py.pitch = -89.9 end - - node.matrix - :identity() - :rotateY(math.rad(py.yaw)) - :rotateX(math.rad(py.pitch)) - end - end)() local capcam = entities:createEntityWithComponents{ @@ -200,7 +166,7 @@ function setupEntities() parent = capcamPivot, matrix = Mat4():identity():translate(Vec3{0,0,20}), }, - onWindowResize = { script = "scripts.cameraHandleResize" }, + onFramebufferSize = { script = "scripts.cameraHandleResize" }, } |