Casting a MovableObject as a Entity

Mwr

23-04-2006 14:54:14

I'm trying to convert a Axiom project to OgreDotNet and am having problems casting a MovableObject to a Entity. It always fails.

So my code would be something like:

Entity ent=(Entity) scenenode_ptr.GetAttachedObject(0);

If I use :

MovableObject movable=scenenode_ptr.GetAttachedObject(0);

then it works fine but as I need to change the animations on the entity this is no good to me.

As Entity is meant to inherit from MovableObject, I have no idea why it is not working. So I was just wondering if anyone else has had this problem or if it is just me. I'm currently using the precompiled dll's (found at the top of the forum, while I decide if its worth converting all the project).

rastaman

23-04-2006 18:32:25

With OgreDotNet you have to remember that it uses proxy classes, all of the work is done in Ogre. So if a function is defined to return a MoveableObject the .Net class that is created is a MoveableObject. In Ogre it maybe an entity but the proxy class can only go by what the header files has as the return. So it creates a proxy class for the return class (MoveableObject in this case) and passes it an IntPtr (c++ to the actual Ogre object). All of ODN's proxy classes have a constructor that takes an IntPtr to the object and Boolean value that if true tells the proxy class to delete the object when the proxy class is destroyed.

In short you can create a new Entity proxy class with the MoveableObject's pointer and false so it doesn't destroy. Like this:

Entity ent= new Entity( MovableObject.getCPtr(scenenode_ptr.GetAttachedObject(0)).Handle, false);

Mwr

24-04-2006 12:00:15

Thanks for your reply and help. I should have thought of that.

Another problem I'm having is removing a scenenode from the scene manager.

My code is like:

MovableObject movable=scenenode_ptr.GetAttachedObject(0);
scenenode_ptr.DetachObject(movable);
mSceneManager.RootSceneNode.RemoveChild(scenenode_ptr); //I've tried casting the scenenode_ptr as a standard node but that has the same effect.

I know that the scenenode is attached to the root scene node, but this will always freeze up. If I leave out the removechild call then it is fine but as far as I know the DetachObject call doesn't remove the node from the scenemanager.

Also has anyone been able to compile the dll's using Code::blocks (either with MingW or microsoft c++ toolkit) and sharpdevelop ?

Mwr

25-04-2006 00:34:10

Well I managed to get the dll's to compile with codeblocks (had to call swig manually though) and sharpdevelop but got a couple of errors in OgreBindings related to: getSkyPlaneGenParameters, getSkyBoxGenParameters and SkyDomeGenParameters. It says they are undeclared identifiers.

The calls are like:

SWIGEXPORT void * SWIGSTDCALL CSharp_SceneManager_getSkyDomeGenParameters(void * jarg1)

If I comment those sections out then the dll compiles and works.

The other thing is that I'm not noticing much improvement (Frame rate wise) when doing a release compile over the debug dll's (therefore the frame rate I'm getting isn't very good), not sure if this is because I'm using the microsoft toolkit compiler.

rastaman

25-04-2006 00:59:08

got a couple of errors in OgreBindings related to: getSkyPlaneGenParameters, getSkyBoxGenParameters and SkyDomeGenParameters. It says they are undeclared identifiers.

fixed in update 2006-04-23

The other thing is that I'm not noticing much improvement (Frame rate wise) when doing a release compile over the debug dll's (therefore the frame rate I'm getting isn't very good), not sure if this is because I'm using the microsoft toolkit compiler.
well OgreDotNet does nothing but call Ogre. are you using Ogre's release dlls?