Compare commits
2 commits
d36ec336ab
...
2426302dd8
Author | SHA1 | Date | |
---|---|---|---|
|
2426302dd8 | ||
|
fd7a38f407 |
153
main.lua
153
main.lua
|
@ -1,7 +1,6 @@
|
|||
-- Bootstrap
|
||||
appName = "lovr-playspace"
|
||||
|
||||
-- Function to get the current time
|
||||
function getCurrentTime()
|
||||
local time = os.time()
|
||||
local date = os.date("*t", time)
|
||||
|
@ -11,21 +10,21 @@ end
|
|||
-- App
|
||||
hands = {"hand/right","hand/left"}
|
||||
limbs = {
|
||||
"head",
|
||||
"hand/left",
|
||||
"hand/right",
|
||||
"hand/left/grip",
|
||||
"hand/right/grip",
|
||||
"elbow/left",
|
||||
"elbow/right",
|
||||
"shoulder/left",
|
||||
"shoulder/right",
|
||||
"chest",
|
||||
"waist",
|
||||
"knee/left",
|
||||
"knee/right",
|
||||
"foot/left",
|
||||
"foot/right"
|
||||
"head",
|
||||
"hand/left",
|
||||
"hand/right",
|
||||
"hand/left/grip",
|
||||
"hand/right/grip",
|
||||
"elbow/left",
|
||||
"elbow/right",
|
||||
"shoulder/left",
|
||||
"shoulder/right",
|
||||
"chest",
|
||||
"waist",
|
||||
"knee/left",
|
||||
"knee/right",
|
||||
"foot/left",
|
||||
"foot/right"
|
||||
}
|
||||
|
||||
configDirs = {}
|
||||
|
@ -99,9 +98,9 @@ function getClosestDistanceToPerimeter(x, y, z, points)
|
|||
end
|
||||
|
||||
function getButton(method,button,devices)
|
||||
for _,device in ipairs(devices) do
|
||||
if method(device,button) == true then return device end
|
||||
end
|
||||
for _,device in ipairs(devices) do
|
||||
if method(device,button) == true then return device end
|
||||
end
|
||||
end
|
||||
|
||||
function drawSinglePointGrid(pass, point1, point2, cornerColor, miscColor)
|
||||
|
@ -177,38 +176,39 @@ function lovr.load()
|
|||
color_close_grid = {0.45, 0.69, 0.79, 0.5},
|
||||
color_far_corners = {0.45, 0.69, 0.79, 0},
|
||||
color_far_grid = {0.45, 0.69, 0.79, 0},
|
||||
show_time = 0,
|
||||
points = {}
|
||||
}
|
||||
|
||||
-- Helper function to read file with fallback to default
|
||||
local function loadSetting(filename, default, parser)
|
||||
print("Checking file:", filename)
|
||||
local function loadSetting(filename, default, parser)
|
||||
print("Checking file:", filename)
|
||||
|
||||
if not lovr.filesystem.isFile(filename) then
|
||||
print("File doesn't exist, creating:", filename)
|
||||
local valueToSave
|
||||
if type(default) == "table" then
|
||||
valueToSave = json.encode(default)
|
||||
else
|
||||
valueToSave = tostring(default)
|
||||
end
|
||||
if not lovr.filesystem.isFile(filename) then
|
||||
print("File doesn't exist, creating:", filename)
|
||||
local valueToSave
|
||||
if type(default) == "table" then
|
||||
valueToSave = json.encode(default)
|
||||
else
|
||||
valueToSave = tostring(default)
|
||||
end
|
||||
|
||||
local success = lovr.filesystem.write(filename, valueToSave)
|
||||
print("Write success:", success, "for", filename, "with value:", valueToSave)
|
||||
return default
|
||||
end
|
||||
local success = lovr.filesystem.write(filename, valueToSave)
|
||||
print("Write success:", success, "for", filename, "with value:", valueToSave)
|
||||
return default
|
||||
end
|
||||
|
||||
-- File exists, try to read it
|
||||
local content = lovr.filesystem.read(filename)
|
||||
if content and parser then
|
||||
local success, value = pcall(parser, content)
|
||||
if success then return value end
|
||||
elseif content then
|
||||
return content
|
||||
end
|
||||
-- File exists, try to read it
|
||||
local content = lovr.filesystem.read(filename)
|
||||
if content and parser then
|
||||
local success, value = pcall(parser, content)
|
||||
if success then return value end
|
||||
elseif content then
|
||||
return content
|
||||
end
|
||||
|
||||
return default
|
||||
end
|
||||
return default
|
||||
end
|
||||
|
||||
-- Initialize settings with fallbacks
|
||||
settings = {
|
||||
|
@ -223,6 +223,7 @@ function lovr.load()
|
|||
color_close_grid = loadSetting("color_close_grid.json", defaults.color_close_grid, json.decode),
|
||||
color_far_corners = loadSetting("color_far_corners.json", defaults.color_far_corners, json.decode),
|
||||
color_far_grid = loadSetting("color_far_grid.json", defaults.color_far_grid, json.decode),
|
||||
show_time = loadSetting("show_time.json", defaults.show_time, json.decode),
|
||||
points = {},
|
||||
transformed = false
|
||||
}
|
||||
|
@ -303,37 +304,37 @@ function modeConfigure(pass)
|
|||
end
|
||||
end
|
||||
|
||||
local inputDev = getButton(lovr.headset.wasReleased,settings.action_button,hands)
|
||||
if inputDev ~= nil and lovr.headset.isTracked(inputDev) then
|
||||
local inputDev = getButton(lovr.headset.wasReleased,settings.action_button,hands)
|
||||
if inputDev ~= nil and lovr.headset.isTracked(inputDev) then
|
||||
local cx, _, cz = lovr.headset.getPosition(inputDev)
|
||||
table.insert(settings.points,{cx,cz})
|
||||
end
|
||||
table.insert(settings.points,{cx,cz})
|
||||
end
|
||||
|
||||
inputDev = getButton(lovr.headset.isDown,settings.action_button,hands)
|
||||
if inputDev ~= nil then
|
||||
saveProg = saveProg - (deltaTime / 3)
|
||||
if saveProg <= 0 then
|
||||
inputDev = getButton(lovr.headset.isDown,settings.action_button,hands)
|
||||
if inputDev ~= nil then
|
||||
saveProg = saveProg - (deltaTime / 3)
|
||||
if saveProg <= 0 then
|
||||
local floorSpacePoints = {}
|
||||
for _,point in ipairs(settings.points) do
|
||||
local floorSpacePoint = lovr.math.vec3(point[1], 0, point[2]):transform(floorMatrixInv)
|
||||
local x, _, z = floorSpacePoint:unpack()
|
||||
table.insert(floorSpacePoints,{x,z})
|
||||
end
|
||||
lovr.filesystem.write("points.json", json.encode(floorSpacePoints))
|
||||
deinitConfigure()
|
||||
modeDraw(pass)
|
||||
return
|
||||
end
|
||||
else
|
||||
saveProg = 1.0
|
||||
end
|
||||
lovr.filesystem.write("points.json", json.encode(floorSpacePoints))
|
||||
deinitConfigure()
|
||||
modeDraw(pass)
|
||||
return
|
||||
end
|
||||
else
|
||||
saveProg = 1.0
|
||||
end
|
||||
|
||||
pass:setColor(1,0,0,0.5)
|
||||
for _,point in ipairs(settings.points) do
|
||||
pass:sphere(point[1],1.5,point[2],0.1)
|
||||
end
|
||||
pass:setColor(1,0,0,0.5)
|
||||
for _,point in ipairs(settings.points) do
|
||||
pass:sphere(point[1],1.5,point[2],0.1)
|
||||
end
|
||||
|
||||
modeDraw(pass)
|
||||
modeDraw(pass)
|
||||
end
|
||||
|
||||
function modeDraw(pass)
|
||||
|
@ -392,15 +393,17 @@ end
|
|||
function lovr.draw(pass)
|
||||
mode(pass)
|
||||
|
||||
local hx, hy, hz = lovr.headset.getPosition("head")
|
||||
local hangle, hax, hay, haz = lovr.headset.getOrientation("head")
|
||||
local currentTime = getCurrentTime()
|
||||
pass:setColor(1, 1, 1, 0.25)
|
||||
local transform = lovr.math.newMat4()
|
||||
transform:translate(hx, hy + 1.5, hz)
|
||||
transform:rotate(math.pi / 2, 1, 0, 0)
|
||||
transform:rotate(math.pi - math.atan2(hax, haz)*2, 0, 0, 1)
|
||||
transform:translate(0, -0.1, 0)
|
||||
transform:scale(0.1, 0.1, 0.1)
|
||||
pass:text(currentTime, transform)
|
||||
if settings.show_time == 1 then
|
||||
local hx, hy, hz = lovr.headset.getPosition("head")
|
||||
local hangle, hax, hay, haz = lovr.headset.getOrientation("head")
|
||||
local currentTime = getCurrentTime()
|
||||
pass:setColor(1, 1, 1, 0.25)
|
||||
local transform = lovr.math.newMat4()
|
||||
transform:translate(hx, hy + 1.5, hz)
|
||||
transform:rotate(math.pi / 2, 1, 0, 0)
|
||||
transform:rotate(math.pi - math.atan2(hax, haz)*2, 0, 0, 1)
|
||||
transform:translate(0, -0.1, 0)
|
||||
transform:scale(0.1, 0.1, 0.1)
|
||||
pass:text(currentTime, transform)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue