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:
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.
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.