mtscad/context/rotate.lua
BuckarooBanzay f0f206226d refactoring
2022-03-26 15:21:22 +01:00

20 lines
452 B
Lua

local function add_rotation(a, b)
-- TODO: only 90°-increments allowed
a = a or 0
b = b or 0
local sum = a + b
while sum >= 360 do
sum = sum - 360
end
return sum
end
function mtscad.Context:rotate(x, y, z)
local ctx = self:clone()
ctx.rotation.x = add_rotation(ctx.rotation.x, x)
ctx.rotation.y = add_rotation(ctx.rotation.y, y)
ctx.rotation.z = add_rotation(ctx.rotation.z, z)
return ctx
end