1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-27 01:11:37 +00:00

Move camera settings to a menu script

This commit is contained in:
uramer 2024-01-10 20:32:34 +01:00
parent 6917384fc1
commit 5b97a93169
5 changed files with 45 additions and 47 deletions

View file

@ -13,6 +13,7 @@ GLOBAL: scripts/omw/usehandlers.lua
GLOBAL: scripts/omw/worldeventhandlers.lua GLOBAL: scripts/omw/worldeventhandlers.lua
PLAYER: scripts/omw/mechanics/playercontroller.lua PLAYER: scripts/omw/mechanics/playercontroller.lua
PLAYER: scripts/omw/playercontrols.lua PLAYER: scripts/omw/playercontrols.lua
MENU: scripts/omw/camera/settings.lua
PLAYER: scripts/omw/camera/camera.lua PLAYER: scripts/omw/camera/camera.lua
PLAYER: scripts/omw/input/actionbindings.lua PLAYER: scripts/omw/input/actionbindings.lua
PLAYER: scripts/omw/input/smoothmovement.lua PLAYER: scripts/omw/input/smoothmovement.lua

View file

@ -5,6 +5,7 @@ local util = require('openmw.util')
local self = require('openmw.self') local self = require('openmw.self')
local nearby = require('openmw.nearby') local nearby = require('openmw.nearby')
local async = require('openmw.async') local async = require('openmw.async')
local storage = require('openmw.storage')
local I = require('openmw.interfaces') local I = require('openmw.interfaces')
local Actor = require('openmw.types').Actor local Actor = require('openmw.types').Actor
@ -28,7 +29,7 @@ input.registerAction {
defaultValue = 0, defaultValue = 0,
} }
local settings = require('scripts.omw.camera.settings').thirdPerson local settings = storage.playerSection('SettingsOMWCameraThirdPerson')
local head_bobbing = require('scripts.omw.camera.head_bobbing') local head_bobbing = require('scripts.omw.camera.head_bobbing')
local third_person = require('scripts.omw.camera.third_person') local third_person = require('scripts.omw.camera.third_person')
local pov_auto_switch = require('scripts.omw.camera.first_person_auto_switch') local pov_auto_switch = require('scripts.omw.camera.first_person_auto_switch')

View file

@ -2,12 +2,13 @@ local camera = require('openmw.camera')
local self = require('openmw.self') local self = require('openmw.self')
local util = require('openmw.util') local util = require('openmw.util')
local async = require('openmw.async') local async = require('openmw.async')
local storage = require('openmw.storage')
local Actor = require('openmw.types').Actor local Actor = require('openmw.types').Actor
local M = {} local M = {}
local settings = require('scripts.omw.camera.settings').headBobbing local settings = storage.playerSection('SettingsOMWCameraHeadBobbing')
local doubleStepLength, stepHeight, maxRoll local doubleStepLength, stepHeight, maxRoll
@ -31,7 +32,7 @@ local arcHeight = sampleArc(1)
function M.update(dt, smoothedSpeed) function M.update(dt, smoothedSpeed)
local speed = Actor.getCurrentSpeed(self) local speed = Actor.getCurrentSpeed(self)
speed = speed / (1 + speed / 500) -- limit bobbing frequency if the speed is very high speed = speed / (1 + speed / 500) -- limit bobbing frequency if the speed is very high
totalMovement = totalMovement + speed * dt totalMovement = totalMovement + speed * dt
if not M.enabled or camera.getMode() ~= camera.MODE.FirstPerson then if not M.enabled or camera.getMode() ~= camera.MODE.FirstPerson then
effectWeight = 0 effectWeight = 0
@ -44,18 +45,17 @@ function M.update(dt, smoothedSpeed)
end end
local doubleStepState = totalMovement / doubleStepLength local doubleStepState = totalMovement / doubleStepLength
doubleStepState = doubleStepState - math.floor(doubleStepState) -- from 0 to 1 during 2 steps doubleStepState = doubleStepState - math.floor(doubleStepState) -- from 0 to 1 during 2 steps
local stepState = math.abs(doubleStepState * 4 - 2) - 1 -- from -1 to 1 on even steps and from 1 to -1 on odd steps local stepState = math.abs(doubleStepState * 4 - 2) - 1 -- from -1 to 1 on even steps and from 1 to -1 on odd steps
local effect = sampleArc(stepState) / arcHeight -- range from 0 to 1 local effect = sampleArc(stepState) / arcHeight -- range from 0 to 1
-- Smoothly reduce the effect to zero when the player stops -- Smoothly reduce the effect to zero when the player stops
local coef = math.min(smoothedSpeed / 300, 1) * effectWeight local coef = math.min(smoothedSpeed / 300, 1) * effectWeight
local zOffset = (0.5 - effect) * coef * stepHeight -- range from -stepHeight/2 to stepHeight/2 local zOffset = (0.5 - effect) * coef * stepHeight -- range from -stepHeight/2 to stepHeight/2
local roll = ((stepState > 0 and 1) or -1) * effect * coef * maxRoll -- range from -maxRoll to maxRoll local roll = ((stepState > 0 and 1) or -1) * effect * coef * maxRoll -- range from -maxRoll to maxRoll
camera.setFirstPersonOffset(camera.getFirstPersonOffset() + util.vector3(0, 0, zOffset)) camera.setFirstPersonOffset(camera.getFirstPersonOffset() + util.vector3(0, 0, zOffset))
camera.setExtraRoll(camera.getExtraRoll() + roll) camera.setExtraRoll(camera.getExtraRoll() + roll)
end end
return M return M

