Exported mesh doesn't overlap its OgreNewt Collision Box

ncazanav

03-03-2007 15:22:31

I have used oFusion to export a cube of size 100 (with XForm reset). I am using OgreNewt and I am trying to add a collision box, but I don't manage to have both
my cube mesh and my box collision object overlaped : there is still an offset between the two, it seems that the center are differents

here's what I get



And here is my sample code (it is written with Mogre, but shouldn't be different from the original C++ lib)

1- The creation of the scene :

// /////////////////////////// Manual Scene
Entity planeEnt = mgr.CreateEntity("plane01", "plane01.mesh");
SceneNode planeNode = mgr.RootSceneNode.CreateChildSceneNode("plane01Node");
planeNode.AttachObject(planeEnt);

Vector3 size = new Vector3(1f, 1f, 1f);
Entity boxEnt = mgr.CreateEntity("box04", "box04.mesh");
SceneNode boxNode = mgr.RootSceneNode.CreateChildSceneNode("box04Node");
boxNode.SetScale(size);
boxNode.AttachObject(boxEnt);
boxEnt.SetMaterialName("Murs");

camera = mgr.CreateCamera("Camera02");
camera.Position = new Vector3(-336.414f, 71.1905f, 13.3086f);
camera.Orientation = new Quaternion(-0.501067f, 0.49893f, -0.49893f, -0.501067f);
camera.LookAt(new Vector3(355.638f, 71.1905f, 10.3511f));
mWindow.AddViewport(camera);

Light li = mgr.CreateLight("Omni01");
li.Type = Light.LightTypes.LT_POINT;
li.Position = new Vector3(-155.58f, 153.848f, -121.603f);


2- The creation of the Box collsion object :

// /////////////////////////// Manual Physics
MogreNewt.Collision mCol = new MogreNewt.CollisionPrimitives.Box(mNewtonManager.NewtonWorld, 100*size);
MogreNewt.Body mBoxBody = new MogreNewt.Body(mNewtonManager.NewtonWorld, mCol);
mCol.Dispose();

mBoxBody.attachToNode(boxNode);
// base mass on the size of the object.
float mass = size.x * size.y * size.z * 2.5f;
// calculate the inertia based on box formula and mass
Vector3 inertia = MogreNewt.MomentOfInertia.CalcBoxSolid(mass, size);
mBoxBody.setMassMatrix(mass, inertia);
mBoxBody.setPositionOrientation(boxNode.Position, boxNode.Orientation);


What's wrong in my code?

darkscorp

04-03-2007 22:36:11

I'm having the same problem with the exported meshes and OgreNewt,

I have a design of a racing track, when I export it as separate meshes and apply a treecollision to any mesh it doesn't fit, but when I export it as a single "Editable mesh" everything works fine.

BergBoy

05-03-2007 02:41:02

I had this problem last year. Simply modify the code that creates your physics world to have an offset to acocunt for misalligned objects. Its just a difference between the 2 systems so you need to make a work around for it. Its generally easy enough to solve with mathes, its not going to be guessing so it wont be inaccurate or anything. Boxes are easy. Barrels are a bit more effort...

Lioric

05-03-2007 16:23:47

What are the results of displaying the sceneNode AABB?
is that in the screenshot the AABB of the phy object?