mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Document & extend testing for rotation conventions (#16200)
* Document Luanti rotation conventions * Add test for setPitchYawRollRad (entity) rotation conventions * Test and document that `vector.rotate` uses (extrinsic) Z-X-Y rotation order
This commit is contained in:
parent
33940021a1
commit
23bf50a07c
7 changed files with 123 additions and 38 deletions
|
@ -432,7 +432,32 @@ describe("vector", function()
|
|||
assert.True(almost_equal({x = 1, y = 0, z = 0},
|
||||
vector.rotate({x = 1, y = 0, z = 0}, {x = math.pi / 123, y = 0, z = 0})))
|
||||
end)
|
||||
it("is counterclockwise", function()
|
||||
it("rotation order is Z-X-Y", function()
|
||||
local r = vector.new(1, 2, 3)
|
||||
for _, v in ipairs({
|
||||
vector.new(1, 0, 0),
|
||||
vector.new(0, 1, 0),
|
||||
vector.new(0, 0, 1),
|
||||
}) do
|
||||
local expected = v:rotate(r)
|
||||
local function try(order)
|
||||
local rotated = v
|
||||
for axis in order:gmatch(".") do
|
||||
local r_axis = vector.zero()
|
||||
r_axis[axis] = r[axis]
|
||||
rotated = vector.rotate(rotated, r_axis)
|
||||
end
|
||||
return almost_equal(rotated, expected)
|
||||
end
|
||||
assert.False(try("xyz"))
|
||||
assert.False(try("xzy"))
|
||||
assert.False(try("yxz"))
|
||||
assert.False(try("yzx"))
|
||||
assert.True(try("zxy"))
|
||||
assert.False(try("zyx"))
|
||||
end
|
||||
end)
|
||||
it("is right handed", function()
|
||||
local v_before1 = {x = 0, y = 1, z = -1}
|
||||
local v_after1 = vector.rotate(v_before1, {x = math.pi / 4, y = 0, z = 0})
|
||||
assert.True(almost_equal(vector.normalize(vector.cross(v_after1, v_before1)), {x = 1, y = 0, z = 0}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue