Skip to main content

History: OGRE to MOGRE

Source of version: 2 (current)

Copy to clipboard
            Guidelines for converting Ogre C++ code to Mogre C# code

{maketoc}

!!.NET naming conventions
* Methods use pascal case instead of camel case.
* Properties instead of get/set methods. Ogre methods that get transformed to properties are:
** get/setXXXX methods
** getXXXX methods
** bool isXXXX methods

Example:
__OGRE__
{CODE(wrap="1", colors="c++")}mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
 SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();{CODE}
__MOGRE__
{CODE(wrap="1", colors="c#")}mSceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);
 SceneNode node = mSceneMgr.RootSceneNode.CreateChildSceneNode();{CODE}
__Note:__ If you see a property that starts with a lower case letter, it means that the property is not a conversion of get/set methods but a direct wrapper of a class field variable (i.e [http://www.ogre3d.org/docs/api/html/classOgre_1_1Mesh.html#Ogre_1_1PatchMesho0|Mesh.sharedVertexData])

!!.NET Events
Ogre uses Listener classes to provide notifications of various events. The pattern involves subclassing an abstract Listener class (that gets the notifications), and subscribing to a notifier using a __addListener__ method. .NET provides Events for this mechanism, so in Mogre there are no add/removeListener methods. Instead, the notifier exposes one event for each function defined in the Ogre's abstract Listener class.

Example:
__OGRE__
{CODE(wrap="1", colors="c++")}mFrameListener = new SkeletalAnimationFrameListener(mWindow, mCamera);
 mRoot->addFrameListener(mFrameListener);

 class RefractionTextureListener : public RenderTargetListener
 {
 public:
     void preRenderTargetUpdate(const RenderTargetEvent& evt)
     {
     ........
     }
 };
 
 RenderTarget *rttTex = mTexture->getBuffer()->getRenderTarget();
 rttTex->addListener(&mRefractionListener);{CODE}

__MOGRE__
{CODE(wrap="1", colors="c#")}mRoot.FrameStarted += new FrameListener.FrameStartedHandler(Skeletal_FrameStarted);

 RenderTarget rttTex = mTexture.GetBuffer().GetRenderTarget();
 rttTex.PreRenderTargetUpdate += new RenderTargetListener.PreRenderTargetUpdateHandler(rttTex_PreRenderTargetUpdate);
 
 void rttTex_PreRenderTargetUpdate(RenderTargetEvent_NativePtr evt)
 {
 ...
 }{CODE}

!!See also
* In a short ((Mogre porting example)) you can see how to port by means of a complete snipit.
* How to port functions with ''void*'' parameter - look to [http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=8354|this thread]