<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Maratis forum - Programming question]]></title>
		<link>http://forum.maratis3d.com/viewtopic.php?id=992</link>
		<description><![CDATA[The most recent posts in Programming question.]]></description>
		<lastBuildDate>Thu, 29 Jan 2015 14:18:36 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=7476#p7476</link>
			<description><![CDATA[<p>Hi !<br />here you are :</p><div class="codebox"><pre><code>MOEntity * entity = (MOEntity *)parent; // be sure that parent is an entity
MPhysicsProperties * phyProps = entity-&gt;getPhysicsProperties();
unsigned int objId = phyProps-&gt;getCollisionObjectId();</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Thu, 29 Jan 2015 14:18:36 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=7476#p7476</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=7475#p7475</link>
			<description><![CDATA[<p>Hi,<br />i need to move object and i tried to do it with<br /></p><div class="codebox"><pre><code>MPhysicsContext * Phys=engine-&gt;getPhysicsContext();
MObject3d * parent = getParentObject();
Phys-&gt;addCentralForce(objId?, MVector3(x,y,0));</code></pre></div><p>how can i get objectId?</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Tue, 27 Jan 2015 16:17:32 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=7475#p7475</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6859#p6859</link>
			<description><![CDATA[<p>I can see the video now, promising !!</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Tue, 03 Jun 2014 20:26:38 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6859#p6859</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6858#p6858</link>
			<description><![CDATA[<p>wow i didn&#039;t think about that,<br />in this way it willn&#039;t change native scene&#039;s script<br />p.s updated link to video<br />p.p.s updated code with anael&#039;s advice</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Tue, 03 Jun 2014 18:36:47 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6858#p6858</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6857#p6857</link>
			<description><![CDATA[<p>seems nice,</p><p>about the script,<br />it will be faster if you call a function from the current scene script so you are not loading/compiling the script each time :</p><p>replace m_scriptName with m_functionName and use &quot;callFunction&quot; instead :</p><div class="codebox"><pre><code>if(input-&gt;onKeyDown(&quot;MOUSE_BUTTON1&quot;))
    SampleScript-&gt;callFunction(m_functionName);</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Tue, 03 Jun 2014 14:16:41 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6857#p6857</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6856#p6856</link>
			<description><![CDATA[<p>So, workable version of text behavior(to create simple menu)<br />MouseClick.h<br /></p><div class="codebox"><pre><code>/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleGamePlugin
// MouseClick.h
// 
// Code : Anael Seghezzi &amp; hog
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef _MOUSE_CLICK_H
#define _MOUSE_CLICK_H

#include &lt;MEngine.h&gt;


class MouseClick : public MBehavior
{
public:

    // constructors / destructors
    MouseClick(MObject3d * parentObject);
    MouseClick(MouseClick &amp; behavior, MObject3d * parentObject);
    ~MouseClick(void);

private:
    
    // custom variables

    const char* m_cameraName;
    const char* m_sceneName;
    MVector4 m_colour;
    const char* m_soundName;
    const char* m_functionName;
    bool m_play;
    
public:

    // destroy
    void destroy(void);

    // get new
    static MBehavior * getNew(MObject3d * parentObject);

    // get copy
    MBehavior * getCopy(MObject3d * parentObject);

    // name
    static const char * getStaticName(void){ return &quot;MouseClick&quot;; }
    const char * getName(void){ return getStaticName(); }

    // variables
    unsigned int getVariablesNumber(void);
    MVariable getVariable(unsigned int id);

    // events (virtuals from MBehavior class)
    void update(void);
    //void onBeginScene(void);
    void runEvent(int param){}
};

#endif</code></pre></div><p>MouseClick.cpp<br /></p><div class="codebox"><pre><code>/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleGamePlugin
// MouseClick.cpp
// 
// Code : Anael Seghezzi &amp; hog
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#include &quot;MouseClick.h&quot;


/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Init, this part is always similar, constructor, copy constructor etc
/////////////////////////////////////////////////////////////////////////////////////////////////////////

// constructor
MouseClick::MouseClick(MObject3d * parentObject):
MBehavior(parentObject),
m_cameraName(&quot;&quot;),
m_sceneName(&quot;&quot;),
m_colour(1,1,1,1),
m_soundName(&quot;&quot;),
m_functionName(&quot;&quot;),
m_play(true)
{}

// copy constructor
MouseClick::MouseClick(MouseClick &amp; behavior, MObject3d * parentObject):
MBehavior(parentObject),
m_cameraName(behavior.m_cameraName),
m_sceneName(behavior.m_sceneName),
m_colour(behavior.m_colour),
m_soundName(behavior.m_soundName),
m_functionName(behavior.m_functionName),
m_play(behavior.m_play)
{}

// destructor
MouseClick::~MouseClick(void)
{}

// destroy function : always similar
void MouseClick::destroy(void)
{
    delete this;
}

// getNew function : always similar
MBehavior * MouseClick::getNew(MObject3d * parentObject)
{
    return new MouseClick(parentObject);
}

// getCopy function : always similar
MBehavior * MouseClick::getCopy(MObject3d * parentObject)
{
    return new MouseClick(*this, parentObject);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables, allow to access custom variable from script and from Maratis Editor
/////////////////////////////////////////////////////////////////////////////////////////////////////////

unsigned int MouseClick::getVariablesNumber(void){
    return 5;
}

MVariable MouseClick::getVariable(unsigned int id)
{
    switch(id)
    {
    default:
        return MVariable(&quot;NULL&quot;, NULL, M_VARIABLE_NULL);
    case 0:
        return MVariable(&quot;cameraName&quot;, &amp;m_cameraName, M_VARIABLE_STRING);
    case 1:
    return MVariable(&quot;sceneName&quot;, &amp;m_sceneName, M_VARIABLE_STRING);
    case 2:
        return MVariable(&quot;colour&quot;, &amp;m_colour, M_VARIABLE_VEC4);
    case 3:
    return MVariable(&quot;soundName&quot;, &amp;m_soundName, M_VARIABLE_STRING);
    case 4:
    return MVariable(&quot;functionName&quot;, &amp;m_functionName, M_VARIABLE_STRING);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Events
/////////////////////////////////////////////////////////////////////////////////////////////////////////










// update function (called by MGame class by default)
void MouseClick::update(void)
{
MEngine * engine = MEngine::getInstance();//engine
MGame * game = engine-&gt;getGame();//game
MSystemContext * system = engine-&gt;getSystemContext();
MInputContext * input=engine-&gt;getInputContext();

if( !game-&gt;isRunning())
        return;

    MObject3d * parent = getParentObject();
    MLevel * SampleLevel=engine-&gt;getLevel();//level
MScene *    SampleScene = SampleLevel-&gt;getSceneByName(m_sceneName);//scene
MOText*    SampleText = SampleScene-&gt;getTextByName(parent-&gt;getName());//text
MOCamera*    SampleCamera=SampleScene-&gt;getCameraByName(m_cameraName);//camera
    MOSound * SampleSound=NULL;
    SampleSound=SampleScene-&gt;getSoundByName(m_soundName);
    MScriptContext * SampleScript=engine-&gt;getScriptContext();
MBox3d*    bbox = SampleText-&gt;getBoundingBox();
unsigned int width=0;
unsigned int height=0;
    system-&gt;getScreenSize(&amp;width, &amp;height);
    
float mouseX = input-&gt;getAxis(&quot;MOUSE_X&quot;);
float mouseY = input-&gt;getAxis(&quot;MOUSE_Y&quot;);
MVector3 origin = SampleCamera-&gt;getTransformedPosition();
MVector3 dest = SampleCamera-&gt;getUnProjectedPoint(MVector3(mouseX*width, (1.0f - mouseY)*height, 1.0f));
MVector3 localOrigin = SampleText-&gt;getInversePosition(origin);
MVector3 localDest = SampleText-&gt;getInversePosition(dest);

    if(isEdgeToBoxCollision(localOrigin, localDest,bbox-&gt;min,bbox-&gt;max)){        
        SampleText-&gt;setColor(m_colour);    
        if(SampleSound)
            if(m_play){
            SampleSound-&gt;play();
            m_play=false;
            }
            if(input-&gt;onKeyDown(&quot;MOUSE_BUTTON1&quot;))
            //if(SampleScript)
            SampleScript-&gt;callFunction(m_functionName);
    }
    else
    {
        SampleText-&gt;setColor(MVector4(0.8,0.8,0.8,0.6));
    m_play=true;
    
    }
    
}</code></pre></div><p>Behavior properties:<br />1)cameraName - camera that captures text <br />2) sceneName - scene, where texts/sounds take place<br />3)colour - text highlighting(r,y,b,a), when you put mouse on it<br />4)soundName - sound, when you put mouse on text<br />5)functionName - the function that would be called, when we press on text (must be in you scene script)<br />example:<br /></p><div class="codebox"><pre><code>...
function funcName()
...
end</code></pre></div><p>you can change the default text colour by editing<br /></p><div class="codebox"><pre><code>SampleText-&gt;setColor(MVector4(0.8,0.8,0.8,0.6));</code></pre></div><p>video<br /><a href="http://youtu.be/_l2oAbihUX4">http://youtu.be/_l2oAbihUX4</a></p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Tue, 03 Jun 2014 11:55:39 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6856#p6856</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6854#p6854</link>
			<description><![CDATA[<p>First doesn&#039;t work but second works perfectly<br />I&#039;ve found solution to my problem with empty scene:&nbsp; i used mvariable in behavior with empty blank (such as &quot;Camera Name&quot;), and you mustn&#039;t use such names (good name is &quot;cameraName&quot; for example). May be it will be useful for somebody</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Mon, 02 Jun 2014 13:25:36 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6854#p6854</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6853#p6853</link>
			<description><![CDATA[<p>yes, I forget to add the object position :</p><div class="codebox"><pre><code>unsigned int width = 0;
unsigned int height = 0;
system-&gt;getScreenSize(&amp;width, &amp;height);

float mouseX = input-&gt;getAxis(&quot;MOUSE_X&quot;);
float mouseY = input-&gt;getAxis(&quot;MOUSE_Y&quot;);

// ray
MVector3 origin = camera-&gt;getTransformedPosition();
MVector3 dest = camera-&gt;getUnProjectedPoint(MVector3(mouseX*width, (1.0f - mouseY)*height, 1.0f));

// bounding box
MBox3d * bbox = text-&gt;getBoundingBox();
MVector3 pos = text-&gt;getTransformedPosition();

if(isEdgeToBoxCollision(origin, dest, pos + bbox-&gt;min, pos + bbox-&gt;max))
    // intersection</code></pre></div><p>or (slower but more correct) :</p><div class="codebox"><pre><code>unsigned int width = 0;
unsigned int height = 0;
system-&gt;getScreenSize(&amp;width, &amp;height);

float mouseX = input-&gt;getAxis(&quot;MOUSE_X&quot;);
float mouseY = input-&gt;getAxis(&quot;MOUSE_Y&quot;);

// ray
MVector3 origin = camera-&gt;getTransformedPosition();
MVector3 dest = camera-&gt;getUnProjectedPoint(MVector3(mouseX*width, (1.0f - mouseY)*height, 1.0f));

// bounding box
MBox3d * bbox = text-&gt;getBoundingBox();

// local ray
MVector3 localOrigin = text-&gt;getInversePosition(origin);
MVector3 localDest = text-&gt;getInversePosition(dest);

if(isEdgeToBoxCollision(localOrigin, localDest, bbox-&gt;min, bbox-&gt;max))
    // intersection</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Sun, 01 Jun 2014 18:38:23 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6853#p6853</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6852#p6852</link>
			<description><![CDATA[<div class="quotebox"><cite>anael wrote:</cite><blockquote><p>In this case you can use the bounding box of the text and send a ray :</p><div class="codebox"><pre><code>unsigned int width = 0;
unsigned int height = 0;
system-&gt;getScreenSize(&amp;width, &amp;height);

float mouseX = input-&gt;getAxis(&quot;MOUSE_X&quot;);
float mouseY = input-&gt;getAxis(&quot;MOUSE_Y&quot;);

// ray
MVector3 origin = camera-&gt;getTransformedPosition();
MVector3 dest = camera-&gt;getUnProjectedPoint(MVector3(mouseX*width, (1.0f - mouseY)*height, 1.0f));

// bounding box
MBox3d * bbox = text-&gt;getBoundingBox();

if(isEdgeToBoxCollision(origin, dest, bbox-&gt;min, bbox-&gt;max))
    // intersection</code></pre></div></blockquote></div><p>I&#039;ve fixed crashes, but it doesn&#039;t work.<br />when I put my resolution instead of height/width it doesn&#039;t work too<br />Any ideas?<br />hmm, and when i use plugin and save scene with MouseClick behavior on object, the next time i open it, i take an empty scene ( have to back up), even if i didn&#039;t change Game.dll</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Sun, 01 Jun 2014 17:15:13 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6852#p6852</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6840#p6840</link>
			<description><![CDATA[<p>Huge help!</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Thu, 29 May 2014 20:10:11 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6840#p6840</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6837#p6837</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>1)How do we pick up behaviors? I did in this way, but does it mean that i take first behavior on object?</p></blockquote></div><p>yes, and yes.<br />Just be sure there is a behavior before calling getBehavior(0), check how much behaviors are attached to the object by using getBehaviorsNumber().</p><div class="quotebox"><blockquote><p>2)where do i write runEvent?</p></blockquote></div><p>yes, but I don&#039;t think you are allowed to set a default value for param in a virtual function : &quot;int param=0&quot;<br />do it this way :</p><div class="codebox"><pre><code>void MouseClick::runEvent(int param) // use param as a code
{
    switch(param)
    {
        case 0:
        do_something();
        break;

        case 1001:
        scene_begin();
        break;

        // etc
    }
}</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Thu, 29 May 2014 17:36:44 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6837#p6837</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6835#p6835</link>
			<description><![CDATA[<p>oooooooops, I did something wrong <br />1)How do we pick up behaviors? I did in this way, but does it mean that i take first behavior on object?<br /></p><div class="codebox"><pre><code>ClickBeh=MenuText-&gt;getBehavior(0);
ClickBeh-&gt;runEvent(0);</code></pre></div><p> <br />2)where do i write runEvent?<br />I declare it in header file in this way<br /></p><div class="codebox"><pre><code>void runEvent(int param);</code></pre></div><p>and then in cpp file of beh:<br /></p><div class="codebox"><pre><code>void MouseClick::runEvent(int param=0){
...
}</code></pre></div><p>can i do in this way?(maratis crashes(it&#039;s my classic phrase now :D )</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Thu, 29 May 2014 16:57:18 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6835#p6835</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6820#p6820</link>
			<description><![CDATA[<p>MBehavior don&#039;t have onBeginScene, it&#039;s only for MGame :<br /><a href="https://code.google.com/p/maratis/source/browse/trunk/dev/MSDK/MEngine/Includes/MBehavior.h">https://code.google.com/p/maratis/sourc &#133; Behavior.h</a></p><p>But in your game&#039;s onBeginScene, you can call your native behaviors,<br />or you can call behavior-&gt;runEvent(someNumber) and implement &quot;runEvent&quot; in your behavior.</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Sun, 25 May 2014 15:43:34 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6820#p6820</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6819#p6819</link>
			<description><![CDATA[<p>can i add OnBeginScene to my behavior?<br />i&#039;ve tried to add virtual void to mbehavior.h, and to mouseclick.h and to mybehavior.h, but after that use of mybehavior(from example) and mouseclick behaviors crash maratis</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Sun, 25 May 2014 11:06:49 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6819#p6819</guid>
		</item>
		<item>
			<title><![CDATA[Re: Programming question]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=6806#p6806</link>
			<description><![CDATA[<p>thanks, I&#039;ll try it</p>]]></description>
			<author><![CDATA[dummy@example.com (hog)]]></author>
			<pubDate>Wed, 21 May 2014 19:29:28 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=6806#p6806</guid>
		</item>
	</channel>
</rss>
