From 6e429c0e33a45bb4f9991c0b8cfb4ade6a41bdc6 Mon Sep 17 00:00:00 2001 From: Aaron Warner Date: Sun, 10 Nov 2024 19:36:39 +1300 Subject: [PATCH 1/6] fix GetAngleInBetween parameter references --- lua/utilities.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/utilities.lua b/lua/utilities.lua index 43f5eecd53..8425fb1883 100644 --- a/lua/utilities.lua +++ b/lua/utilities.lua @@ -405,13 +405,15 @@ end ---@param v1 Vector ---@param v2 Vector ---@return number + function GetAngleInBetween(v1, v2) - local x1, y1, z2 = v1[1], v1[2], v1[3] - local x2, y2, z2 = v2[1], v2[2], v2[3] + local x1, y1, z1 = v1.x, v1.y, v1.z + local x2, y2, z2 = v2.x, v2.y, v2.z -- arccos((v1 . v2) / (|v1| |v2|)) + local z1Sq = z1 * z1 local z2Sq = z2 * z2 - local dot = x1*x2 + y1*y2 + z2Sq - local len2 = MathSqrt((x1*x1 + y1*y1 + z2Sq) * (x2*x2 + y2*y2 + z2Sq)) + local dot = x1 * x2 + y1 * y2 + z1 * z2 + local len2 = MathSqrt((x1 * x1 + y1 * y1 + z1Sq) * (x2 * x2 + y2 * y2 + z2Sq)) return MathACos(dot / len2) * 180 / math.pi end From 6d15a0df7534ecc50e42434576e544d59639691a Mon Sep 17 00:00:00 2001 From: Aaron Warner Date: Sun, 10 Nov 2024 19:43:50 +1300 Subject: [PATCH 2/6] remove line space --- lua/utilities.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/utilities.lua b/lua/utilities.lua index 8425fb1883..3fde279360 100644 --- a/lua/utilities.lua +++ b/lua/utilities.lua @@ -405,7 +405,6 @@ end ---@param v1 Vector ---@param v2 Vector ---@return number - function GetAngleInBetween(v1, v2) local x1, y1, z1 = v1.x, v1.y, v1.z local x2, y2, z2 = v2.x, v2.y, v2.z From 83de791cbb978c1aa9a27b396ff728bb334e1235 Mon Sep 17 00:00:00 2001 From: Aaron Warner <34614077+relent0r@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:01:25 +1300 Subject: [PATCH 3/6] Update lua/utilities.lua Co-authored-by: lL1l1 <82986251+lL1l1@users.noreply.github.com> --- lua/utilities.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/utilities.lua b/lua/utilities.lua index 3fde279360..42a9ec3683 100644 --- a/lua/utilities.lua +++ b/lua/utilities.lua @@ -409,8 +409,6 @@ function GetAngleInBetween(v1, v2) local x1, y1, z1 = v1.x, v1.y, v1.z local x2, y2, z2 = v2.x, v2.y, v2.z -- arccos((v1 . v2) / (|v1| |v2|)) - local z1Sq = z1 * z1 - local z2Sq = z2 * z2 local dot = x1 * x2 + y1 * y2 + z1 * z2 local len2 = MathSqrt((x1 * x1 + y1 * y1 + z1Sq) * (x2 * x2 + y2 * y2 + z2Sq)) return MathACos(dot / len2) * 180 / math.pi From 27be5534ed79602f77eea688b0ddcb9341eff9f2 Mon Sep 17 00:00:00 2001 From: Aaron Warner <34614077+relent0r@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:01:45 +1300 Subject: [PATCH 4/6] Update lua/utilities.lua Co-authored-by: lL1l1 <82986251+lL1l1@users.noreply.github.com> --- lua/utilities.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/utilities.lua b/lua/utilities.lua index 42a9ec3683..1f8188bf24 100644 --- a/lua/utilities.lua +++ b/lua/utilities.lua @@ -410,7 +410,7 @@ function GetAngleInBetween(v1, v2) local x2, y2, z2 = v2.x, v2.y, v2.z -- arccos((v1 . v2) / (|v1| |v2|)) local dot = x1 * x2 + y1 * y2 + z1 * z2 - local len2 = MathSqrt((x1 * x1 + y1 * y1 + z1Sq) * (x2 * x2 + y2 * y2 + z2Sq)) + local len2 = MathSqrt((x1 * x1 + y1 * y1 + z1 * z1) * (x2 * x2 + y2 * y2 + z2 * z2)) return MathACos(dot / len2) * 180 / math.pi end From 52ec43b8980084c9b2f5455d3bdb7b4f311874af Mon Sep 17 00:00:00 2001 From: Aaron Warner Date: Mon, 11 Nov 2024 17:17:34 +1300 Subject: [PATCH 5/6] revert to using indexes again, waiting for another update to scathis scripts to support this. --- changelog/snippets/other.6438.md | 2 +- lua/utilities.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog/snippets/other.6438.md b/changelog/snippets/other.6438.md index 711be31cd4..3381eb44b6 100644 --- a/changelog/snippets/other.6438.md +++ b/changelog/snippets/other.6438.md @@ -1,4 +1,4 @@ -- (#5061, #6438) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. +- (#5061, #6438, #(6525)) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. - This **removes** the file `/lua/shared/quaternions.lua`, which was added in #4768 (Mar 4, 2023), so mods that use that file will have to be updated. - The metamethods (defined globally in `/lua/system/utils.lua`) include: - Vector/Vector2 addition/subtraction/negation diff --git a/lua/utilities.lua b/lua/utilities.lua index 1f8188bf24..6135b96dcf 100644 --- a/lua/utilities.lua +++ b/lua/utilities.lua @@ -406,8 +406,8 @@ end ---@param v2 Vector ---@return number function GetAngleInBetween(v1, v2) - local x1, y1, z1 = v1.x, v1.y, v1.z - local x2, y2, z2 = v2.x, v2.y, v2.z + local x1, y1, z1 = v1[1], v1[2], v1[3] + local x2, y2, z2 = v2[1], v2[2], v2[3] -- arccos((v1 . v2) / (|v1| |v2|)) local dot = x1 * x2 + y1 * y2 + z1 * z2 local len2 = MathSqrt((x1 * x1 + y1 * y1 + z1 * z1) * (x2 * x2 + y2 * y2 + z2 * z2)) From 0b1c33652d62227dcf5c8617bf2952be89dc1a9c Mon Sep 17 00:00:00 2001 From: Aaron Warner <34614077+relent0r@users.noreply.github.com> Date: Wed, 13 Nov 2024 07:32:13 +1300 Subject: [PATCH 6/6] Update changelog/snippets/other.6438.md Co-authored-by: lL1l1 <82986251+lL1l1@users.noreply.github.com> --- changelog/snippets/other.6438.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/snippets/other.6438.md b/changelog/snippets/other.6438.md index 3381eb44b6..858cfae9ba 100644 --- a/changelog/snippets/other.6438.md +++ b/changelog/snippets/other.6438.md @@ -1,4 +1,4 @@ -- (#5061, #6438, #(6525)) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. +- (#5061, #6438, #6525) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. - This **removes** the file `/lua/shared/quaternions.lua`, which was added in #4768 (Mar 4, 2023), so mods that use that file will have to be updated. - The metamethods (defined globally in `/lua/system/utils.lua`) include: - Vector/Vector2 addition/subtraction/negation