overlay glasses

This commit is contained in:
kepler155c@gmail.com
2019-03-19 07:34:03 -04:00
parent 048fbc41c5
commit 2cd1ec27e0

View File

@@ -30,30 +30,44 @@ local projecting = { }
local function getPoint() local function getPoint()
local pt = { gps.locate() } local pt = { gps.locate() }
if pt[1] then
return { return {
x = pt[1], x = pt[1],
y = pt[2], y = pt[2],
z = pt[3], z = pt[3],
} }
end
end end
local offset = getPoint() local offset = getPoint() or error('GPS not found')
local canvas = modules.canvas3d().create() local canvas = modules.canvas3d().create()
local function run() local function run()
while true do while true do
-- order matters -- order matters
local scanned = modules.scan() local scanned = modules.scan()
local pos = getPoint() local pos = getPoint()
if pos then
if math.abs(pos.x - offset.x) +
math.abs(pos.y - offset.y) +
math.abs(pos.z - offset.z) > 64 then
for _, b in pairs(projecting) do
b.box.remove()
end
projecting = { }
offset = pos
canvas.recenter()
end
local blocks = { } local blocks = { }
for _, b in pairs(scanned) do for _, b in pairs(scanned) do
if targets[b.name] then if targets[b.name] then
b.wx = math.floor(pos.x + b.x) -- track block's world position
b.wy = math.floor(pos.y + b.y) b.id = table.concat({
b.wz = math.floor(pos.z + b.z) math.floor(pos.x + b.x),
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':') math.floor(pos.y + b.y),
math.floor(pos.z + b.z) }, ':')
blocks[b.id] = b blocks[b.id] = b
end end
end end
@@ -72,20 +86,10 @@ local function run()
for _, b in pairs(projecting) do for _, b in pairs(projecting) do
if not blocks[b.id] then if not blocks[b.id] then
projecting[b.id].box.remove() b.box.remove()
projecting[b.id] = nil projecting[b.id] = nil
end end
end end
if math.abs(pos.x - offset.x) +
math.abs(pos.y - offset.y) +
math.abs(pos.z - offset.z) > 64 then
for _, b in pairs(projecting) do
projecting[b.id].box.remove()
projecting[b.id] = nil
end
offset = pos
canvas.recenter()
end end
os.sleep(.5) os.sleep(.5)
@@ -106,4 +110,4 @@ parallel.waitForAny(
run run
) )
canvas:clear() canvas.clear()