mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-22 21:32:27 +01:00
Fix vector.rotate3
This commit is contained in:
parent
bcda0511b1
commit
228bfda006
@ -190,10 +190,13 @@ function angle(v, w)
|
||||
end
|
||||
|
||||
-- Uses Rodrigues' rotation formula
|
||||
-- axis must be normalized
|
||||
function rotate3(v, axis, angle)
|
||||
assert(#v == 3 and #axis == 3)
|
||||
local cos = math.cos(angle)
|
||||
return multiply_scalar(v, cos)
|
||||
+ multiply_scalar(cross3(axis, v), math.sin(angle))
|
||||
-- Minetest's coordinate system is *left-handed*, so `v` and `axis` must be swapped here
|
||||
+ multiply_scalar(cross3(v, axis), math.sin(angle))
|
||||
+ multiply_scalar(axis, dot(axis, v) * (1 - cos))
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user