Code: Select all
quaternion rotQuat;
vector3df fromVect = emptyZ->getAbsolutePosition();
rotQuat.rotationFromTo(fromVect, trackTargetPos);
vector3df qte;
rotQuat.toEuler(qte);
vector3df qta;
myQuat.toEuler(qta);
vector3df eulerToTarget = vector3df(radToDeg(qte.X), radToDeg(qte.Y), radToDeg(qte.Z));
vector3df eulerFrom = vector3df(radToDeg(qta.X), radToDeg(qta.Y), radToDeg(qta.Z));
quaternion resultQuat;
resultQuat.slerp (eulerFrom, eulerToTarget, 1);
vector3df qtr;
resultQuat.toEuler(qtr);
vector3df resultVect = vector3df(radToDeg(qtr.X), radToDeg(qtr.Y), radToDeg(qtr.Z));
this->setRotation(resultVect);
myQuat is a quaternionen from the Parent of emptyZ which is the one to Rotate, i use this code to get it
Code: Select all
irr::core::matrix4 myMat = this->getAbsoluteTransformation();
myQuat = quaternion(myMat);
trackTargetPos is the Absolute Position from the TargetNode
the center is of the rotation is allways 0,0,0 so both absolute positions are also direction vectors.
_____________
if i execute this code ONCE the node that is to rotate does rotate ... but to somwhere else as in the direction of the target
if i change the code to be called by a render loop so that only slerp is executed and the rotation calculation to degree is done and also changig the 1 in slerp interpolation argument to a upward counting value from 0 to 1 it rotates slowly to the same direction as like when i execute it ONCE.
if i recalculate myQuat and trackTargetPos to involve translation of the target and current rotation ot the node that rotates i get a wild arround flipping node until the 1 in slerp is reached...
can someone please enlighten my darkness