mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 17:12:59 +00:00
It works!! ....but the output seems off when non 90° increments
...probably due to the wiping and rotation overlapping
This commit is contained in:
parent
7d29453699
commit
27aa3a9c8f
2 changed files with 27 additions and 9 deletions
|
@ -16,15 +16,20 @@ local function __compile_rotlist(rotlist)
|
|||
--- 1: Construct a Vector3 to represent which axis we want to rotate on
|
||||
local rotval = Vector3.new(0, 0, 0)
|
||||
-- Assume that if it's a table, it's a Vector3 instance
|
||||
if type(rot) == "table" then rotval = rot:clone() end
|
||||
|
||||
if rot.axis:find("x", 1, true) then rotval.x = 1
|
||||
elseif rot.axis:find("y", 1, true) then rotval.y = 1
|
||||
elseif rot.axis:find("z", 1, true) then rotval.z = 1 end
|
||||
if rot.axis:sub(1, 1) == "-" then
|
||||
rotval = rotval * -1
|
||||
if type(rot) == "table" then
|
||||
print("DEBUG:__compile_rotlist rot is talble, ROT", weac.inspect(rot))
|
||||
rotval = rot.axis:clone()
|
||||
else
|
||||
-- Otherwise, treat it as a string
|
||||
if rot.axis:find("x", 1, true) then rotval.x = 1
|
||||
elseif rot.axis:find("y", 1, true) then rotval.y = 1
|
||||
elseif rot.axis:find("z", 1, true) then rotval.z = 1 end
|
||||
if rot.axis:sub(1, 1) == "-" then
|
||||
rotval = rotval * -1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- 2: Rotate & apply amount of rotation to apply in radians
|
||||
return rotval * rot.rad
|
||||
end)
|
||||
|
@ -53,6 +58,7 @@ function worldeditadditions.rotate(pos1, pos2, origin, rotlist)
|
|||
-- First, rotate the defined region to find the target region
|
||||
local pos1_rot, pos2_rot = pos1:clone(), pos2:clone()
|
||||
for i, rot in ipairs(rotlist_c) do
|
||||
print("DEBUG origin", weac.inspect(origin), "pos1_rot", weac.inspect(pos1_rot), "pos2_rot", weac.inspect(pos2_rot), "rot", weac.inspect(rot))
|
||||
pos1_rot = Vector3.rotate3d(origin, pos1_rot, rot)
|
||||
pos2_rot = Vector3.rotate3d(origin, pos2_rot, rot)
|
||||
end
|
||||
|
@ -81,7 +87,7 @@ function worldeditadditions.rotate(pos1, pos2, origin, rotlist)
|
|||
local cpos_dest = cpos_src:clone()
|
||||
|
||||
-- TODO: This is very inefficient. If we could use quaternions here to stack up the rotations, it would be much more efficient.
|
||||
for i, rot in ipairs(rotlist) do
|
||||
for i, rot in ipairs(rotlist_c) do
|
||||
cpos_dest = Vector3.rotate3d(origin, cpos_dest, rot)
|
||||
end
|
||||
|
||||
|
|
|
@ -95,9 +95,21 @@ worldeditadditions_core.register_command("rotate+", {
|
|||
func = function(name, origin, rotlist)
|
||||
local start_time = wea_c.get_ms_time()
|
||||
-------------------------------------------------
|
||||
local pos_origin = wea_c.pos.get(name, origin)
|
||||
|
||||
|
||||
local pos1, pos2 = wea_c.pos.get1(name), wea_c.pos.get2(name)
|
||||
|
||||
local pos_origin = nil
|
||||
if type(origin) == "number" then
|
||||
pos_origin = wea_c.pos.get(name, origin)
|
||||
elseif type(origin) == "string" and origin == "__AUTO__" then
|
||||
pos_origin = Vector3.mean(pos1, pos2)
|
||||
end
|
||||
if pos_origin == nil then
|
||||
-- There's a very small chance that this could be a bug here if origin is (NOT type("number") and NOT type("string") and ~= "__AUTO__"), but this shouldn't happen because we constrain the output of the above parser. This means we can safely make this assumption here
|
||||
return false, "Error: Failed to get origin point from position "..tostring(origin).." because it doesn't exist."
|
||||
end
|
||||
|
||||
|
||||
local success, stats = worldeditadditions.rotate(
|
||||
pos1, pos2,
|
||||
|
|
Loading…
Reference in a new issue