The first step is to allow bones to move independently from the parent in the global reference frame, so I can attach each of them to a PhysX-actor.
For applying transformations from PhysX-actors to Irrlicht-nodes I call this on every frame:
- cpp Code: Select all
void applyPose (const PxRigidActor *fromPx, ISceneNode *toIrr)
{
PxTransform posePx = fromPx->getGlobalPose();
matrix4 matIrr = quaternion(posePx.q.x,posePx.q.y,posePx.q.z,posePx.q.w).makeInverse().getMatrix();
matIrr.setTranslation(vector3df(posePx.p.x,posePx.p.y,posePx.p.z));
if (toIrr->getParent() != gScene->getRootSceneNode())// this would work with rootSceneNode as parent as well
{
matrix4 pTrans;
toIrr->getParent()->getAbsoluteTransformation().getInverse(pTrans);
matIrr = pTrans*matIrr;
}
toIrr->setPosition(matIrr.getTranslation());
vector3df rot = matIrr.getRotationDegrees();
toIrr->setRotation(rot);
toIrr->updateAbsolutePosition();
}
... and it seems to work fine with nodes I manually "parented" - they move with their attached actor like they don't have a parent-node at all.
When I try the same with BoneSceneNodes I get weird behaviour and Axes don't seem to match, even though the whole .x-mesh orientation is as it should be. I set JointMode to EJUOR_CONTROL, but bones don't really move independently. I can't help thinking the problem is somehow related to the armature (and maybe the way I aligned it before export?...), but I don't know what to do... Any help?
