So, I decided to go with the C++/CLI route. To avoid confusion with ODN let's call this wrapper 'Mogre' (Managed Ogre). C++/CLI is a vast improvement over the awful Managed Extensions, and wrapping Ogre with C++/CLI provides many advanced features/possibilities that are not even available in C#. You have absolute and low-level control of how the wrapping works, giving you the ability to make optimizations and integrate Ogre to the CLR seamlessly.
For example, I wanted the Ogre objects and the wrapping CLR objects to be interconnected so that when you do this:
Code: Select all
Camera cam1 = sceneMgr.CreateCamera("PlayerCam");
Camera cam2 = sceneMgr.GetCamera("PlayerCam");
bool areEqual = (cam1 == cam2);
The C++/CLI wrapping code is clean and straightforward. For example, once you take care of the various conversions, here's how the individual method wrapping goes:
Code: Select all
Camera^ CreateCamera(String^ name)
{
DECLARE_OGRE_STRING(oName, name)
return _native->createCamera(oName);
}
void SetPosition(Real x, Real y, Real z)
{
_native->setPosition(x, y, z);
}
void SetPosition( Vector3 vec )
{
_native->setPosition( vec );
}
Vector3 GetPosition(void)
{
return _native->getPosition();
}
Code: Select all
root.Initialise(false);
System.Collections.Specialized.NameValueCollection col = new System.Collections.Specialized.NameValueCollection();
// Render on a Panel
col["externalWindowHandle"] = panel1.Handle.ToString();
window = root.CreateRenderWindow("", 0, 0, false, col);
Code: Select all
public virtual void CreateFrameListener()
{
_root.FrameStarted += new FrameEventHandler(app_frameStarted);
}
void app_FrameStarted(object sender, FrameEventArgs e)
{
.........
}
The subclassing of Mogre wrapper classes provides many possibilities, for example a custom SceneManager can be implemented using your favourite .NET language and with the help of a "plugin proxy" the SceneManager will be loaded and used by Ogre.
The big disadvantage of Mogre is that it mixes native and managed code, so it can't be used in linux by Mono.
I plan on releasing the Mogre's source once I wrap a decent amount of Ogre's classes, to give back something to this great community.