From ee859c21aea9a7b83cdc17a4fd3449d9e609221a Mon Sep 17 00:00:00 2001
From: ultrakatiz <ultrakatiz@gmail.com>
Date: Fri, 20 May 2022 17:16:55 +0200
Subject: [PATCH] added camera screen shift option (just shifts the \pos by (x,
 -y))

---
 camera.lua        | 6 +++---
 examples/Test.ass | 3 +--
 shape.lua         | 8 ++++----
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/camera.lua b/camera.lua
index 8eb30b2..d7790e7 100644
--- a/camera.lua
+++ b/camera.lua
@@ -6,11 +6,11 @@ camera = {class = "camera"}
 camera.__index = camera
 
 -- Creates a camera at transform t with horizontal fov f,
--- near plane distance nd and far plane distance fd
-function camera.new(t, f, nd, fd)
+-- near plane distance nd, far plane distance fd, and sceen shift (xs, ys)
+function camera.new(t, f, xs, ys, nd, fd)
   local xres, yres, _, _ = aegisub.video_size()
   local c = {transform = t, aspect = xres / yres, fov = f or 80 / 180 * math.pi,
-    near = nd or 1, far = fd or 1000000000}
+    near = nd or 1, far = fd or 1000000000, shiftx = xs or 0, shifty = ys or 0}
   setmetatable(c, camera)
   return c
 end
diff --git a/examples/Test.ass b/examples/Test.ass
index 74559ac..2a981dc 100644
--- a/examples/Test.ass
+++ b/examples/Test.ass
@@ -14,8 +14,7 @@ Last Style Storage: Default
 Video File: ?dummy:24.000000:120:1920:1080:0:0:0:
 Video AR Value: 1.777778
 Video Zoom Percent: 0.500000
-Scroll Position: 4
-Active Line: 7
+Active Line: 5
 
 [V4+ Styles]
 Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
diff --git a/shape.lua b/shape.lua
index 3cb3ff2..cbf57cf 100644
--- a/shape.lua
+++ b/shape.lua
@@ -102,6 +102,7 @@ function shape:draw(subs, line, tags, cull, cam, ambient, lights)
   local camp = cam and cam.transform:position(true) or vector.zero(3)
 
   local xres, yres, _, _ = aegisub.video_size()
+  local hxr, hyr = xres / 2, yres / 2
 
   local m = proj * view * tm
 
@@ -119,8 +120,8 @@ function shape:draw(subs, line, tags, cull, cam, ambient, lights)
       local l = table.copy(line)
       l.text = (tags and "{" .. tags .. "}" or "")
         .. (face.tags and "{" .. face.tags .. "}" or "")
-        .. "{\\an7\\pos(" .. (xres / 2) .. ", " .. (yres / 2) .. ")\\p1}"
-        .. "m " .. (v:x() * xres / 2) .. " " .. (-v:y() * yres / 2) .. " "
+        .. "{\\an7\\pos(" .. (hxr + cam.shiftx) .. ", " .. (hyr - cam.shifty) .. ")\\p1}"
+        .. "m " .. (v:x() * hxr) .. " " .. (-v:y() * hyr) .. " "
 
       local face_center = vector.zero(4)
 
@@ -128,8 +129,7 @@ function shape:draw(subs, line, tags, cull, cam, ambient, lights)
         v = m * (vs[i] + c)
         face_center = face_center + v
         v = (1 / v:w()) * v
-        l.text = l.text .. "l " .. ( v:x() * xres / 2) .. " "
-                                .. (-v:y() * yres / 2) .. " "
+        l.text = l.text .. "l " .. ( v:x() * hxr) .. " " .. (-v:y() * hyr) .. " "
       end
 
       face_center = (1 / #vs) * face_center
-- 
GitLab