Yes, you are doing it the right way, there are no one-line statement :-)
It is very common in 3D applications to create a quaternion from a set of Euler angles, and we do this simply by multiplying together the most basic rotations, since it is anyway pretty cheap to compute (unless you are doing a lot of them, and determined by profiling that this part was critical for performance). For instance, if you are using the convention Z-X-Z (as illustrated in the first picture here ), then you would write:
QQuaternion rotation =
QQuaternion::fromAxisAndAngle(QVector3D(0,0,1), alpha) *
QQuaternion::fromAxisAndAngle(QVector3D(1,0,0), beta) *
QQuaternion::fromAxisAndAngle(QVector3D(0,0,1), gamma);
where alpha
, beta
and gamma
are double
values representing the angles in degrees (be careful, not in radians).
Note: you can create the one-liner yourself by wrapping it in your own method:
static QQuaternion fromEuler(double alpha, double beta, double gamma);