View file

@ -3,10 +3,10 @@ local async = require('openmw.async')
local I = require('openmw.interfaces') local I = require('openmw.interfaces')
I.Settings.registerPage({ I.Settings.registerPage({
key = 'OMWCamera', key = 'OMWCamera',
l10n = 'OMWCamera', l10n = 'OMWCamera',
name = 'Camera', name = 'Camera',
description = 'settingsPageDescription', description = 'settingsPageDescription',
}) })
local thirdPersonGroup = 'SettingsOMWCameraThirdPerson' local thirdPersonGroup = 'SettingsOMWCameraThirdPerson'
@ -16,8 +16,8 @@ local function boolSetting(prefix, key, default)
return { return {
key = key, key = key,
renderer = 'checkbox', renderer = 'checkbox',
name = prefix..key, name = prefix .. key,
description = prefix..key..'Description', description = prefix .. key .. 'Description',
default = default, default = default,
} }
end end
@ -26,8 +26,8 @@ local function floatSetting(prefix, key, default)
return { return {
key = key, key = key,
renderer = 'number', renderer = 'number',
name = prefix..key, name = prefix .. key,
description = prefix..key..'Description', description = prefix .. key .. 'Description',
default = default, default = default,
} }
end end
@ -70,33 +70,29 @@ I.Settings.registerGroup({
}, },
}) })
local settings = { local thirdPerson = storage.playerSection(thirdPersonGroup)
thirdPerson = storage.playerSection(thirdPersonGroup), local headBobbing = storage.playerSection(headBobbingGroup)
headBobbing = storage.playerSection(headBobbingGroup),
}
local function updateViewOverShoulderDisabled() local function updateViewOverShoulderDisabled()
local shoulderDisabled = not settings.thirdPerson:get('viewOverShoulder') local shoulderDisabled = not thirdPerson:get('viewOverShoulder')
I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetX', {disabled = shoulderDisabled}) I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetX', { disabled = shoulderDisabled })
I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetY', {disabled = shoulderDisabled}) I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetY', { disabled = shoulderDisabled })
I.Settings.updateRendererArgument(thirdPersonGroup, 'autoSwitchShoulder', {disabled = shoulderDisabled}) I.Settings.updateRendererArgument(thirdPersonGroup, 'autoSwitchShoulder', { disabled = shoulderDisabled })
I.Settings.updateRendererArgument(thirdPersonGroup, 'zoomOutWhenMoveCoef', {disabled = shoulderDisabled}) I.Settings.updateRendererArgument(thirdPersonGroup, 'zoomOutWhenMoveCoef', { disabled = shoulderDisabled })
local move360Disabled = not settings.thirdPerson:get('move360') local move360Disabled = not thirdPerson:get('move360')
I.Settings.updateRendererArgument(thirdPersonGroup, 'move360TurnSpeed', {disabled = move360Disabled}) I.Settings.updateRendererArgument(thirdPersonGroup, 'move360TurnSpeed', { disabled = move360Disabled })
end end
local function updateHeadBobbingDisabled() local function updateHeadBobbingDisabled()
local disabled = not settings.headBobbing:get('enabled') local disabled = not headBobbing:get('enabled')
I.Settings.updateRendererArgument(headBobbingGroup, 'step', {disabled = disabled, min = 1}) I.Settings.updateRendererArgument(headBobbingGroup, 'step', { disabled = disabled, min = 1 })
I.Settings.updateRendererArgument(headBobbingGroup, 'height', {disabled = disabled}) I.Settings.updateRendererArgument(headBobbingGroup, 'height', { disabled = disabled })
I.Settings.updateRendererArgument(headBobbingGroup, 'roll', {disabled = disabled, min = 0, max = 90}) I.Settings.updateRendererArgument(headBobbingGroup, 'roll', { disabled = disabled, min = 0, max = 90 })
end end
updateViewOverShoulderDisabled() updateViewOverShoulderDisabled()
updateHeadBobbingDisabled() updateHeadBobbingDisabled()
settings.thirdPerson:subscribe(async:callback(updateViewOverShoulderDisabled)) thirdPerson:subscribe(async:callback(updateViewOverShoulderDisabled))
settings.headBobbing:subscribe(async:callback(updateHeadBobbingDisabled)) headBobbing:subscribe(async:callback(updateHeadBobbingDisabled))
return settings

