<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/GetScreenRotationFromWorldPosition?action=history&amp;feed=atom</id>
	<title>GetScreenRotationFromWorldPosition - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/GetScreenRotationFromWorldPosition?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetScreenRotationFromWorldPosition&amp;action=history"/>
	<updated>2026-06-26T19:18:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetScreenRotationFromWorldPosition&amp;diff=38838&amp;oldid=prev</id>
		<title>Ccw: Created page with &quot;{{Useful Function}} __NOTOC__ This function returns a screen relative rotation to a world position. The returned rotation can be used in dxDrawImage  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetScreenRotationFromWorldPosition&amp;diff=38838&amp;oldid=prev"/>
		<updated>2014-02-13T08:07:26Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Useful Function}} __NOTOC__ This function returns a screen relative rotation to a world position. The returned rotation can be used in &lt;a href=&quot;/wiki/DxDrawImage&quot; title=&quot;DxDrawImage&quot;&gt;dxDrawImage&lt;/a&gt;  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Useful Function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function returns a screen relative rotation to a world position. The returned rotation can be used in [[dxDrawImage]]&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;float getScreenRotationFromWorldPosition( float targetX, float targetY, float targetZ )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''targetX''': The target world X position&lt;br /&gt;
* '''targetY''': The target world Y position&lt;br /&gt;
* '''targetZ''': The target world Z position&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Clientside script&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function getScreenRotationFromWorldPosition( targetX, targetY, targetZ )&lt;br /&gt;
    -- Get camera position and rotation&lt;br /&gt;
    local camX, camY, _, lookAtX, lookAtY = getCameraMatrix()&lt;br /&gt;
    local camRotZ = math.atan2 ( ( lookAtX - camX ), ( lookAtY - camY ) )&lt;br /&gt;
&lt;br /&gt;
    -- Calc direction to&lt;br /&gt;
    local dirX = targetX - camX&lt;br /&gt;
    local dirY = targetY - camY&lt;br /&gt;
&lt;br /&gt;
    -- Calc rotation to&lt;br /&gt;
    local dirRotZ = math.atan2(dirX,dirY)&lt;br /&gt;
&lt;br /&gt;
    -- Calc relative rotation to&lt;br /&gt;
    local relRotZ = dirRotZ - camRotZ&lt;br /&gt;
&lt;br /&gt;
    -- Return rotation in degrees&lt;br /&gt;
    return math.deg(relRotZ)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example draws an arrow which points to the centre of the map.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler('onClientRender', root,&lt;br /&gt;
    function ()&lt;br /&gt;
        local rotation = getScreenRotationFromWorldPosition( 0, 0, 0 )&lt;br /&gt;
        dxDrawImage( 100,100, 100,100, &amp;quot;arrow.png&amp;quot;, rotation )&lt;br /&gt;
    end&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Ccw</name></author>
	</entry>
</feed>