OgreNewt 2 tutorial, various problems

Blaxar

15-08-2014 11:53:19

Hi everyone.

Sorry if this has been answered before, but I didn't find concrete solutions to my "various problems" (and most recent posts are like two years old).

So, I've been following those instructions here and there's several things worth mentioning:

- All calls to CollisionPrimitives in this tutorial are missing one mandatory argument: the id (a unique integer value corresponding to the collision object I guess), so the code does not straight compile unless you perform the adequate modifications by adding some integer argument to each constructor.

- None of the mesh files used in this tutorial are provided by my version of Ogre (1.9), in fact here's what my /usr/share/OGRE/Media/models/ folder contains:

athene.mesh geosphere4500.mesh penguin.mesh sphere.mesh
Barrel.mesh geosphere8000.mesh penguin.skeleton spine.mesh
column.mesh jaiqua.mesh razor.mesh spine.mesh.skeleton
cornell.mesh jaiqua.skeleton robot.mesh tudorhouse.mesh
cube.mesh knot.mesh robot.skeleton uv_sphere.mesh
facial.mesh ninja.mesh RZR-002.mesh WoodPallet.mesh
fish.mesh ninja.skeleton ShaderSystem.mesh
fish.skeleton ogrehead.mesh sibenik.mesh


No cylinder.mesh or cone.mesh to be seen, and the closest thing to a "box" I have is "cube.mesh", so I ended up using "cube.mesh" instead of "box.mesh" and I skipped all the parts about adding a cylinders and cones.
I've downloaded Ogre version 1.7.4 to check if those mesh files were provided, they are not either, so I have no clue where to find them.

Those two points taken in consideration, here's my code:

//Floor
Ogre::Vector3 size(10.0, 1.0, 10.0);
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Ogre::Entity* ent = mSceneMgr->createEntity("floorobj", "cube.mesh");
node->attachObject(ent);
node->setScale(size);

OgreNewt::CollisionPtr col(new OgreNewt::CollisionPrimitives::TreeCollision(mWorld, ent, true, 0));

OgreNewt::Body* floorbody = new OgreNewt::Body( mWorld, col );
floorbody->attachNode(node);

floorbody->setPositionOrientation( Ogre::Vector3(0, -5, 0), Ogre::Quaternion::IDENTITY );

// Box
size = Ogre::Vector3(10, 10, 10);
node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ent = mSceneMgr->createEntity("cube_body", "cube.mesh");
node->attachObject(ent);
node->setScale(size);

//Rigid body
OgreNewt::CollisionPrimitives::Box *boxcol = new OgreNewt::CollisionPrimitives::Box(mWorld, size,1);
col = OgreNewt::CollisionPtr(boxcol);
OgreNewt::Body* bod = new OgreNewt::Body( mWorld, col);
bod->attachNode(node);

//Initial position
bod->setPositionOrientation( Ogre::Vector3(-2, 20, 2), Ogre::Quaternion::IDENTITY);


Ogre::Real mass = 10.0;
Ogre::Vector3 inertia, centerOfMass;
boxcol->calculateInertialMatrix(inertia, centerOfMass);

inertia*=mass;

bod->setMassMatrix( mass, inertia );
bod->setCenterOfMass(centerOfMass);

bod->setStandardForceCallback();


This compiles, but here's what it looks like running:





Note that I first had to move the camera away, otherwise I'm in the middle of the mess and don't see properly.

At this point I conclude that "cube.mesh" is initially not the same as "box.mesh" since it seems I have a big scaling problem, So I fiddle a bit the code to adjust scales (for both the floor and the box):





This provides a better understanding of the situation, but this is still not what it's supposed to do, the box get stuck at this position in the floor instead of having its bottom face onto the top face of the floor.

I do see the box falling when running the application, going from a higher position to the point you see in the screenshots, but I don't understand why it collides like this.
I've also tried to set a different scale for the Ogre entity and the corresponding CollisionPrimitives (knowing that "cube.mesh" was not intended to be used here), but still nothing conclusive.

Any clue ?

[EDIT]

Between the moment I submitted this and the approval by the moderators, I tried various stuff ending up thinking it was an Ogre problem, hence my post on the official Ogre forum, turns out it isn't (that's why I marked it [SOLVED], because Ogre itself wasn't culprit), however the informations there can be useful to the problem here.

In short: the TreeCollision Primitive doesn't work with every kind of mesh, I got a segfault with "box.mesh" (I found it eventually) and "cube.mesh" gives a weird behaviour (see images above), but the Box Primitive works well with "box.mesh".

Something worth mentioning: if I declare the floor object as a Box Primitive (instead of a collision tree) with "box.mesh", I get the expected result: a "box.mesh" entity falling on a flat "box.mesh" used as a ground (and stopping on top of it, like it's supposed to)

Even though this sort of do the trick for this single tutorial, missing the TreeCollision Primitive might quickly become annoying, as I understand it: it's the one used to declare physical objects with the same shape as a given ogre mesh file (even more complex ones, not only boxes, cones, etc.)

[/EDIT]

Thanks in advance.

Lax

05-10-2014 20:40:07

The tutorial is no longer conform with OgreNewt2, hence some small adaptations are required, thats true.

Now to your collision problem:
your collision hull is not at the center of the box. When you create the box collision, you need to adapt the offset vector. Take a closer look in the function OgreNewt::CollisionPrimitives::Box(...)

You could also enable the OgreNewt collision debugger, to paint collision hulls, to see where they are...