<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Maratis forum - rotate the object?]]></title>
		<link>http://forum.maratis3d.com/viewtopic.php?id=1011</link>
		<description><![CDATA[The most recent posts in rotate the object?.]]></description>
		<lastBuildDate>Mon, 07 Jul 2014 12:31:42 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: rotate the object?]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6962#p6962</link>
			<description><![CDATA[<div class="codebox"><pre><code>obj1 = getObject(&quot;obj1&quot;)
obj2 = getObject(&quot;obj2&quot;)

function onSceneUpdate()

    dir = normalize(getPosition(obj2) - getPosition(obj1))
    lookAt(obj1, dir, 1)

end</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Mon, 07 Jul 2014 12:31:42 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6962#p6962</guid>
		</item>
		<item>
			<title><![CDATA[Re: rotate the object?]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6961#p6961</link>
			<description><![CDATA[<p>I don&#039;t use behavior, I use Lua function.<br />I copied all three functions:<br /></p><div class="codebox"><pre><code>function getLength2d(vec)
    ...
end
function normalize2d(vec)
    ...
end
function lookAt(object, dir, rotSpeed)
    ...
end
obj1 = getObject(&quot;obj1&quot;)
obj2 = getObject(&quot;obj2&quot;)

function onSceneUpdate()
    dir = getPosition(obj2)
    lookAt(obj1, dir, 1)
end</code></pre></div><p>nothing happens.</p>]]></description>
			<author><![CDATA[dummy@example.com (ant0n)]]></author>
			<pubDate>Mon, 07 Jul 2014 11:58:23 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6961#p6961</guid>
		</item>
		<item>
			<title><![CDATA[Re: rotate the object?]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6960#p6960</link>
			<description><![CDATA[<p>look-at is a behavior :<br />select your object in the editor &gt; go to behavior tab &gt; add a look-at behavior &gt; set the name of the target</p><p>(except is you use the script I gave before, in this case copy/paste it on top of your script)</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Mon, 07 Jul 2014 11:36:47 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6960#p6960</guid>
		</item>
		<item>
			<title><![CDATA[Re: rotate the object?]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6959#p6959</link>
			<description><![CDATA[<p>I have not function lookAt(). What am I doing wrong?<br />--onSceneUpdate()<br />dir = getPosition(object2)<br />lookAt(object1, dir, 1)</p>]]></description>
			<author><![CDATA[dummy@example.com (ant0n)]]></author>
			<pubDate>Mon, 07 Jul 2014 09:43:37 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6959#p6959</guid>
		</item>
		<item>
			<title><![CDATA[Re: rotate the object?]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6944#p6944</link>
			<description><![CDATA[<p>Thanks anael! This is exactly what I need.</p>]]></description>
			<author><![CDATA[dummy@example.com (ant0n)]]></author>
			<pubDate>Tue, 24 Jun 2014 10:42:06 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6944#p6944</guid>
		</item>
		<item>
			<title><![CDATA[Re: rotate the object?]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6943#p6943</link>
			<description><![CDATA[<p>You can use the look-at behavior :<br />- create an invisible object called &quot;dummy&quot;<br />- add a look-at behavior to your first object and set the target to the dummy<br />- in script, set the dummy X and Z position to be the X and Z position of the object you want to point at<br />- set the dummy Y position to 0 or to your first object Y position</p><br /><p>Or use some math in pure lua, but it&#039;s more complicated (this example rotate on Z axis) :</p><div class="codebox"><pre><code>-- get 2d vector length
function getLength2d(vec)

    return math.sqrt(vec[1]*vec[1] + vec[2]*vec[2])

end

-- normalize 2d vector
function normalize2d(vec)

    length = getLength2d(vec)
    vec[1] = vec[1] / length
    vec[2] = vec[2] / length
    return vec

end

-- lookAt
function lookAt(object, dir, rotSpeed)

    -- compute object X dir and Y dir
    rot = getRotation(object)

    zAngle = math.rad(rot[3])
    sinZ = math.sin(zAngle)
    cosZ = math.cos(zAngle)

    YDir = normalize2d({sinZ, -cosZ})
    XDir = {-YDir[2], YDir[1]}

    -- dot products for orientation and angle
    ori = (dir[1]*XDir[1] + dir[2]*XDir[2])
    angle = math.acos(dir[1]*YDir[1] + dir[2]*YDir[2])

    if ori &lt; 0 then
        angle = - angle
    end

    rotate(object, {0, 0, 1}, math.deg(angle) * rotSpeed)

end</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Tue, 24 Jun 2014 09:32:28 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6943#p6943</guid>
		</item>
		<item>
			<title><![CDATA[rotate the object?]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6942#p6942</link>
			<description><![CDATA[<p>hi all! <br />how to rotate the object in the direction of another entity only on the Y axis (lua)?</p>]]></description>
			<author><![CDATA[dummy@example.com (ant0n)]]></author>
			<pubDate>Tue, 24 Jun 2014 03:16:37 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6942#p6942</guid>
		</item>
	</channel>
</rss>
