I am trying to slerp between 2 quaternions using Eigen(thought would be the easiest).
I found two different examples
One,
for(int i = 0; i < list.size(); i++)
{
Matrix3f m;
Quaternion<float,0> q1 = m.toRotationMatrix();
Quaternion<float,0> q3(q1.slerp(1,q2));
m_node->Rotation(q3.toRotationMatrix());
}
Second,
Vec3 slerp(const Vec3& a, const Vec3& b, const Real& t)
{
Quaternionf qa;
Quaternionf qb;
qa = Quaternionf::Identity();
qb.setFromTwoVectors(a,b);
return (qa.slerp(t,qb)) * a;
}
I cant really say which one is correct. There is not many documentation about this. Can anyone tell me if I should use a different library? or how can I slerp using eigen.
Doing a SLERP between two quaternions is just a matter of calling the slerp method:
Quaterniond qa, qb, qres;
// initialize qa, qb;
qres = qa.slerp(t, qb);
where t is your interpolation parameter.
Use the second variant.
Both code snippets implement a SLERP, however the first one does something with elements in a list, which your snippet doesn't show. Also the second variant is the computationally more efficient one, as it doesn't take a detour over a rotation matrix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With