Difference between revisions of "D3d.World2Screen"

From Nomad DB
(Created page with "Translates 3d-world coordinates to 2d-coordinates on the screen. {{Warning|This function can only be called from inside OnRender event!}} ==Syntax...")
 
 
Line 1: Line 1:
 +
{{Page_WD2}}{{Page_MDE}}{{Page_WDL}}
 
Translates 3d-world coordinates to 2d-coordinates on the screen.
 
Translates 3d-world coordinates to 2d-coordinates on the screen.
  
Line 31: Line 32:
  
 
==Related Pages==
 
==Related Pages==
*[[WD2 ScriptHook: Rendering]]
+
*[[ScriptHook: Rendering]]
  
 
[[Category:WD2 ScriptHook Lua]]
 
[[Category:WD2 ScriptHook Lua]]
 +
[[Category:WDL ScriptHook Lua]]

Latest revision as of 11:11, 15 April 2021

Translates 3d-world coordinates to 2d-coordinates on the screen.

This function can only be called from inside OnRender event!

Syntax

d3d.World2Screen(x, y, z)
  • x, y, z: number (World coordinates)
  • Returns:
    • visible: boolean (is on screen)
    • x, y: number (screen coordinates)

Example

Draws a white square on the local players' position, which originates at their feet.

function script:OnRender()
	local entityId = GetLocalPlayerEntityId()
	local xPos = GetEntityPosition(entityId, 0)
	local yPos = GetEntityPosition(entityId, 1)
	local zPos = GetEntityPosition(entityId, 2)

	local isVisible, screenX, screenY = d3d.World2Screen(xPos, yPos, zPos)
	if isVisible then
		d3d.DrawRect(screenX, screenY, 50, 50)
	end
end

Related Pages