I would like to know how can i do the weighted sum of quaternion? I cannot do it by slerp...
w1, w2, w3, ..., wn
q1, q2, q3,..., qn
Code: Select all
q = Quaternion::Slerp(w1, q1, q2);
q = q * Quaternion::Slerp(w2, q2, q3);
... ???
Code: Select all
q = Quaternion::Slerp(w1, q1, q2);
q = q * Quaternion::Slerp(w2, q2, q3);
... ???
Code: Select all
// in
quat_with_weight inputs[N];
// result net torque as a rotation vector
vec3 accum(0,0,0);
foreach(q in inputs)
{
// add the torque contributation of this rotation
accum += q.getAngle() * q.weight * q.getUnitAxis();
}
// convert angle/axis back to quaternion
quat result(accum.magnitude(), accum.asUnitVector());
Code: Select all
Ogre::Vector3 vAccum = Ogre::Vector3(0,0,0);
Ogre::Quaternion qTemp;
Ogre::Radian fAngle;
Ogre::Vector3 vAxis;
Ogre::Real fBaseW = 1.0 / m_vQuats.size();
for(std::list<Ogre::Quaternion>::iterator i = m_vQuats.begin(); i != m_vQuats.end(); ++i)
{
qTemp = *i;
qTemp.ToAngleAxis(fAngle,vAxis);
//vAxis.normalise();
vAccum += fAngle.valueRadians() * vAxis * fBaseW;
}
Ogre::Quaternion qFinal = Ogre::Quaternion((Ogre::Radian)vAccum.length(), vAccum.normalisedCopy());