<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Maratis forum - Use of lua in maratis3d iOS project for hit testing]]></title>
	<link rel="self" href="http://forum.maratis3d.com/extern.php?action=feed&amp;tid=434&amp;type=atom"/>
	<updated>2012-09-25T16:56:57Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.maratis3d.com/viewtopic.php?id=434</id>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2693#p2693"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Mikey]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1103</uri>
			</author>
			<updated>2012-09-25T16:56:57Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2693#p2693</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2683#p2683"/>
			<content type="html"><![CDATA[<p>Thank you for sharing!</p>]]></content>
			<author>
				<name><![CDATA[Petr]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1081</uri>
			</author>
			<updated>2012-09-24T06:35:24Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2683#p2683</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2681#p2681"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Mikey]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1103</uri>
			</author>
			<updated>2012-09-23T16:09:15Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2681#p2681</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2551#p2551"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2012-09-08T13:19:59Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2551#p2551</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2518#p2518"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Petr]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1081</uri>
			</author>
			<updated>2012-09-06T07:24:16Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2518#p2518</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2513#p2513"/>
			<content type="html"><![CDATA[<p>Ok, thank you.</p>]]></content>
			<author>
				<name><![CDATA[Petr]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1081</uri>
			</author>
			<updated>2012-09-05T14:26:31Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2513#p2513</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2508#p2508"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2012-09-05T10:45:27Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2508#p2508</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2506#p2506"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[hedphelym]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=181</uri>
			</author>
			<updated>2012-09-05T09:56:00Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2506#p2506</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Use of lua in maratis3d iOS project for hit testing]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2504#p2504"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Petr]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1081</uri>
			</author>
			<updated>2012-09-05T09:14:15Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2504#p2504</id>
		</entry>
</feed>
