mirror of https://github.com/OpenMW/openmw.git
Addition camera features: move360, pov_auto_switch, slow_view_change
parent
3fb470dcce
commit
1ca0a3a555
@ -0,0 +1,52 @@
|
||||
local camera = require('openmw.camera')
|
||||
local util = require('openmw.util')
|
||||
local nearby = require('openmw.nearby')
|
||||
local self = require('openmw.self')
|
||||
|
||||
local forcedFirstPerson = false
|
||||
local limitSwitch = 40
|
||||
local limitReturn = 65
|
||||
|
||||
local rayOptions = {collisionType = nearby.COLLISION_TYPE.Default - nearby.COLLISION_TYPE.Actor}
|
||||
local function castRayBackward()
|
||||
local from = camera.getTrackedPosition()
|
||||
local orient = util.transform.rotateZ(camera.getYaw()) * util.transform.rotateX(camera.getPitch())
|
||||
local resLeft = nearby.castRay(from, from + orient * util.vector3(-30, -limitReturn, 0), rayOptions)
|
||||
local resRight = nearby.castRay(from, from + orient * util.vector3(30, -limitReturn, 0), rayOptions)
|
||||
local distLeft = limitReturn + 1
|
||||
local distRight = limitReturn + 1
|
||||
if resLeft.hit then distLeft = (resLeft.hitPos - from):length() end
|
||||
if resRight.hit then distRight = (resRight.hitPos - from):length() end
|
||||
return math.min(distLeft, distRight)
|
||||
end
|
||||
|
||||
local M = {
|
||||
enabled = false,
|
||||
}
|
||||
|
||||
function M.onUpdate(dt)
|
||||
if camera.getMode() ~= camera.MODE.FirstPerson then forcedFirstPerson = false end
|
||||
if not M.enabled then
|
||||
if forcedFirstPerson then
|
||||
camera.setMode(camera.MODE.ThirdPerson, false)
|
||||
forcedFirstPerson = false
|
||||
end
|
||||
return
|
||||
end
|
||||
if camera.getMode() == camera.MODE.ThirdPerson and camera.getThirdPersonDistance() < limitSwitch
|
||||
and math.abs(util.normalizeAngle(camera.getYaw() - self.rotation.z)) < math.rad(10) then
|
||||
if castRayBackward() <= limitSwitch then
|
||||
camera.setMode(camera.MODE.FirstPerson, true)
|
||||
forcedFirstPerson = true
|
||||
end
|
||||
return
|
||||
end
|
||||
if forcedFirstPerson then
|
||||
if castRayBackward() > limitReturn then
|
||||
camera.setMode(camera.MODE.ThirdPerson, false)
|
||||
forcedFirstPerson = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
@ -0,0 +1,73 @@
|
||||
local core = require('openmw.core')
|
||||
local camera = require('openmw.camera')
|
||||
local input = require('openmw.input')
|
||||
local self = require('openmw.self')
|
||||
local util = require('openmw.util')
|
||||
local I = require('openmw.interfaces')
|
||||
|
||||
local Actor = require('openmw.types').Actor
|
||||
|
||||
local MODE = camera.MODE
|
||||
|
||||
local active = false
|
||||
|
||||
local M = {
|
||||
enabled = false,
|
||||
turnSpeed = 5,
|
||||
}
|
||||
|
||||
local function turnOn()
|
||||
I.Camera.disableStandingPreview()
|
||||
active = true
|
||||
end
|
||||
|
||||
local function turnOff()
|
||||
I.Camera.enableStandingPreview()
|
||||
active = false
|
||||
if camera.getMode() == MODE.Preview then
|
||||
camera.setMode(MODE.ThirdPerson)
|
||||
end
|
||||
end
|
||||
|
||||
function M.onFrame(dt)
|
||||
if core.isWorldPaused() then return end
|
||||
local newActive = M.enabled and Actor.stance(self) == Actor.STANCE.Nothing
|
||||
if newActive and not active then
|
||||
turnOn()
|
||||
elseif not newActive and active then
|
||||
turnOff()
|
||||
end
|
||||
if not active then return end
|
||||
if camera.getMode() == MODE.Static then return end
|
||||
if camera.getMode() == MODE.ThirdPerson then camera.setMode(MODE.Preview) end
|
||||
if camera.getMode() == MODE.Preview and not input.isActionPressed(input.ACTION.TogglePOV) then
|
||||
camera.showCrosshair(camera.getFocalPreferredOffset():length() > 5)
|
||||
local move = util.vector2(self.controls.sideMovement, self.controls.movement)
|
||||
local yawDelta = camera.getYaw() - self.rotation.z
|
||||
move = move:rotate(-yawDelta)
|
||||
self.controls.sideMovement = move.x
|
||||
self.controls.movement = move.y
|
||||
self.controls.pitchChange = camera.getPitch() * math.cos(yawDelta) - self.rotation.x
|
||||
if move:length() > 0.05 then
|
||||
local delta = math.atan2(move.x, move.y)
|
||||
local maxDelta = math.max(delta, 1) * M.turnSpeed * dt
|
||||
self.controls.yawChange = util.clamp(delta, -maxDelta, maxDelta)
|
||||
else
|
||||
self.controls.yawChange = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.onInputAction(action)
|
||||
if not active or core.isWorldPaused() then return end
|
||||
if action == input.ACTION.ZoomIn and camera.getMode() == MODE.Preview
|
||||
and I.Camera.getBaseThirdPersonDistance() == 30 then
|
||||
self.controls.yawChange = camera.getYaw() - self.rotation.z
|
||||
camera.setMode(MODE.FirstPerson)
|
||||
elseif action == input.ACTION.ZoomOut and camera.getMode() == MODE.FirstPerson then
|
||||
camera.setMode(MODE.Preview)
|
||||
I.Camera.setBaseThirdPersonDistance(30)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
Loading…
Reference in New Issue