overlay glasses

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

View File

@@ -29,63 +29,67 @@ local targets = {
local projecting = { }
local function getPoint()
local pt = { gps.locate() }
return {
x = pt[1],
y = pt[2],
z = pt[3],
}
local pt = { gps.locate() }
if pt[1] then
return {
x = pt[1],
y = pt[2],
z = pt[3],
}
end
end
local offset = getPoint()
local offset = getPoint() or error('GPS not found')
local canvas = modules.canvas3d().create()
local function run()
while true do
-- order matters
local scanned = modules.scan()
local pos = getPoint()
local blocks = { }
for _, b in pairs(scanned) do
if targets[b.name] then
b.wx = math.floor(pos.x + b.x)
b.wy = math.floor(pos.y + b.y)
b.wz = math.floor(pos.z + b.z)
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':')
blocks[b.id] = b
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
end
for _, b in pairs(blocks) do
if not projecting[b.id] then
projecting[b.id] = b
b.box = canvas.addBox(
pos.x - offset.x + b.x + -(pos.x % 1) + .25,
pos.y - offset.y + b.y + -(pos.y % 1) + .25,
pos.z - offset.z + b.z + -(pos.z % 1) + .25,
.5, .5, .5, targets[b.name])
b.box.setDepthTested(false)
local blocks = { }
for _, b in pairs(scanned) do
if targets[b.name] then
-- track block's world position
b.id = table.concat({
math.floor(pos.x + b.x),
math.floor(pos.y + b.y),
math.floor(pos.z + b.z) }, ':')
blocks[b.id] = b
end
end
end
for _, b in pairs(projecting) do
if not blocks[b.id] then
projecting[b.id].box.remove()
projecting[b.id] = nil
for _, b in pairs(blocks) do
if not projecting[b.id] then
projecting[b.id] = b
b.box = canvas.addBox(
pos.x - offset.x + b.x + -(pos.x % 1) + .25,
pos.y - offset.y + b.y + -(pos.y % 1) + .25,
pos.z - offset.z + b.z + -(pos.z % 1) + .25,
.5, .5, .5, targets[b.name])
b.box.setDepthTested(false)
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
if not blocks[b.id] then
b.box.remove()
projecting[b.id] = nil
end
end
offset = pos
canvas.recenter()
end
os.sleep(.5)
@@ -106,4 +110,4 @@ parallel.waitForAny(
run
)
canvas:clear()
canvas.clear()