From ae4d8ec41aa916d6edffd5b42a6dd27d4633b94e Mon Sep 17 00:00:00 2001 From: exochron Date: Mon, 16 Oct 2023 19:25:37 +0200 Subject: [PATCH] fix(ui): fix LUA error of OrbitCamera [cf#97] --- UI/BlizzFixes.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/UI/BlizzFixes.lua b/UI/BlizzFixes.lua index dd4bee6..7bd6729 100644 --- a/UI/BlizzFixes.lua +++ b/UI/BlizzFixes.lua @@ -12,6 +12,41 @@ local function fixInitialRiderBlend() end end +-- Rotating the display camera wildly extends the internal vector further and further. +-- At some point on very high/low values the UI bugs with an error. (https://legacy.curseforge.com/wow/addons/mount-journal-enhanced/issues/97) +-- Although that might only happen with an unlocked Y-rotation/pitch. +-- Also, when resetting the camera the whole rotation gets reverted. That looks a bit funny. +-- +-- To fix both we keep the rotation values within a fixed boundary of -2*PI and 2*PI. That prevents the LUA error and +-- keeps the reset rotation short. +local function keepCameraValuesInBound() + local two_pi = 2 * math.pi + local keepValueInBound = function(self, newValue, index, interpolatedIndex) + if newValue < -two_pi then + self[index] = newValue + two_pi + if nil ~= self[interpolatedIndex] then + self[interpolatedIndex] = self[interpolatedIndex] + two_pi + end + elseif newValue > two_pi then + self[index] = newValue - two_pi + if nil ~= self[interpolatedIndex] then + self[interpolatedIndex] = self[interpolatedIndex] - two_pi + end + end + end + + -- horizontal rotation + hooksecurefunc(MountJournal.MountDisplay.ModelScene.activeCamera, "SetYaw", function(self, yaw) + keepValueInBound(self, yaw, "yaw", "interpolatedYaw") + end) + -- vertical rotation + hooksecurefunc(MountJournal.MountDisplay.ModelScene.activeCamera, "SetPitch", function(self, pitch) + keepValueInBound(self, pitch, "pitch", "interpolatedPitch") + end) + -- same could be done with roll. but that's not necessary for the mount display. +end + ADDON.Events:RegisterCallback("loadUI", function() fixInitialRiderBlend() + keepCameraValuesInBound() end, "blizz plz fix") \ No newline at end of file