Automatically compute reasonable aspect ratio (#457)

Automatically compute reasonable aspect ratio in sgct lua helper
This commit is contained in:
Emil Axelsson
2018-01-26 11:07:22 +01:00
committed by GitHub
parent d569b8235e
commit 8cc5250df8

View File

@@ -360,15 +360,6 @@ end
function generateSingleWindowConfig(arg)
-- First some type checking
assert(
type(arg[1]) == "number" or type(arg[1]) == "nil",
"First argument must be a number or nil"
)
assert(
type(arg[2]) == "number" or type(arg[2]) == "nil",
"Second argument must be a number or nil"
)
assert(
type(arg["res"]) == "table" or type(arg["res"]) == "nil",
"res must be a table or nil"
@@ -400,10 +391,6 @@ function generateSingleWindowConfig(arg)
if (type(arg["windowSize"]) == "table") then
assert(type(arg["windowSize"][1]) == "number", "windowPos[1] must be a number")
assert(type(arg["windowSize"][2]) == "number", "windowPos[2] must be a number")
assert(
type(arg[1]) == "nil" and type(arg[2]) == "nil",
"Only windowSize or the first and second arguments can be set. Not both"
)
end
assert(
@@ -594,9 +581,7 @@ function generateSingleWindowConfig(arg)
end
if not arg["windowSize"] then
arg["windowSize"] = {}
arg["windowSize"][1] = arg[1] or 1280
arg["windowSize"][2] = arg[2] or 720
arg["windowSize"] = {1280, 720}
end
arg["scene"] = generateScene(arg)
@@ -609,6 +594,35 @@ function generateSingleWindowConfig(arg)
end
function normalizeArg(arg)
arg = arg or {}
if (type(arg["windowSize"]) == "table") then
assert(
type(arg[1]) == "nil" and type(arg[2]) == "nil",
"Only windowSize or the first and second arguments can be set. Not both"
)
end
assert(
type(arg[1]) == "number" or type(arg[1]) == "nil",
"First argument must be a number or nil"
)
assert(
type(arg[2]) == "number" or type(arg[2]) == "nil",
"Second argument must be a number or nil"
)
if (type(arg[1]) == "number") then
if (type(arg[2]) == "nil") then
arg[2] = arg[1] * 9/16
end
arg["windowSize"] = { arg[1], arg[2] }
arg[1] = nil
arg[2] = nil
end
return arg
end
function sgct.makeConfig(config)
local configFile = os.tmpname()
@@ -624,7 +638,12 @@ end
function sgct.config.single(arg)
arg = arg or {}
arg = normalizeArg(arg)
assert(
type(arg["windowSize"]) == "table" or type(arg["windowSize"]) == "nil",
"windowSize must be a table or nil"
)
assert(
type(arg["fov"]) == "table" or type(arg["fov"]) == "nil",
@@ -635,9 +654,32 @@ function sgct.config.single(arg)
assert(type(arg["fov"]["right"]) == "number", "fov['right'] must be a number")
assert(type(arg["fov"]["up"]) == "number", "fov['up'] must be a number")
assert(type(arg["fov"]["down"]) == "number", "fov['down'] must be a number")
else
if (type(arg["windowSize"]) == "table") then
assert(type(arg["windowSize"][1]) == "number", "windowPos[1] must be a number")
assert(type(arg["windowSize"][2]) == "number", "windowPos[2] must be a number")
local ratio = arg["windowSize"][1] / arg["windowSize"][2]
local horizontalFov = 30
local verticalFov = 30
if (ratio > 1) then
verticalFov = horizontalFov / ratio
else
horizontalFov = verticalFov * ratio
end
arg["fov"] = {
down = verticalFov,
up = verticalFov,
left = horizontalFov,
right = horizontalFov
}
else
arg["fov"] = { down = 16.875, up = 16.875, left = 30.0, right = 30.0 }
end
end
arg["fov"] = arg["fov"] or { down = 16.875, up = 16.875, left = 30.0, right = 30.0 }
arg["viewport"] = generateSingleViewportFOV(
arg["fov"]["down"],
arg["fov"]["up"],
@@ -651,7 +693,7 @@ end
function sgct.config.fisheye(arg)
arg = arg or {}
arg = normalizeArg(arg)
assert(
type(arg["fov"]) == "number" or type(arg["fov"]) == "nil",