WorldToScreen: Difference between revisions
From Onset Developer Wiki
Created page with "{{Info|Function|Client|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|WorldToScreen(loc.X, loc.Y, loc.Z)}} {{FuncParameters}} {{FuncParam|loc.X|__EDIT_ME__}} {{FuncPara..." |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Info|Function|Client|1.0}} | {{Info|Function|Client|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Projects a 3d world location into 2d screen space location. Also returns a bool indicating whether the 3d location is actually on the screen.}} | ||
{{FuncSyntax|WorldToScreen( | {{FuncSyntax|WorldToScreen(x, y, z)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam| | {{FuncParam|x|Coordinate X in world space.}} | ||
{{FuncParam| | {{FuncParam|y|Coordinate Y in world space.}} | ||
{{FuncParam| | {{FuncParam|z|Coordinate Z in world space.}} | ||
{{ | {{FuncReturnValues}} | ||
* bResult: True on success or False if the world location is not on screen. | |||
* ScreenX: Converted screen X coordinate. | |||
* ScreenY: Converted screen Y coordinate. | |||
== Example == | == Example == | ||
Example taken from https://github.com/BlueMountainsIO/OnsetLuaScripts/blob/6ef0c5406e84a434ca2d497c470404802f05e0d6/horizon/client/esp.lua | |||
<syntaxhighlight lang="Lua"> | |||
function OnRenderHUD() | |||
if EnableESP ~= 1 then | |||
return | |||
end | |||
--local lX, lY, lZ = GetCameraLocation() | |||
local x, y, z | |||
local ScreenX, ScreenY = GetScreenSize() | |||
local t = { 1 } | |||
--local bones = GetPlayerBoneNames() | |||
for k, v in pairs(GetStreamedPlayers()) do | |||
local x, y, z = GetPlayerLocation(v) | |||
local sX, sY, sZ = WorldToScreen(x, y, z) | |||
if sZ ~= 0.0 then | |||
--local length = GetDistance3D(x, y, z, lX, lY, lZ) | |||
--DrawPoint3D(x, y, z) | |||
--DrawRect(sX, sY, 10.0, 40.0) | |||
DrawLine(ScreenX / 2, ScreenY, sX, sY) | |||
DrawBox(sX - 50, sY - 100, 100, 200) | |||
--[[for k2, v2 in pairs(bones) do | |||
local bX, bY, bZ = GetPlayerBoneLocation(v, v2) | |||
DrawPoint3D(bX, bY, bZ, 3.0) | |||
end]]-- | |||
end | |||
end | |||
end | |||
AddEvent("OnRenderHUD", OnRenderHUD) | |||
</syntaxhighlight> | |||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
* [[ScreenToWorld]] |
Latest revision as of 14:44, 23 December 2020
Description
Projects a 3d world location into 2d screen space location. Also returns a bool indicating whether the 3d location is actually on the screen.
Syntax
WorldToScreen(x, y, z)
Parameters
- x
Coordinate X in world space. - y
Coordinate Y in world space. - z
Coordinate Z in world space.
Return Values
- bResult: True on success or False if the world location is not on screen.
- ScreenX: Converted screen X coordinate.
- ScreenY: Converted screen Y coordinate.
Example
Example taken from https://github.com/BlueMountainsIO/OnsetLuaScripts/blob/6ef0c5406e84a434ca2d497c470404802f05e0d6/horizon/client/esp.lua
function OnRenderHUD()
if EnableESP ~= 1 then
return
end
--local lX, lY, lZ = GetCameraLocation()
local x, y, z
local ScreenX, ScreenY = GetScreenSize()
local t = { 1 }
--local bones = GetPlayerBoneNames()
for k, v in pairs(GetStreamedPlayers()) do
local x, y, z = GetPlayerLocation(v)
local sX, sY, sZ = WorldToScreen(x, y, z)
if sZ ~= 0.0 then
--local length = GetDistance3D(x, y, z, lX, lY, lZ)
--DrawPoint3D(x, y, z)
--DrawRect(sX, sY, 10.0, 40.0)
DrawLine(ScreenX / 2, ScreenY, sX, sY)
DrawBox(sX - 50, sY - 100, 100, 200)
--[[for k2, v2 in pairs(bones) do
local bX, bY, bZ = GetPlayerBoneLocation(v, v2)
DrawPoint3D(bX, bY, bZ, 3.0)
end]]--
end
end
end
AddEvent("OnRenderHUD", OnRenderHUD)