From 228bfda006ddae498e03e9e22be275023576bb5a Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 11 Jan 2022 18:02:39 +0100 Subject: [PATCH] Fix vector.rotate3 --- vector.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vector.lua b/vector.lua index a5ab234..0b62b62 100644 --- a/vector.lua +++ b/vector.lua @@ -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