<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Maratis forum - Physics]]></title>
	<link rel="self" href="http://forum.maratis3d.com/extern.php?action=feed&amp;tid=451&amp;type=atom"/>
	<updated>2012-09-25T16:55:42Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.maratis3d.com/viewtopic.php?id=451</id>
		<entry>
			<title type="html"><![CDATA[Re: Physics]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2692#p2692"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>anael wrote:</cite><blockquote><p>I think the y mouse needs to be inverted :<br />Your camera is not in ortho mode ?</p><div class="codebox"><pre><code>MVector3 cameraPos = camera-&gt;getTransformedPosition();
MVector3 mousePos3d = camera-&gt;getUnProjectedPoint(MVector3(x*width, height - y*height, 1));
    
MVector3 vec = (mousePos3d - cameraPos).getNormalized();
    
MVector3 rayO = pos + vec*camera-&gt;getClippingNear();
MVector3 rayD = pos + vec*camera-&gt;getClippingFar();</code></pre></div></blockquote></div><p>Perspective. Thanks for hint, i missed about y axis <img src="http://forum.maratis3d.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[Mikey]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1103</uri>
			</author>
			<updated>2012-09-25T16:55:42Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2692#p2692</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Physics]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2691#p2691"/>
			<content type="html"><![CDATA[<p>I think the y mouse needs to be inverted :<br />Your camera is not in ortho mode ?</p><div class="codebox"><pre><code>MVector3 cameraPos = camera-&gt;getTransformedPosition();
MVector3 mousePos3d = camera-&gt;getUnProjectedPoint(MVector3(x*width, height - y*height, 1));
    
MVector3 vec = (mousePos3d - cameraPos).getNormalized();
    
MVector3 rayO = pos + vec*camera-&gt;getClippingNear();
MVector3 rayD = pos + vec*camera-&gt;getClippingFar();</code></pre></div>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2012-09-25T13:49:20Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2691#p2691</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Physics]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2690#p2690"/>
			<content type="html"><![CDATA[<p>Thanks for fast response, when i tried to pick objects (with function i wrote in my plugin) i faced the problem that after rotation the body is not rotated, so <br /></p><div class="quotebox"><blockquote><p>The rotation/scale etc transform the bodies yes.</p></blockquote></div><p>so, i think i have a problem with my function below <img src="http://forum.maratis3d.com/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /><br />can you look at this function and say whats wrong ? (I use only perspective projection)<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), 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>sometimes if works wrong (don&#039;t detect collision)</p>]]></content>
			<author>
				<name><![CDATA[Mikey]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1103</uri>
			</author>
			<updated>2012-09-25T12:14:51Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2690#p2690</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Physics]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2689#p2689"/>
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Is there a way to display physic bodies ?</p></blockquote></div><p>&gt; But we&#039;ll add that on the TODO list</p>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2012-09-25T11:54:00Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2689#p2689</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Physics]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2688#p2688"/>
			<content type="html"><![CDATA[<p>There is no physics display in editor,<br />but you can use the box.mesh, cylinder.mesh, cone.mesh and sphere.mesh of &quot;Small Demos&quot; example<br />to build a collision body, set it invisible and then attach an object to it.</p><p>The rotation/scale etc transform the bodies yes.</p>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2012-09-25T11:53:00Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2688#p2688</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Physics]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=2687#p2687"/>
			<content type="html"><![CDATA[<p>Is there a way to display physic bodies ?<br />Does fuctions set rotation and else transform bodies ?</p>]]></content>
			<author>
				<name><![CDATA[Mikey]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1103</uri>
			</author>
			<updated>2012-09-25T11:23:22Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=2687#p2687</id>
		</entry>
</feed>
