BoxCollisionShape not in right position with mesh

0x46B

28-11-2010 14:49:28

Hello everyone,
I´ve tried the demo described in the Tutorial 2 here: http://www.ogre3d.org/tikiwiki/OgreBullet+Tutorial+2&structure=Libraries
My problem is, that the CollisionBox seems to get an offset somewhere, so it don´t match my mesh anymore.

The only thing I´ve changed is the mesh and the size, because my mesh is too small, but that seems not to affect anything, because in "originalscaling" the problem was there, too.

node->scale(0.05f, 0.05f, 0.05f); // the cube is too big for us
size *= 0.05f; // don't forget to scale down the Bullet-box too

to

node->scale(0.5f, 0.5f, 0.5f); // the cube is too big for us
size *= 0.5f; // don't forget to scale down the Bullet-box too

I´ve tried it with the defaultninja, too, but the behaviour is the same.
Here are the screens so you can see, what I am talking about:

http://img602.imageshack.us/i/bbox.png/


http://img232.imageshack.us/i/bbox2.png/

I´ve tried to change this line,
defaultBody->setShape(node,
sceneBoxShape,
0.6f, // dynamic body restitution
0.6f, // dynamic body friction
1.0f, // dynamic bodymass
position, // starting position of the box
Quaternion(0,0,0,1));// orientation of the box

to something like this
defaultBody->setShape(node,
sceneBoxShape,
0.6f, // dynamic body restitution
0.6f, // dynamic body friction
1.0f, // dynamic bodymass
position-Ogre::Vector3(xOffset,yOffset,zOffset), // starting position of the box
Quaternion(0,0,0,1));// orientation of the box

too, but that seems to only affect where the box and the mesh is starting, not the offset between them.
I don´t know exactly where the problem is, so my searches around the net don´t were very sucessful. I would be happy about any clue, how to fix this.

Thanks in advance,
0x46B

0x46B

04-12-2010 22:37:54

Okay, with some trial and error I´ve got it working with these lines(for the box):
OgreBulletCollisions::BoxCollisionShape *sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size);
OgreBulletCollisions::CompoundCollisionShape* comShape = new OgreBulletCollisions::CompoundCollisionShape();
comShape->addChildShape(sceneBoxShape, Ogre::Vector3(0,-0.7,-1.3), Ogre::Quaternion(1,0,0,0));

OgreBulletDynamics::RigidBody *defaultBody = new OgreBulletDynamics::RigidBody("defaultBoxRigid" + Ogre::StringConverter::toString(*m_nNumEntitiesInstanced),m_World);
defaultBody->setShape(node,
comShape,
0.6f, // dynamic body restitution
0.8f, // dynamic body friction
8.0f, // dynamic bodymass
position, // starting position of the box
direction);// orientation of the box


But I don´t know, where this offsets came from and I don´t believe, that the only solution is trying some random numbers till it works fine. Is there any nicer solution of this problem? Maybe some sort of calculation for the needed offset or something like that would work fine, too.

Fish

05-12-2010 01:25:18

Did it work fine with the "cube.mesh" used in the wiki article? If so, the offset you see with your model is a function of your models origin. If the origin of your cube model is not at the geometric center of the model then you need to provide bullet with an offset to properly center the physics object, as you just did.

Same issue with the Ninja. Notice that the geometric center of the physics object is at the feet of the model. That's because the origin of the model is at the feet.

- Fish

newmyl

06-05-2011 16:50:29

I meet with the same problem with you.First, I will show my thanks for your post. And I have test that If i set the offset equals the bounding's center, they will match exactly.