clone() overhaul / fix missing steps in line()
This commit is contained in:
parent
2834245229
commit
2574f487bb
@ -4,7 +4,7 @@ local function round(n)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mtscad.Context:line(x, y, z)
|
function mtscad.Context:line(x, y, z)
|
||||||
local steps = math.sqrt( (x*x) + (y*y) + (z*z) )
|
local steps = math.ceil( math.sqrt( (x*x) + (y*y) + (z*z) ) )
|
||||||
for step=0,steps do
|
for step=0,steps do
|
||||||
local xi = round(x / steps * step)
|
local xi = round(x / steps * step)
|
||||||
local yi = round(y / steps * step)
|
local yi = round(y / steps * step)
|
||||||
|
@ -3,16 +3,16 @@ local Context_mt = { __index = mtscad.Context }
|
|||||||
|
|
||||||
-- copy the current context
|
-- copy the current context
|
||||||
function mtscad.Context:clone()
|
function mtscad.Context:clone()
|
||||||
return mtscad.create_context(self.pos, self.rotation, self.nodefactory, self.param2)
|
return mtscad.create_context(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create a new context with given (optional) params
|
-- create a new context with given (optional) params
|
||||||
function mtscad.create_context(pos, rotation, nodefactory, param2)
|
function mtscad.create_context(opts)
|
||||||
local self = {
|
local self = {
|
||||||
pos = pos and vector.copy(pos) or vector.zero(),
|
pos = opts.pos and vector.copy(opts.pos) or vector.zero(),
|
||||||
rotation = rotation and vector.copy(rotation) or vector.zero(),
|
rotation = opts.rotation and vector.copy(opts.rotation) or vector.zero(),
|
||||||
nodefactory = nodefactory,
|
nodefactory = opts.nodefactory,
|
||||||
param2 = param2 or 0
|
param2 = opts.param2 or 0
|
||||||
}
|
}
|
||||||
return setmetatable(self, Context_mt)
|
return setmetatable(self, Context_mt)
|
||||||
end
|
end
|
||||||
|
4
load.lua
4
load.lua
@ -34,7 +34,9 @@ minetest.register_chatcommand("scad", {
|
|||||||
func = function(name, modulename)
|
func = function(name, modulename)
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local ppos = player:get_pos()
|
local ppos = player:get_pos()
|
||||||
local ctx = mtscad.create_context(vector.round(ppos))
|
local ctx = mtscad.create_context({
|
||||||
|
pos = vector.round(ppos)
|
||||||
|
})
|
||||||
|
|
||||||
local fn, options
|
local fn, options
|
||||||
local success, exec_err = pcall(function()
|
local success, exec_err = pcall(function()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user