1
votes

Using Qt Quick 3D QML and without having additional C++, how could I multiply two quaternions?

I have a fixed rotation value given in quaternion (Qt.quaternion(a,b,c)), to which I would like to add a variable part.

Documentation is very scarce about that (I only found quaternion and Transform) and apparently there is no "times()" property similar to the one from vector. On the C++ side, I can multiply and normalize quaternions (QQuaternion)

1

1 Answers

1
votes

I would recommend writing your own JavaScript function doing the multiplication. One example implementation (multiplyQuaternion()) can be seen in this answer to another question.

You can also take a look into implementation of inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2) in QQuaternion class for reference when writing your own JS function.

Another possibility might be to utilize some ready-made JS implementation (if found) by importing a JS file in question into your QML.

You could also write QObject-based C++ wrapper which utilizes QQuaternion class and then expose it to QML. But you would have to link with Qt Gui module and write quite a lot of boilerplate code because of that one function which probably doesn't make too much sense.