2022-12-20 17:54:59 +11:00
|
|
|
lib.raycast = {}
|
|
|
|
|
|
2022-08-03 17:22:45 +10:00
|
|
|
local StartShapeTestLosProbe = StartShapeTestLosProbe
|
|
|
|
|
local GetShapeTestResultIncludingMaterial = GetShapeTestResultIncludingMaterial
|
2024-05-08 02:27:00 +08:00
|
|
|
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
|
2022-08-03 17:22:45 +10:00
|
|
|
|
2022-11-26 02:02:02 +11:00
|
|
|
---@alias ShapetestIgnore
|
|
|
|
|
---| 1 GLASS
|
|
|
|
|
---| 2 SEE_THROUGH
|
|
|
|
|
---| 3 GLASS | SEE_THROUGH
|
|
|
|
|
---| 4 NO_COLLISION
|
|
|
|
|
---| 7 GLASS | SEE_THROUGH | NO_COLLISION
|
|
|
|
|
|
|
|
|
|
---@param flags number? Line of sight flags, defaults to 511 (see: https://docs.fivem.net/natives/?_0x377906D8A31E5586).
|
2023-04-17 06:50:12 +02:00
|
|
|
---@param ignore ShapetestIgnore? Defaults to 4.
|
|
|
|
|
---@param distance number? Defaults to 10.
|
2022-08-18 01:58:54 +10:00
|
|
|
---@return boolean hit
|
2022-08-03 17:22:45 +10:00
|
|
|
---@return number entityHit
|
2022-08-18 01:58:54 +10:00
|
|
|
---@return vector3 endCoords
|
2022-08-03 17:22:45 +10:00
|
|
|
---@return vector3 surfaceNormal
|
|
|
|
|
---@return number materialHash
|
2023-04-17 06:50:12 +02:00
|
|
|
function lib.raycast.cam(flags, ignore, distance)
|
2024-05-08 02:27:00 +08:00
|
|
|
local camCoords = GetFinalRenderedCamCoord()
|
|
|
|
|
local destination = camCoords + getForwardVector() * (distance or 10)
|
|
|
|
|
local handle = StartShapeTestLosProbe(camCoords.x, camCoords.y, camCoords.z, destination.x, destination.y,
|
|
|
|
|
destination.z, flags or 511, cache.ped, ignore or 4)
|
2022-08-03 17:22:45 +10:00
|
|
|
|
2024-05-08 02:27:00 +08:00
|
|
|
while true do
|
|
|
|
|
Wait(0)
|
|
|
|
|
local retval, hit, coords, surfaceNormal, materialHash, entityHit = GetShapeTestResultIncludingMaterial(handle)
|
2022-08-03 17:22:45 +10:00
|
|
|
|
2024-05-08 02:27:00 +08:00
|
|
|
if retval ~= 1 then
|
|
|
|
|
return hit, entityHit, coords, surfaceNormal, materialHash
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-08-03 17:22:45 +10:00
|
|
|
end
|
|
|
|
|
|
2022-11-26 02:02:02 +11:00
|
|
|
return lib.raycast
|