mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-19 06:46:04 +01:00
More enhancements to cameras.lua
Tidy up `createTempCam()` Add `loadLocation()` and `clearLoadLocation()` functions Add `renderTime` variable for `stopTempCam()` Add wrapper functions for each one (for my own sanity): `createCam()` = `createTempCam()` `startCam()` = `startTempCam()` `stopTempCam()` = `stopTempCam()`
This commit is contained in:
@@ -21,32 +21,28 @@ function createTempCam(ent, coords)
|
|||||||
local camID = nil
|
local camID = nil
|
||||||
if Config.Crafting?.craftCam or Config.System.enableCam then
|
if Config.Crafting?.craftCam or Config.System.enableCam then
|
||||||
|
|
||||||
|
-- if not ent or coords are provided, make a basic camera to control later
|
||||||
if not ent and not coords then
|
if not ent and not coords then
|
||||||
camID = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
|
camID = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
|
||||||
camCache[#camCache+1] = camID
|
camCache[#camCache+1] = camID
|
||||||
return camID
|
return camID
|
||||||
end
|
end
|
||||||
|
|
||||||
debugPrint("^6Bridge^7: ^2Custom Camera Created")
|
-- if received a vector3 or vector4 use those coords for origin point, otherwrise get offset from entity
|
||||||
|
local camCoords = type(ent) ~= "number" and ent or GetOffsetFromEntityInWorldCoords(ent, 1.0, -0.3, 0.8)
|
||||||
local camCoords = nil
|
|
||||||
--local pointCoords = nil
|
|
||||||
|
|
||||||
if type(ent) ~= "number" then -- if received a vector3 or vector4 use those coords for origin point
|
|
||||||
camCoords = ent
|
|
||||||
else
|
|
||||||
camCoords = GetOffsetFromEntityInWorldCoords(ent, 1.0, -0.3, 0.8)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Create the camera
|
-- Create the camera
|
||||||
camID = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z + 0.5, 1.0, 0.0, 0.0, 60.00, false, 0)
|
camID = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z + 0.5, 1.0, 0.0, 0.0, 60.00, false, 0)
|
||||||
camCache[#camCache+1] = camID
|
camCache[#camCache+1] = camID
|
||||||
|
|
||||||
|
debugPrint("^6Bridge^7: ^2Custom Camera Created")
|
||||||
|
|
||||||
--if type(coords) == "number" then
|
--if type(coords) == "number" then
|
||||||
-- SetCamCoord(camID, GetCamCoord(camID) + vec3(0, 0, 1.0))
|
-- SetCamCoord(camID, GetCamCoord(camID) + vec3(0, 0, 1.0))
|
||||||
--end
|
--end
|
||||||
|
if coords then
|
||||||
camLookAt(camID, coords)
|
camLookAt(camID, coords)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
return camID
|
return camID
|
||||||
@@ -69,9 +65,10 @@ local cachePrevCam = nil
|
|||||||
-- ```lua
|
-- ```lua
|
||||||
-- startTempCam(camID, 1000, true, { postFx = "HeistCelebEnd" })
|
-- startTempCam(camID, 1000, true, { postFx = "HeistCelebEnd" })
|
||||||
-- ```
|
-- ```
|
||||||
function startTempCam(cam, renderTime, loadScene, filter)
|
function startTempCam(cam, renderTime, loadScene, filter, switchCam)
|
||||||
if cam and DoesCamExist(cam) then
|
if cam and DoesCamExist(cam) then
|
||||||
if cachePrevCam then
|
-- if moving from a cached previous cam, or you've sent a camre id for it to switch from, interpolate to it
|
||||||
|
if switchCam or cachePrevCam then
|
||||||
SetCamActiveWithInterp(cam, cachePrevCam, renderTime or 1000, 0, 0)
|
SetCamActiveWithInterp(cam, cachePrevCam, renderTime or 1000, 0, 0)
|
||||||
else
|
else
|
||||||
SetCamActive(cam, true)
|
SetCamActive(cam, true)
|
||||||
@@ -101,13 +98,30 @@ function startTempCam(cam, renderTime, loadScene, filter)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if loadScene then
|
if loadScene then
|
||||||
local pos = GetCamCoord(cam)
|
loadLocation(cam, nil, 100.0)
|
||||||
|
end
|
||||||
|
|
||||||
local radius = 100.0
|
RenderScriptCams(true, true, renderTime or 1000, true, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Follow cam or coords
|
||||||
|
function camLookAt(cam, entCoords)
|
||||||
|
if cam and DoesCamExist(cam) and entCoords then
|
||||||
|
if type(entCoords) ~= "number" then
|
||||||
|
PointCamAtCoord(cam, entCoords.xyz)
|
||||||
|
else
|
||||||
|
PointCamAtEntity(cam, entCoords)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function loadLocation(cam, pos, radius)
|
||||||
|
local pos = pos or GetCamCoord(cam)
|
||||||
|
|
||||||
SetFocusPosAndVel(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0)
|
SetFocusPosAndVel(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0)
|
||||||
RequestCollisionAtCoord(pos.x, pos.y, pos.z)
|
RequestCollisionAtCoord(pos.x, pos.y, pos.z)
|
||||||
NewLoadSceneStart(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0, radius, 0)
|
NewLoadSceneStart(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0, radius or 100.0, 0)
|
||||||
|
|
||||||
local t0 = GetGameTimer()
|
local t0 = GetGameTimer()
|
||||||
while not IsNewLoadSceneLoaded() and (GetGameTimer() - t0) < 2000 do
|
while not IsNewLoadSceneLoaded() and (GetGameTimer() - t0) < 2000 do
|
||||||
@@ -118,20 +132,11 @@ function startTempCam(cam, renderTime, loadScene, filter)
|
|||||||
NewLoadSceneStop()
|
NewLoadSceneStop()
|
||||||
end
|
end
|
||||||
|
|
||||||
RenderScriptCams(true, true, renderTime or 1000, true, true)
|
function clearLoadLocation()
|
||||||
end
|
ClearFocus()
|
||||||
|
NewLoadSceneStop()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Follow cam or coords
|
|
||||||
function camLookAt(cam, entCoords)
|
|
||||||
if cam and entCoords then
|
|
||||||
if type(entCoords) ~= "number" then
|
|
||||||
PointCamAtCoord(cam, entCoords.xyz)
|
|
||||||
else
|
|
||||||
PointCamAtEntity(cam, entCoords)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Deactivates the temporary camera and stops rendering.
|
--- Deactivates the temporary camera and stops rendering.
|
||||||
--
|
--
|
||||||
@@ -144,7 +149,7 @@ end
|
|||||||
-- ```lua
|
-- ```lua
|
||||||
-- stopTempCam()
|
-- stopTempCam()
|
||||||
-- ```
|
-- ```
|
||||||
function stopTempCam()
|
function stopTempCam(renderTime)
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
Wait(1000)
|
Wait(1000)
|
||||||
|
|
||||||
@@ -160,13 +165,18 @@ function stopTempCam()
|
|||||||
cacheCameraEffect.timecycle = nil
|
cacheCameraEffect.timecycle = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
RenderScriptCams(false, true, 500, true, true)
|
RenderScriptCams(false, true, renderTime or 500, true, true)
|
||||||
|
|
||||||
|
clearLoadLocation()
|
||||||
|
|
||||||
|
Wait(renderTime or 0)
|
||||||
for i = 1, #camCache do
|
for i = 1, #camCache do
|
||||||
DestroyCam(camCache[i], true)
|
DestroyCam(camCache[i], true)
|
||||||
end
|
end
|
||||||
camCache = {}
|
camCache = {}
|
||||||
--DestroyAllCams()
|
|
||||||
ClearFocus()
|
|
||||||
NewLoadSceneStop()
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function createCam(...) createTempCam(...) end
|
||||||
|
function startCam(...) startTempCam(...) end
|
||||||
|
function stopTempCam(...) startCam(...) end
|
||||||
Reference in New Issue
Block a user