From 26bfc10ad0e8a355e9b02946dd31642f49a6ec60 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 9 May 2023 20:21:25 -0500 Subject: fix camera resizing and move all scripts into separate files --- scripts/cameraHandleResize.lua | 1 + scripts/cameraPivot.lua | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 scripts/cameraPivot.lua (limited to 'scripts') diff --git a/scripts/cameraHandleResize.lua b/scripts/cameraHandleResize.lua index 7d1713d..97974f5 100644 --- a/scripts/cameraHandleResize.lua +++ b/scripts/cameraHandleResize.lua @@ -1,6 +1,7 @@ return function(entities, id, data) local camera = entities:getComponent(id, "camera") if camera then + print("resize camera!") camera.projection:perspectiveResize(data.width/data.height) end end diff --git a/scripts/cameraPivot.lua b/scripts/cameraPivot.lua new file mode 100644 index 0000000..d2fad59 --- /dev/null +++ b/scripts/cameraPivot.lua @@ -0,0 +1,21 @@ +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 -- cgit v1.2.1