GET_WORLD_COORD_FROM_SCREEN_COORD
Converts a screen coordinate into its relative world coordinate.
Signature
void GET_WORLD_COORD_FROM_SCREEN_COORD(float screenX, float screenY, Vector3* worldVector, Vector3* normalVector);Parameters
| Name | Type | Description |
|---|---|---|
screenX | float | A screen horizontal axis coordinate (0.0 - 1.0). |
screenY | float | A screen vertical axis coordinate (0.0 - 1.0). |
worldVector | Vector3* | The world coord vector pointer. |
normalVector | Vector3* | The screen normal vector pointer. |
Returns void — A Vector3 representing the world coordinates relative to the specified screen coordinates and a screen plane normal Vector3 (normalised).
Description
Converts a screen coordinate into its relative world coordinate.
Usage
local worldVector, normalVector = GetWorldCoordFromScreenCoord(screenX, screenY)
-- always works, by hash
local worldVector, normalVector = Citizen.InvokeNative(0xc81d0659, screenX, screenY, Citizen.PointerValueVector(), Citizen.PointerValueVector())JavaScript and C#
const [worldVector, normalVector] = GetWorldCoordFromScreenCoord(screenX, screenY);
// by hash
const [worldVector, normalVector] = Citizen.invokeNative('0xc81d0659', screenX + 0.0000001, screenY + 0.0000001, Citizen.pointerValueVector(), Citizen.pointerValueVector());var worldVector = new OutputArgument();
var normalVector = new OutputArgument();
Function.Call((Hash)0xc81d0659, screenX, screenY, worldVector, normalVector);
// worldVector.GetResult<Vector3>()
// normalVector.GetResult<Vector3>()- Float parameters: Lua integers (
10, or whole numbers decoded from NUI/JSON) are sent as ints and read as garbage. Write10.0orvalue + 0.0. The generated JS wrappers add0.0000001to non-zero floats for the same reason. - Pointer (out) arguments are not passed in Lua/JS: their values are returned after the result, in order.
Examples
CreateThread(function()
while true do
local screenX = GetDisabledControlNormal(0, 239)
local screenY = GetDisabledControlNormal(0, 240)
local world, normal = GetWorldCoordFromScreenCoord(screenX, screenY)
local depth = 10
local target = world + normal * depth
DrawSphere(target.x, target.y, target.z, 0.5, 255, 0, 0, 0.5)
Wait(0)
end
end)Sources
Something wrong or missing? Contribute a verified note — corrections ship through pull requests.