mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
refactor(raycast): smoother raycast during camera movement (#569)
This commit is contained in:
@@ -2,7 +2,16 @@ lib.raycast = {}
|
|||||||
|
|
||||||
local StartShapeTestLosProbe = StartShapeTestLosProbe
|
local StartShapeTestLosProbe = StartShapeTestLosProbe
|
||||||
local GetShapeTestResultIncludingMaterial = GetShapeTestResultIncludingMaterial
|
local GetShapeTestResultIncludingMaterial = GetShapeTestResultIncludingMaterial
|
||||||
local GetWorldCoordFromScreenCoord = GetWorldCoordFromScreenCoord
|
local glm_sincos = require 'glm'.sincos
|
||||||
|
local glm_rad = require 'glm'.rad
|
||||||
|
local math_abs = math.abs
|
||||||
|
local GetFinalRenderedCamCoord = GetFinalRenderedCamCoord
|
||||||
|
local GetFinalRenderedCamRot = GetFinalRenderedCamRot
|
||||||
|
|
||||||
|
local function getForwardVector()
|
||||||
|
local sin, cos = glm_sincos(glm_rad(GetFinalRenderedCamRot(2)))
|
||||||
|
return vec3(-sin.z * math_abs(cos.x), cos.z * math_abs(cos.x), sin.x)
|
||||||
|
end
|
||||||
|
|
||||||
---@alias ShapetestIgnore
|
---@alias ShapetestIgnore
|
||||||
---| 1 GLASS
|
---| 1 GLASS
|
||||||
@@ -20,20 +29,19 @@ local GetWorldCoordFromScreenCoord = GetWorldCoordFromScreenCoord
|
|||||||
---@return vector3 surfaceNormal
|
---@return vector3 surfaceNormal
|
||||||
---@return number materialHash
|
---@return number materialHash
|
||||||
function lib.raycast.cam(flags, ignore, distance)
|
function lib.raycast.cam(flags, ignore, distance)
|
||||||
local coords, normal = GetWorldCoordFromScreenCoord(0.5, 0.5)
|
local camCoords = GetFinalRenderedCamCoord()
|
||||||
local destination = coords + normal * (distance or 10)
|
local destination = camCoords + getForwardVector() * (distance or 10)
|
||||||
local handle = StartShapeTestLosProbe(coords.x, coords.y, coords.z, destination.x, destination.y, destination.z,
|
local handle = StartShapeTestLosProbe(camCoords.x, camCoords.y, camCoords.z, destination.x, destination.y,
|
||||||
flags or 511, cache.ped, ignore or 4)
|
destination.z, flags or 511, cache.ped, ignore or 4)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
Wait(0)
|
Wait(0)
|
||||||
local retval, hit, endCoords, surfaceNormal, materialHash, entityHit = GetShapeTestResultIncludingMaterial(handle)
|
local retval, hit, coords, surfaceNormal, materialHash, entityHit = GetShapeTestResultIncludingMaterial(handle)
|
||||||
|
|
||||||
if retval ~= 1 then
|
if retval ~= 1 then
|
||||||
---@diagnostic disable-next-line: return-type-mismatch
|
return hit, entityHit, coords, surfaceNormal, materialHash
|
||||||
return hit, entityHit, endCoords, surfaceNormal, materialHash
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return lib.raycast
|
return lib.raycast
|
||||||
|
|||||||
Reference in New Issue
Block a user