How to attach physics body to mesh that's controlled w/ OGRE

Xenomorph

08-02-2010 20:47:29

Hi there!
I'm new to physics and didn't really bother to include it in my game until now. I have a mesh in my game that the user controls, but it is moved around by OGRE. Now the problem is that I want to add a physics body to this mesh so I can use it for collisions and other physics stuff. I don't want to control the mesh with NxOgre or so. I still want to be able to move my object with the ogre functions. I hope you understand what I want to do.
So, how can i just attach a physics body to a mesh and still be able to control the mesh with Ogre and the physics body just moves with it?

LucaMoller

09-02-2010 19:37:09

I think you are complicating things.
The straight way of doing it, is to have a physical body with the appearence of the mesh you are using with ogre (so that the mesh follows the body automatically, not the opposite). Now you have to think about what kind of shape your phisical body you will have, you might need to aproximate it to some simple shapes together (like cubes, spheres, capsules...) or you could use a triangle mesh made with Flour from your .mesh file (but I think this option only works fine for static objects, with collisions and other physics stuff, and in your case you want the body to move, so it is not static). And finally you would have to control the body position through NxOgre, if you are setting its position directly, then I think this body would have to be kinematic, otherwise you could use a character controller to do it (you could try to work adding forces to a dynamic body to move it too, but it just sounds impossible).

This might have sounded a bit complicated, but it is because in a physic simulation we dont expect, at first, a body with the position being set all over the time (you need to treat that as a special case, or else strange things might happen) :wink:

betajaen

09-02-2010 19:49:33

^^^^ What he said.


But what you could do is; Get the difference between positions (newest-last) then multiply it by deltaTime, then try adding that as a linearVelocity.

Xenomorph

09-04-2010 17:10:11

First of all, thanks for the replies!
Second, I have looked into that stuff and now I have the problem that my main object in the game is a .scene file. So, the question is how can I create a kinematic body with a .scene file? My .scene file has multile meshes and has node and mesh animations. I tried combining everything into one mesh and I was able to attach this mesh with a physical actor. The only problem I have when i do that is that I lose all my animations. Obviously I want to keep them.
If there is a way of attaching a .scene object to a kinematic actor then I think I can use all that stuff in my game which would be fantastic.

alexx109

10-04-2010 02:49:38

i think u have the same problem that i do xD

u think that we shoulda control the mesh trought our rendering engine, not trought the physics engine, and we only use it for phisycs... but, if what we must do is control the entire "game" through a phisycs system... so i guess i must start to put that in my head...