View file

@ -3,10 +3,11 @@ local util = require('openmw.util')
local self = require('openmw.self') local self = require('openmw.self')
local nearby = require('openmw.nearby') local nearby = require('openmw.nearby')
local async = require('openmw.async') local async = require('openmw.async')
local storage = require('openmw.storage')
local Actor = require('openmw.types').Actor local Actor = require('openmw.types').Actor
local settings = require('scripts.omw.camera.settings').thirdPerson local settings = storage.playerSection('SettingsOMWCameraThirdPerson')
local MODE = camera.MODE local MODE = camera.MODE
local STATE = { RightShoulder = 0, LeftShoulder = 1, Combat = 2, Swimming = 3 } local STATE = { RightShoulder = 0, LeftShoulder = 1, Combat = 2, Swimming = 3 }
@ -31,7 +32,7 @@ local function updateSettings()
viewOverShoulder = settings:get('viewOverShoulder') viewOverShoulder = settings:get('viewOverShoulder')
autoSwitchShoulder = settings:get('autoSwitchShoulder') autoSwitchShoulder = settings:get('autoSwitchShoulder')
shoulderOffset = util.vector2(settings:get('shoulderOffsetX'), shoulderOffset = util.vector2(settings:get('shoulderOffsetX'),
settings:get('shoulderOffsetY')) settings:get('shoulderOffsetY'))
zoomOutWhenMoveCoef = settings:get('zoomOutWhenMoveCoef') zoomOutWhenMoveCoef = settings:get('zoomOutWhenMoveCoef')
defaultShoulder = (shoulderOffset.x > 0 and STATE.RightShoulder) or STATE.LeftShoulder defaultShoulder = (shoulderOffset.x > 0 and STATE.RightShoulder) or STATE.LeftShoulder
@ -46,7 +47,7 @@ local state = defaultShoulder
local function ray(from, angle, limit) local function ray(from, angle, limit)
local to = from + util.transform.rotateZ(angle) * util.vector3(0, limit, 0) local to = from + util.transform.rotateZ(angle) * util.vector3(0, limit, 0)
local res = nearby.castRay(from, to, {collisionType = camera.getCollisionType()}) local res = nearby.castRay(from, to, { collisionType = camera.getCollisionType() })
if res.hit then if res.hit then
return (res.hitPos - from):length() return (res.hitPos - from):length()
else else
@ -55,8 +56,8 @@ local function ray(from, angle, limit)
end end
local function trySwitchShoulder() local function trySwitchShoulder()
local limitToSwitch = 120 -- switch to other shoulder if wall is closer than this limit local limitToSwitch = 120 -- switch to other shoulder if wall is closer than this limit
local limitToSwitchBack = 300 -- switch back to default shoulder if there is no walls at this distance local limitToSwitchBack = 300 -- switch back to default shoulder if there is no walls at this distance
local pos = camera.getTrackedPosition() local pos = camera.getTrackedPosition()
local rayRight = ray(pos, camera.getYaw() + math.rad(90), limitToSwitchBack + 1) local rayRight = ray(pos, camera.getYaw() + math.rad(90), limitToSwitchBack + 1)
@ -79,7 +80,7 @@ end
local function calculateDistance(smoothedSpeed) local function calculateDistance(smoothedSpeed)
local smoothedSpeedSqr = smoothedSpeed * smoothedSpeed local smoothedSpeedSqr = smoothedSpeed * smoothedSpeed
return (M.baseDistance + math.max(camera.getPitch(), 0) * 50 return (M.baseDistance + math.max(camera.getPitch(), 0) * 50
+ smoothedSpeedSqr / (smoothedSpeedSqr + 300*300) * zoomOutWhenMoveCoef) + smoothedSpeedSqr / (smoothedSpeedSqr + 300 * 300) * zoomOutWhenMoveCoef)
end end
local function updateState() local function updateState()
@ -95,7 +96,7 @@ local function updateState()
state = defaultShoulder state = defaultShoulder
end end
if (mode == MODE.ThirdPerson or Actor.getCurrentSpeed(self) > 0 or state ~= oldState or noThirdPersonLastFrame) if (mode == MODE.ThirdPerson or Actor.getCurrentSpeed(self) > 0 or state ~= oldState or noThirdPersonLastFrame)
and (state == STATE.LeftShoulder or state == STATE.RightShoulder) then and (state == STATE.LeftShoulder or state == STATE.RightShoulder) then
if autoSwitchShoulder then if autoSwitchShoulder then
trySwitchShoulder() trySwitchShoulder()
else else
@ -108,11 +109,11 @@ local function updateState()
-- Player doesn't touch controls for a long time. Transition should be very slow. -- Player doesn't touch controls for a long time. Transition should be very slow.
camera.setFocalTransitionSpeed(0.2) camera.setFocalTransitionSpeed(0.2)
elseif (oldState == STATE.Combat or state == STATE.Combat) and elseif (oldState == STATE.Combat or state == STATE.Combat) and
(mode ~= MODE.Preview or M.standingPreview) then (mode ~= MODE.Preview or M.standingPreview) then
-- Transition to/from combat mode and we are not in preview mode. Should be fast. -- Transition to/from combat mode and we are not in preview mode. Should be fast.
camera.setFocalTransitionSpeed(5.0) camera.setFocalTransitionSpeed(5.0)
else else
camera.setFocalTransitionSpeed(1.0) -- Default transition speed. camera.setFocalTransitionSpeed(1.0) -- Default transition speed.
end end
if state == STATE.RightShoulder then if state == STATE.RightShoulder then
@ -149,7 +150,7 @@ function M.update(dt, smoothedSpeed)
end end
M.preferredDistance = calculateDistance(smoothedSpeed) M.preferredDistance = calculateDistance(smoothedSpeed)
if noThirdPersonLastFrame then -- just switched to third person view if noThirdPersonLastFrame then -- just switched to third person view
camera.setPreferredThirdPersonDistance(M.preferredDistance) camera.setPreferredThirdPersonDistance(M.preferredDistance)
camera.instantTransition() camera.instantTransition()
noThirdPersonLastFrame = false noThirdPersonLastFrame = false
@ -161,4 +162,3 @@ function M.update(dt, smoothedSpeed)
end end
return M return M