getScreenCoordFromWorldCoord
GET_SCREEN_COORD_FROM_WORLD_COORD0x34E82F05DF2974F5The GTA V native GET_SCREEN_COORD_FROM_WORLD_COORD of the GRAPHICS namespace, as LS:MP client scripts call it: the global function getScreenCoordFromWorldCoord, in JavaScript and in Lua.
getScreenCoordFromWorldCoord(
worldX: number,
worldY: number,
worldZ: number
): [ok: boolean, screenX: number, screenY: number]getScreenCoordFromWorldCoord(
worldX: number,
worldY: number,
worldZ: number
): boolean, number, numberUsage
const [ok, screenX, screenY] = getScreenCoordFromWorldCoord(worldX, worldY, worldZ);local ok, screenX, screenY = getScreenCoordFromWorldCoord(worldX, worldY, worldZ)Three consecutive numbers can be given as one vector: { x, y, z } (or [x, y, z]) in JavaScript, a Vector3 in Lua.
const [ok, screenX, screenY] = getScreenCoordFromWorldCoord(world);local ok, screenX, screenY = getScreenCoordFromWorldCoord(world)Parameters
| Parameter | Type | JavaScript | Lua |
|---|---|---|---|
worldX | float | number | number |
worldY | float | number | number |
worldZ | float | number | number |
Returns
3 values, in this order: an array in JavaScript, multiple return values in Lua.
| # | Value | Type | JavaScript | Lua | Description |
|---|---|---|---|---|---|
| 1 | ok | BOOL | boolean | boolean | The native’s own return value. |
| 2 | screenX | float | number | number | output |
| 3 | screenY | float | number | number | output |
On LS:MP
lsmp.worldToScreen returns the same values as an object: { onScreen, x, y }.
Notes
From the community native database. Names are LS:MP’s; samples may be written for C++ or another framework.
Convert a world coordinate into its relative screen coordinate. (WorldToScreen)
Returns a boolean; whether or not the operation was successful. It will return false if the coordinates given are not visible to the rendering camera.
For .NET users...
VB:
Public Shared Function World3DToScreen2d(pos as vector3) As Vector2
Dim x2dp, y2dp As New Native.OutputArgument
Native.Function.Call(Of Boolean)(Native.Hash.GET_SCREEN_COORD_FROM_WORLD_COORD , pos.x, pos.y, pos.z, x2dp, y2dp)
Return New Vector2(x2dp.GetResult(Of Single), y2dp.GetResult(Of Single))
End FunctionC#:
Vector2 World3DToScreen2d(Vector3 pos)
{
var x2dp = new OutputArgument();
var y2dp = new OutputArgument();
Function.Call<bool>(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD , pos.X, pos.Y, pos.Z, x2dp, y2dp);
return new Vector2(x2dp.GetResult<float>(), y2dp.GetResult<float>());
}
//USE VERY SMALL VALUES FOR THE SCALE OF RECTS/TEXT because it is dramatically larger on screen than in 3D, e.g '0.05' small.It does seem however that calling setDrawOrigin then your natives, then ending it. Seems to work better for certain things such as keeping boxes around people for a predator missile e.g.
Reference
- Namespace
- Graphics GRAPHICS
- In the game
BOOL GET_SCREEN_COORD_FROM_WORLD_COORD(float worldX, float worldY, float worldZ, float* screenX, float* screenY)- Hash
0x34E82F05DF2974F5- Formerly
_WORLD3D_TO_SCREEN2D