Extract settings, narrow assumed FOV

Assume that the FOV might be as narrow as 72.
This commit is contained in:
Aaron Suen 2022-04-22 21:32:06 -04:00
parent 7ae04eb463
commit 65ad490837
2 changed files with 37 additions and 20 deletions

1
TODO
View File

@ -10,6 +10,7 @@
- !filter to exclude players matching filter
- admin priv to externally control filters
- configurability via settings w/ live updates
- remote control of FOV?
- settingtypes.txt for all mods

View File

@ -5,7 +5,23 @@ local math_atan2, math_cos, math_pi, math_random, math_sin, math_sqrt
= math.atan2, math.cos, math.pi, math.random, math.sin, math.sqrt
-- LUALOCALS > ---------------------------------------------------------
local cycletime = 20
local cycletime = 20 -- time between cycles
local hudtime = 4 -- time to display HUD
local dummyradius = 64 -- max radius for dummy cam
local dummymin = 0.25 -- min radius (of max) for dummy cam
local dummyclear = 16 -- min clear sight for dummy cam
local vellead = -2 -- ratio of player vel for camera pos "leading/chasing"
local camdistset = 4 -- initial target distance from player to set camera
local camdistmin = 1 -- min distance from player to allow camera
local camdistmax = 16 -- max distance from player to allow camera
local camfov = 72 -- assume camera fov for angle check
local camlocktime = 1 -- min time to lock camera after moving
local minlight = 4 -- min light level to not affect cam time
local maxidle = 10 -- max idle time before penalty
local idlepenalty = 4 -- extra countdown speed for being idle
local modname = minetest.get_current_modname()
@ -102,16 +118,16 @@ local function camdummy(player, data, dtime)
local theta = math_random() * math_pi * 2
local dpos = {
x = math_cos(theta) * 64,
y = math_random() * 64,
z = math_sin(theta) * 64
x = math_cos(theta) * dummyradius,
y = math_random() * dummyradius,
z = math_sin(theta) * dummyradius
}
dpos = vector.multiply(dpos, 0.25 + math_random() * 0.75)
dpos = vector.multiply(dpos, dummymin + math_random() * (1 - dummymin))
if not allow(dpos) then return end
local len = vector.length(dpos)
local tpos = vector.multiply(dpos, (len - 16) / len)
local tpos = vector.multiply(dpos, (len - dummyclear) / len)
if sightblocked(dpos, tpos) then return end
setcamera(player, dpos, tpos)
@ -129,7 +145,7 @@ local function camcheck(player, dtime)
if text ~= data.tip.text then data.tip.time = 0 end
data.tip.text = text
local show = text
if data.tip.time >= 4 then show = "" end
if data.tip.time >= hudtime then show = "" end
if data.tip.show ~= show then
player:hud_change(data.tip.id, "text", show)
data.tip.show = text
@ -197,8 +213,8 @@ local function camcheck(player, dtime)
tpos.y = tpos.y + target:get_properties().eye_height
local tidle = getdata(target).idletime or 0
if tidle >= 10 then
data.tracktime = data.tracktime - dtime * 4
if tidle >= maxidle then
data.tracktime = data.tracktime - dtime * idlepenalty
end
local function newcam()
@ -207,17 +223,17 @@ local function camcheck(player, dtime)
x = math_cos(theta),
y = math_random() * 2 - 0.5,
z = math_sin(theta)
}, 8))
}, camdistmax))
trypos = vector.add(trypos, vector.multiply(
target:get_velocity(), -2))
target:get_velocity(), vellead))
local dist = vector.distance(trypos, tpos)
if dist > 4 then
if dist > camdistset then
trypos = vector.add(tpos, vector.multiply(
vector.direction(tpos, trypos), 4))
vector.direction(tpos, trypos), camdistset))
end
local bpos = sightblocked(tpos, trypos)
if bpos and vector.distance(tpos, bpos) < 1 then
if bpos and vector.distance(tpos, bpos) < camdistmin then
return
end
trypos = bpos or trypos
@ -230,28 +246,28 @@ local function camcheck(player, dtime)
setcamera(player, trypos, tpos)
data.moved = 0
data.locked = 1
data.locked = camlocktime
end
if not allow(pos) then return newcam() end
local tlight = nodecore and nodecore.get_node_light(tpos)
or minetest.get_node_light(tpos)
if tlight and tlight < 8 then
data.tracktime = data.tracktime - dtime * 8 / tlight
if tlight and tlight < minlight then
data.tracktime = data.tracktime - dtime * minlight / tlight
end
local dist = vector.distance(pos, tpos)
if dist < 1 or dist > 16 then return newcam() end
if dist < 1 or dist > camdistmax then return newcam() end
local look = player:get_look_dir()
local angle = vector.angle(vector.direction(pos, tpos), look)
if angle > math_pi / 4 then return newcam() end
if angle > camfov / 2/180 * math_pi then return newcam() end
if sightblocked(pos, tpos) then return newcam() end
data.moved = (data.moved or 0) + dtime
if data.moved > 15 then return newcam() end
if data.moved > cycletime then return newcam() end
end
minetest.register_globalstep(function(dtime)