<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Maratis forum - Use of lua in maratis3d iOS project for hit testing]]></title>
		<link>http://forum.maratis3d.com/viewtopic.php?id=434</link>
		<description><![CDATA[The most recent posts in Use of lua in maratis3d iOS project for hit testing.]]></description>
		<lastBuildDate>Tue, 25 Sep 2012 16:56:57 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2693#p2693</link>
			<description><![CDATA[<div class="quotebox"><cite>Petr wrote:</cite><blockquote><p>Thank you for sharing!</p></blockquote></div><p>there was i bug, i updated post<br />P.S.<br /></p><div class="codebox"><pre><code>changed 
        MVector3 rayD = camera-&gt;getUnProjectedPoint(MVector3(x * float(width), y * float(height), 1));
to 
        MVector3 rayD = camera-&gt;getUnProjectedPoint(MVector3(x * float(width), (1 - y) * float(height), 1));</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (Mikey)]]></author>
			<pubDate>Tue, 25 Sep 2012 16:56:57 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2693#p2693</guid>
		</item>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2683#p2683</link>
			<description><![CDATA[<p>Thank you for sharing!</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Mon, 24 Sep 2012 06:35:24 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2683#p2683</guid>
		</item>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2681#p2681</link>
			<description><![CDATA[<p>here is the function i created to pick objects :<br /></p><div class="codebox"><pre><code>int pickObject(void)
{
    MEngine * engine = MEngine::getInstance();
    MScriptContext * script = engine-&gt;getScriptContext();
    
    if (script-&gt;getArgsNumber() == 3)
    {
        MOCamera * camera = (MOCamera *)script-&gt;getPointer(0);
        float x = script-&gt;getFloat(1);
        float y = script-&gt;getFloat(2);

        MPhysicsContext * physics = engine-&gt;getPhysicsContext();
        
        unsigned int width, height;
        engine-&gt;getSystemContext()-&gt;getScreenSize(&amp;width, &amp;height);

        MVector3 rayO = camera-&gt;getTransformedPosition();
        MVector3 rayD = camera-&gt;getUnProjectedPoint(MVector3(x * float(width), (1 - y) * float(height), 1));
        rayD = rayO + ((rayD - rayO).getNormalized() * (camera-&gt;getClippingFar() - camera-&gt;getClippingNear()));

        unsigned int objId;
        if (physics-&gt;isRayHit(rayO, rayD, &amp;objId))
        {
            MLevel * level = engine-&gt;getLevel();
            MScene * scene = level-&gt;getCurrentScene();
            unsigned int entCount = scene-&gt;getEntitiesNumber();
            for (unsigned int i = 0; i &lt; entCount; ++i)
            {
                MOEntity * entity = scene-&gt;getEntityByIndex(i);
                MPhysicsProperties * phyProps = entity-&gt;getPhysicsProperties();
                if (phyProps)
                {
                    if (phyProps-&gt;getCollisionObjectId() == objId)
                    {
                        script-&gt;pushPointer(entity);
                        return 1;
                    }
                }
            }
        }
    }
    
    return 0;
}</code></pre></div><p>Usage :</p><div class="codebox"><pre><code>obj = pickObject(Camera, x, y)
if obj then
...
end</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (Mikey)]]></author>
			<pubDate>Sun, 23 Sep 2012 16:09:15 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2681#p2681</guid>
		</item>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2551#p2551</link>
			<description><![CDATA[<p>There is multiple way to do it, you can use RayHit by sending a ray starting from the touch position,<br />or you can use collision detection :</p><p>- move a cube (collision physics as a ghost) depending on the touch position.<br />- detect if there is a collision with other objects (also set as ghost) : <a href="http://wiki.maratis3d.org/index.php?title=IsCollisionBetween">http://wiki.maratis3d.org/index.php?tit &#133; ionBetween</a></p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Sat, 08 Sep 2012 13:19:59 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2551#p2551</guid>
		</item>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2518#p2518</link>
			<description><![CDATA[<p>I cannot find method for hit testing in lua maratis3d docs. I found method RayHit, but I cannot understand fhow can I use it to determine on which mesh touch occurs.<br />SDK has functionality for this?</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Thu, 06 Sep 2012 07:24:16 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2518#p2518</guid>
		</item>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2513#p2513</link>
			<description><![CDATA[<p>Ok, thank you.</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Wed, 05 Sep 2012 14:26:31 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2513#p2513</guid>
		</item>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2508#p2508</link>
			<description><![CDATA[<p>You can communicate from lua to c++ (and so for objective c I suppose)</p><p>For example by creating your own script function :</p><div class="codebox"><pre><code>int exampleFunc(void)
{
    MEngine * engine = MEngine::getInstance();
    MScriptContext * script = engine-&gt;getScriptContext();
    
    if(script-&gt;getArgsNumber() == 2)
    {
        int firstArgument = script-&gt;getInteger(0);
        int secondArgument = script-&gt;getInteger(1);
        
        // do a simple addition
        script-&gt;pushInteger(firstArgument+secondArgument);
        return 1; 
    }
    
    return 0;
}



MyGame * game = NULL;

void StartPlugin(void)
{
    // get engine
    MEngine * engine = MEngine::getInstance();

    // add script function
    MScriptContext * script = engine-&gt;getScriptContext();
    script-&gt;addFunction(&quot;testFunction&quot;, exampleFunc);
    
    // set my game
    game = new MyGame();
    engine-&gt;setGame(game);
}

void EndPlugin(void)
{
    SAFE_DELETE(game);
}</code></pre></div><p>There is also examples to download here : <a href="http://www.maratis3d.org/?page_id=53">http://www.maratis3d.org/?page_id=53</a></p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 05 Sep 2012 10:45:27 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2508#p2508</guid>
		</item>
		<item>
			<title><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2506#p2506</link>
			<description><![CDATA[<p>Look through here for all the functions:</p><p><a href="http://wiki.maratis3d.org/index.php?title=Lua_functions_list">http://wiki.maratis3d.org/index.php?tit &#133; tions_list</a></p><p>All the functions you need for this are in there.<br />It&#039;s just a matter of taking the time to actually do some research.</p>]]></description>
			<author><![CDATA[dummy@example.com (hedphelym)]]></author>
			<pubDate>Wed, 05 Sep 2012 09:56:00 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2506#p2506</guid>
		</item>
		<item>
			<title><![CDATA[Use of lua in maratis3d iOS project for hit testing]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2504#p2504</link>
			<description><![CDATA[<p>I make a 3D gallery app.<br />In that app I have three meshes on the&nbsp; first &quot;screen&quot;.<br />Each mesh represents category of 3D models to view.<br />When user tap on one of these meshes, camera should translate to next screen with several meshes.<br />Can I use lua for mesh hit testing (ie determine to what the mesh user touched)?</p><p>Can I send (trigger) events from lua to my Objective C iOS code?<br />For example, when user select one of the categories and&nbsp; camera translates to it, I need to change UI (buttons, labels) in app.</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Wed, 05 Sep 2012 09:14:15 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2504#p2504</guid>
		</item>
	</channel>
</rss>
