create a cylinder shape on each bone of mesh

kulebril

07-04-2011 03:42:22

Hi:

I'm trying to put a Cylinder or capsule around the bones of the mesh.

I got this code:

OgreBulletCollisions::CompoundCollisionShape * comp= new OgreBulletCollisions::CompoundCollisionShape();

for (int e=0;e<Entity->getSkeleton()->getNumBones();e++)
{
Ogre::Bone * B=Entity->getSkeleton()->getBone(e);
if (B->numChildren()>0)
{
Ogre::Real radius,height;
Ogre::Vector3 ax;

Ogre::Vector3 Position=B->_getDerivedPosition();
Ogre::Vector3 ChildPosition=B->getChild(0)->_getDerivedPosition();

Ogre::Quaternion q = ChildPosition.getRotationTo(Position);

Ogre::Vector3 Size=B->getChild(0)->getPosition();

Ogre::Real boneSize=Size.length();
Ogre::String boneName=B->getName();

ax=Ogre::Vector3(0,1,0);

Ogre::Vector3 cylSize;
cylSize.x=Size.length()/6;
cylSize.y=Size.length()/2;
cylSize.z=0.0;

OgreBulletCollisions::CylinderCollisionShape * boneC=
new OgreBulletCollisions::CylinderCollisionShape(cylSize,ax);

comp->addChildShape(boneC,Position,q);

}
}


The position of the Bone is correct (from _getDerivedPosition) as I seen it with SphereCollisionShapes.
But what I'm not capable to is putting the cilinders arround the bones of the Mesh.
The orientation in the Quaternion q is not correct. Also, the position of the Cylinder/Capsule is centered on the middle, while the BoneEnvelope should be centered on one of his Bases.

Any idea on how to achieve this?

Thanks in advance.

dermont

07-04-2011 13:52:04

I think to "centre" on it's base you have to set it's CompoundCollisionShape position to something like the mid-point of the parent / child bone. Attached is simple example, 'c' key to create Character, HTH.

Padres

06-12-2011 10:24:30

Sorry for reopening this post, but has this been solved?

I have the same problem as the kulebril - the positions of the bones are calculated okay, but the orientation quaternion of the bone is not correct.

I calculate the world position of the bone with the following:
Ogre::Vector3 bonePos = m_node->_getDerivedPosition() + m_node->_getDerivedOrientation()*m_node->_getDerivedScale()*bone->_getDerivedPosition();

How can the bone orientation quaternion (in world space) be computed?

Thanks

dermont

06-12-2011 11:02:20

Sorry for reopening this post, but has this been solved?

I have the same problem as the kulebril - the positions of the bones are calculated okay, but the orientation quaternion of the bone is not correct.

I calculate the world position of the bone with the following:
Ogre::Vector3 bonePos = m_node->_getDerivedPosition() + m_node->_getDerivedOrientation()*m_node->_getDerivedScale()*bone->_getDerivedPosition();

How can the bone orientation quaternion (in world space) be computed?

Thanks


Don't think so, I removed the code since I had exceeded my quota on the forum, obviously it wasn't what the OP was wanting so it probably isn't much use to you (C to create character; R to view cylinders; 1/2/3/4 to move character).