Try to fix the ellipsoid function, but it's not working right.

Thankfully I have a clue as to what's going wrong, which I've made a
note of. Time for some research I think.....
This commit is contained in:
Starbeamrainbowlabs 2018-06-09 13:36:25 +01:00
parent 2b33100356
commit 43f395ad02
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 27 additions and 10 deletions

View File

@ -13,35 +13,44 @@ function worldedit.ellipsoid(position, radius, target_node)
local node_id = minetest.get_content_id(target_node)
local node_id_air = minetest.get_content_id("air")
local offset_x, offset_y, offset_z = position.x - area.MinEdge.x, position.y - area.MinEdge.y
local stride_z, stride_y = area.zstride, area.ystride
-- TODO: This won't work, because we need to vary the calculation we use this in based on what part of the ellipsoid we're working on / in, not compare to a static value
local radius_distance_sq = worldeditadditions.vector.lengthsquared(radius)
local count = 0 -- The number of nodes replaced
local idx_z_base = position.z - area.MinEdge.z -- initial z offset
local idx_z_base = area:index(position.x, position.y, position.z) -- initial z offset
for z = -radius.z, radius.z do
local idx_y_base = idx_z_base
for y = -radius.y + offset_y, radius.y + offset_y do
for y = -radius.y, radius.y do
local i = idx_y_base
for x = -radius.x + offset_x, radius.x + offset_x do
for x = -radius.x, radius.x do
-- If we're inside the ellipse, then fill it in
if math.abs(z - position.z) < radius.z and
math.abs(y - position.y) < radius.y and
math.ans(z - position.x) < radius.x then
if math.abs(z) <= radius.z and
math.abs(y) <= radius.y and
math.abs(x) <= radius.x and
worldeditadditions.vector.lengthsquared({ x = x, y = y, z = z }) < radius_distance_sq then
data[i] = node_id
count = count + 1
else
minetest.log("action", "x: " .. x .. ", radius.x: " .. radius.x)
minetest.log("action", "y: " .. y .. ", radius.y: " .. radius.y)
minetest.log("action", "z: " .. z .. ", radius.z: " .. radius.z)
minetest.log("action", "***")
end
i = i + 1
end
idx_y_base = idx_y_base + y_stride
idx_y_base = idx_y_base + stride_y
end
idx_z_base = idx_z_base + z_stride
idx_z_base = idx_z_base + stride_z
end

View File

@ -84,6 +84,7 @@ minetest.register_chatcommand("/overlay", {
end, function(name, params_text)
if not worldedit.normalize_nodename(params_text) then
worldedit.player_notify(name, "Error: Invalid node name '" .. params_text .. "'.")
return 0
end
local pos1 = worldedit.pos1[name]
@ -116,7 +117,13 @@ local function parse_params_ellipsoid(params_text)
z = tonumber(radius_z)
}
minetest.log("action", "Radius x: " .. radius_x)
minetest.log("action", "Radius y: " .. radius_y)
minetest.log("action", "Radius z: " .. radius_z)
minetest.log("action", "Raw target node: " .. replace_node)
replace_node = worldedit.normalize_nodename(replace_node)
minetest.log("action", "Normalised target node: " .. replace_node)
return replace_node, radius
end
@ -145,8 +152,9 @@ minetest.register_chatcommand("/ellipsoid", {
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
end, function(name, params_text)
local target_node, radius = parse_params_ellipsoid(params_text)
if target_node == nil or radius == nil then
if not target_node or not radius then
worldedit.player_notify(name, "Error: Invalid input '" .. params_text .. "'. Try '/help /ellipsoid' to learn how to use this command.")
return 0
end
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)