Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix GetAngleInBetween parameter references #6525

Merged
merged 7 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog/snippets/other.6438.md
Original file line number Diff line number Diff line change
@@ -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.
relent0r marked this conversation as resolved.
Show resolved Hide resolved
- 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
Expand Down
8 changes: 3 additions & 5 deletions lua/utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,11 @@ 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 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))
local len2 = MathSqrt((x1 * x1 + y1 * y1 + z1 * z1) * (x2 * x2 + y2 * y2 + z2 * z2))
return MathACos(dot / len2) * 180 / math.pi
end

Expand Down