Skip to content

Commit

Permalink
Fix GetAngleInBetween refactor (#6525)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: lL1l1 <[email protected]>
  • Loading branch information
relent0r and lL1l1 authored Nov 12, 2024
1 parent 55b6598 commit 5fa3faf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
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, #6527) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them.
- (#5061, #6438, #6527, #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
Expand Down
7 changes: 3 additions & 4 deletions lua/utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,11 @@ end
---@param v2 Vector
---@return number
function GetAngleInBetween(v1, v2)
local x1, y1, z2 = v1[1], v1[2], v1[3]
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 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 + z1 * z1) * (x2 * x2 + y2 * y2 + z2 * z2))
return MathACos(dot / len2) * 180 / math.pi
end

Expand Down

0 comments on commit 5fa3faf

Please sign in to comment.