slashkeyvalue

coé

Jul 31st, 2022
1,633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. local glm = require("glm")
  2.  
  3. function ScreenPositionToCameraRay(screenX, screenY)
  4.     local pos = GetFinalRenderedCamCoord()
  5.     local rot = glm.rad(GetFinalRenderedCamRot(2))
  6.  
  7.     local q = glm.quatEulerAngleZYX(rot.z, rot.y, rot.x)
  8.     return pos,glm.rayPicking(
  9.         q * glm.forward(),
  10.         q * glm.up(),
  11.         glm.rad(GetFinalRenderedCamFov()),
  12.         GetAspectRatio(true),
  13.         0.10000, -- GetFinalRenderedCamNearClip(),
  14.         10000.0, -- GetFinalRenderedCamFarClip(),
  15.         screenX * 2 - 1, -- scale mouse coordinates from [0, 1] to [-1, 1]
  16.         screenY * 2 - 1
  17.     )
  18. end
  19.  
  20. -- RegisterNUICallback...
  21. local w, h = GetActiveScreenResolution()
  22.  
  23. -- data.mouseX e mouseY são recebidos via NUICallback
  24. -- correspondem às propriedades pageX e pageY do evento `mousemove`
  25. local mx = data.mouseX / w
  26. local my = data.mouseY / h
  27.  
  28. local r_pos, r_dir = ScreenPositionToCameraRay(mx, my)
  29.  
  30. local b = r_pos + 10000 * r_dir
  31.  
  32. local handle = StartExpensiveSynchronousShapeTestLosProbe(r_pos.x, r_pos.y, r_pos.z, b.x, b.y, b.z, 8, PlayerPedId(), 7)
  33.  
  34. local _, hit, pos, surface, entity = GetShapeTestResult(handle)
Advertisement
Add Comment
Please, Sign In to add comment