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 /scripts/cameraPivot.lua | |
parent | 78d8efa4ac61bc7fd4d1e5bfb41193e9dece5c03 (diff) |
fix camera resizing and move all scripts into separate files
Diffstat (limited to 'scripts/cameraPivot.lua')
-rw-r--r-- | scripts/cameraPivot.lua | 21 |
1 files changed, 21 insertions, 0 deletions
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 |