# Myo quaternion to 3D object rotation

Hi all,
I’m quite lost on rotating a simple cube by using Myo quaternion. I started by placing the ofRotation using w,x,y,z then x,y,z,w but after trying many options I really don’t get it. Can someone help me on this?
Thanks
David

I do not know what Myo is, but recents versions of openFrameworks uses glm. glm has quaternions too.
This is a good tutorial about how to use glm::quat to rotate things.
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#quaternions

If you simply want to rotate a cube on its x, y or z axis I suggest to have a look at the methods tiltDeg/tiltRad (depending if you want to rotate in degree or radians) for rotation on x axis, panDeg/panRad for rotation on y axis and
rollDeg/rollRad for rotation on z axis. I would not suggest to use quaternions if you simply have to rotate an object on its axis, the ofNode(from which the ofBoxPrimitive inherits from) already gives you the things that you need to do basic operations.

you can’t directly translate the ofRotate parameters to the x,y,z of a quaternion. quaternion classes have a way of creating them from an axis and an angle, in glm for example:

``````auto q = glm::angleAxis(angle, axis);
``````

returns a quaternion with the rotation for that angle around that axis, which is the equivalent to

``````ofRotate(angle, axis.x, axis.y, axis.z);
``````

or with ofQuaternion:

``````auto q = ofQuaternion(angle, axis);
``````

Hi Arturo,
And in the case of Myo device, when the quaternion is already given, how to place it on ofRotate(angle, x,y,z)?

i wouldn’t try to use ofRotate if you are given a rotation as a quaternion, use ofNode for example instead, set the orientation on it using a quaternion and then use it’s transformGL method

hi Arturo,
Where I can find an example of ofNode, I’m a little confused, I checked ofNode and it is a brunch of openframeworks. https://github.com/ofnode/of but Visual Studio is not supported. I am on windows 10 with VS2015.

Ah ok! I just found the example in 3D folder
Best yeah this ofNode: http://openframeworks.cc/documentation/3d/ofNode/

Nice example!
Maybe my question is predictable When I rotate the myo device the cube keeps rotating, but the quat from the myo is more like the rotation from an imaginary origin to the new position.
I’m using geometry.rotate(mQuat.w(), mQuat.x(), mQuat.y(), mQuat.z());
thanks for te help!

rotate keeps adding to the previous rotation in the node, you need to use setOrientation

ok got it! But setOrientation only support euler angles, in later of-editions it supports quat? I’m on 0.9.8

mmh, no in 0.9.8 it has 2 versions one for quaternions and one for euler angles:

http://openframeworks.cc/documentation/3d/ofNode/#show_setOrientation

totally my mistake! Awesome thanks a lot for the help! Now I need to find the correct camera position Hi,
A new question related to ofNode. Now I need to reset the center position, myo takes any imaginary position as a center. What would be the method for ofNode to add a rotation only once? and then keep rotating from there.
Do I need to add a center rotation to the the quaternion I’m sending? or it is possible to just send how much it has to add, like move but rotating?

you can parent 2 nodes, rotate the first by that first rotation and then update the second every frame

ooook! very nice solution