Aligning the mesh with collision shape

Milryth

25-07-2007 02:47:50

Hi,

I have a simplified polygon that I'm using for collision detection, which uses a much more complex mesh on top for display. The problem is, the mesh is displaced from where the collision shape is located. It seems to be consistently lower than the actual collision shape. I'm trying to offset the mesh so that it lines up correctly with the collision shape, but I'm not having any success. I've tried moving the scene node, but I don't think that's the way to go given some of the forum posts I've seen. Anyone have any tips? Is it a problem with the mesh model, or is there a way to fix it in the code? Also, the mesh needs to rotate correctly along with the collision shape, so that's why I'm more concerned as to the reason why this happening (i.e. if I simply offset the mesh in the y direction, and the actor rotates, the mesh might pivot around the wrong point while the collision shape pivots correctly, thus misaligning the mesh and collision shape).

Thanks for any help.

betajaen

25-07-2007 09:24:30

You need to center the mesh in your modeler. It is the most permanent and efficient way.

daedar

25-07-2007 12:28:34

I had the same problem when I wanted to have my meshed exploded in many pieces. What I've done is something like that:

Vector3 offset = ent->getBoundingBox().getCenter()*node->getScale();
NxOgre::Body* b = PhysicEngine::getSingleton()->getNxScene()->createBody("crash"+StringConverter::toString(i)+"_"+vStats->mesh, new NxOgre::CubeShape(size.x, size.y, size.z, "offset: "+StringConverter::toString(offset)), position, "mass: "+StringConverter::toString(vStats->mass)+", Group: ObjectsGroup");


In fact I'm getting the center of the bounding box (offset) and I apply this offset to the CubeShape, it works well!

luis

25-07-2007 12:40:22

another way would be:

- create the NxOgre body/character without mesh
- manually create your entity (loading the mesh with Ogre in the usual way)
- create a SceneNode and attach your entity with the desired offset in the new SceneNode
- attach your new SceneNode to the Body's scenenode.

Before deleting Body/Character you should manually detach and remove the entity and the scenenode or you'll have a 'leak' there.

I'm doing this to have the wheelshape aligned with the outer part of the wheel mesh (the wheels I use in my vehicles are a bit fat).

Milryth

25-07-2007 22:29:53

Thanks, I got it to work by realigning the model. Apparently, it was some problem with how LexiExporter works with 3DS MAX. I had to move the pivot of the object and then reset the XForm.

But I've got another question: Have the 6-Degrees of Freedom joints been implemented in NxOgre yet? I only need them because it's simple to save and load joint descriptors from them, which I'm using to lock a wheel in place during runtime. Essentially, I have a wheel that's attached to a body using a revolute joint, and then when the user presses some key, the revolute joint becomes a fixedJoint, thus preventing all rotational motion. Do I really have to use the 6DOF joint, or is there some easier way to lock and unlock joints? I've tried creating a fixed joint on top of the revolute joint when the joint needs to be locked, but when I try breaking or deleting the fixed joint, I get a runtime error.

Thanks for any help.