overlay glasses
This commit is contained in:
@@ -29,63 +29,67 @@ local targets = {
|
|||||||
local projecting = { }
|
local projecting = { }
|
||||||
|
|
||||||
local function getPoint()
|
local function getPoint()
|
||||||
local pt = { gps.locate() }
|
local pt = { gps.locate() }
|
||||||
return {
|
if pt[1] then
|
||||||
x = pt[1],
|
return {
|
||||||
y = pt[2],
|
x = pt[1],
|
||||||
z = pt[3],
|
y = pt[2],
|
||||||
}
|
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()
|
||||||
|
|
||||||
local blocks = { }
|
if pos then
|
||||||
for _, b in pairs(scanned) do
|
if math.abs(pos.x - offset.x) +
|
||||||
if targets[b.name] then
|
math.abs(pos.y - offset.y) +
|
||||||
b.wx = math.floor(pos.x + b.x)
|
math.abs(pos.z - offset.z) > 64 then
|
||||||
b.wy = math.floor(pos.y + b.y)
|
for _, b in pairs(projecting) do
|
||||||
b.wz = math.floor(pos.z + b.z)
|
b.box.remove()
|
||||||
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':')
|
end
|
||||||
blocks[b.id] = b
|
projecting = { }
|
||||||
|
offset = pos
|
||||||
|
canvas.recenter()
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for _, b in pairs(blocks) do
|
local blocks = { }
|
||||||
if not projecting[b.id] then
|
for _, b in pairs(scanned) do
|
||||||
projecting[b.id] = b
|
if targets[b.name] then
|
||||||
b.box = canvas.addBox(
|
-- track block's world position
|
||||||
pos.x - offset.x + b.x + -(pos.x % 1) + .25,
|
b.id = table.concat({
|
||||||
pos.y - offset.y + b.y + -(pos.y % 1) + .25,
|
math.floor(pos.x + b.x),
|
||||||
pos.z - offset.z + b.z + -(pos.z % 1) + .25,
|
math.floor(pos.y + b.y),
|
||||||
.5, .5, .5, targets[b.name])
|
math.floor(pos.z + b.z) }, ':')
|
||||||
b.box.setDepthTested(false)
|
blocks[b.id] = b
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for _, b in pairs(projecting) do
|
for _, b in pairs(blocks) do
|
||||||
if not blocks[b.id] then
|
if not projecting[b.id] then
|
||||||
projecting[b.id].box.remove()
|
projecting[b.id] = b
|
||||||
projecting[b.id] = nil
|
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
|
||||||
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
|
for _, b in pairs(projecting) do
|
||||||
projecting[b.id].box.remove()
|
if not blocks[b.id] then
|
||||||
projecting[b.id] = nil
|
b.box.remove()
|
||||||
|
projecting[b.id] = nil
|
||||||
|
end
|
||||||
end
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user