From 54d9a578e1ec0ee48603b4f33be4527e326e23f9 Mon Sep 17 00:00:00 2001 From: semyon422 Date: Wed, 11 Aug 2021 17:08:30 +0500 Subject: [PATCH 1/2] Use local variables --- modules/mat4.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/mat4.lua b/modules/mat4.lua index 25b8a39..092a150 100644 --- a/modules/mat4.lua +++ b/modules/mat4.lua @@ -236,10 +236,10 @@ function mat4.from_hmd_perspective(tanHalfFov, zNear, zFar, flipZ, farAtInfinity local isOpenGL = true local function CreateNDCScaleAndOffsetFromFov(tanHalfFov) - x_scale = 2 / (tanHalfFov.LeftTan + tanHalfFov.RightTan) - x_offset = (tanHalfFov.LeftTan - tanHalfFov.RightTan) * x_scale * 0.5 - y_scale = 2 / (tanHalfFov.UpTan + tanHalfFov.DownTan ) - y_offset = (tanHalfFov.UpTan - tanHalfFov.DownTan ) * y_scale * 0.5 + local x_scale = 2 / (tanHalfFov.LeftTan + tanHalfFov.RightTan) + local x_offset = (tanHalfFov.LeftTan - tanHalfFov.RightTan) * x_scale * 0.5 + local y_scale = 2 / (tanHalfFov.UpTan + tanHalfFov.DownTan ) + local y_offset = (tanHalfFov.UpTan - tanHalfFov.DownTan ) * y_scale * 0.5 local result = { Scale = vec2(x_scale, y_scale), From f22c9e09ccd4378b6f9c8d1d4a4529f346f547c1 Mon Sep 17 00:00:00 2001 From: semyon422 Date: Wed, 11 Aug 2021 18:12:58 +0500 Subject: [PATCH 2/2] Fix incorrect out of mat4.invert when out = a --- modules/mat4.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/mat4.lua b/modules/mat4.lua index 092a150..e40428d 100644 --- a/modules/mat4.lua +++ b/modules/mat4.lua @@ -389,18 +389,14 @@ function mat4.invert(out, a) tm4[15] = -a[1] * a[6] * a[15] + a[1] * a[7] * a[14] + a[5] * a[2] * a[15] - a[5] * a[3] * a[14] - a[13] * a[2] * a[7] + a[13] * a[3] * a[6] tm4[16] = a[1] * a[6] * a[11] - a[1] * a[7] * a[10] - a[5] * a[2] * a[11] + a[5] * a[3] * a[10] + a[9] * a[2] * a[7] - a[9] * a[3] * a[6] - for i=1, 16 do - out[i] = tm4[i] - end - - local det = a[1] * out[1] + a[2] * out[5] + a[3] * out[9] + a[4] * out[13] + local det = a[1] * tm4[1] + a[2] * tm4[5] + a[3] * tm4[9] + a[4] * tm4[13] if det == 0 then return a end det = 1 / det for i = 1, 16 do - out[i] = out[i] * det + out[i] = tm4[i] * det end return out