WorldToScreen: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Info|Function|Client|1.0}}
{{Info|Function|Client|1.0}}


{{FuncDescription|Converts a 3d world location into 2d screen space location. Also returns a bool indicating whether the 3d location is actually on the screen.}}
{{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(x, y, z)}}
{{FuncSyntax|WorldToScreen(x, y, z)}}
Line 16: Line 16:


== Example ==
== Example ==
__EDIT_ME__
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}}
__EDIT_ME__
* [[ScreenToWorld]]

Latest revision as of 14:44, 23 December 2020

WorldToScreen

Type: Function
Context: Client
Introduced: v1.0

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)

See also