Do I use bone->_getDerivedPosition for the spot where a bullet should fire from? Ive tried it and it is not correct from the bone placement in blender. It must be either a blender problem, an exporter problem, or I'm not using ogre correctly?
here is what I'm doing to try to get the position to fire from:
Take in mind that Ogre bones are at the head of the bone, while Blender bones have a head and a tail. If you need the position of the tail, then create another connected bone, so that the head of this new bone will be where the tail of the previous bone is.
If the bone is part of a larger skeletal heirarchy, you need to traverse upwards ... because yes as dark_sylinc is explaining the bone position is in local space
Ogre::Vector3 GetBoneWorldPosition(Ogre::Entity* ent, const Ogre::String &boneName)
{
Ogre::Bone* bone = ent->getSkeleton()->getBone(boneName);
Ogre::Vector3 world_position = bone->_getDerivedPosition();
//multiply with the parent derived transformation
Ogre::Node *pParentNode = ent->getParentNode();
Ogre::SceneNode *pSceneNode = ent->getParentSceneNode();
while (pParentNode != NULL)
{
//process the current i_Node
if (pParentNode != pSceneNode)
{
//this is a tag point (a connection point between 2 entities). which means it has a parent i_Node to be processed
world_position = pParentNode->_getFullTransform() * world_position;
pParentNode = pParentNode->getParent();
}
else
{
//this is the scene i_Node meaning this is the last i_Node to process
world_position = pParentNode->_getFullTransform() * world_position;
break;
}
}
return world_position;
}
It does all the hierarchy transform stuff internally.
There's also sn->convertLocalToWorldOrientation for orientation (so you can make the bullet move in the direction of the bone, in case it's a turret), and world to local versions of both functions.
This solution works for almost all conditions, thanks!
The other function convertLocalToWorldPosition(mBone->_getDerivedPosition()) only works when it has no large skeletal heirachy according to my test.
c6burns wrote:If the bone is part of a larger skeletal heirarchy, you need to traverse upwards ... because yes as dark_sylinc is explaining the bone position is in local space
Ogre::Vector3 GetBoneWorldPosition(Ogre::Entity* ent, const Ogre::String &boneName)
{
Ogre::Bone* bone = ent->getSkeleton()->getBone(boneName);
Ogre::Vector3 world_position = bone->_getDerivedPosition();
//multiply with the parent derived transformation
Ogre::Node *pParentNode = ent->getParentNode();
Ogre::SceneNode *pSceneNode = ent->getParentSceneNode();
while (pParentNode != NULL)
{
//process the current i_Node
if (pParentNode != pSceneNode)
{
//this is a tag point (a connection point between 2 entities). which means it has a parent i_Node to be processed
world_position = pParentNode->_getFullTransform() * world_position;
pParentNode = pParentNode->getParent();
}
else
{
//this is the scene i_Node meaning this is the last i_Node to process
world_position = pParentNode->_getFullTransform() * world_position;
break;
}
}
return world_position;
}