I have an electronic device which can stream it's orientation in quaternion format. I'd like to take that quaternion and apply it to a mesh that I have loaded. This way, as I move the physical device, the mesh can mimic the move.
What functions should I be looking at? Does anyone know of any example code that will illustrate this?
Thank you,
Quaternion input
-
- Posts: 18
- Joined: Thu Jun 16, 2011 2:46 pm
Quaternion input
You are unique - just like everyone else.
Re: Quaternion input
Working on game: Marrbles (Currently stopped).
-
- Posts: 18
- Joined: Thu Jun 16, 2011 2:46 pm
Re: Quaternion input
I was able to get things mostly working. It all boiled down to a few lines of code...
The last thing I need to do (I think) is to rotate the mesh 90 degrees around the Z axis. The problem I am having is that when I hold the device and pitch up, the mesh rotates and when I rotate the model, the mesh pitches. I assume that I should do a rotation between the line where I get the quaternion and before it is converted to Euler rotations.
I tried the following, but when I yaw the device, very little yaw is seen on screen, and when I pitch or roll the device, the model does a combination pitch and rotate. Any ideas?
Is rotation the correct thing to do, or do I need to do something else?
Code: Select all
qRot = device->GetQuaternion();
qRot.toEuler(rot);
vector3df rot*=core::RADTODEG;
node->setRotation(rot);
I tried the following, but when I yaw the device, very little yaw is seen on screen, and when I pitch or roll the device, the model does a combination pitch and rotate. Any ideas?
Code: Select all
qRot = device->GetQuaternion();
qPrime = qRot;
qPrime.makeInverse();
qRot = (qRot* quaternion(0,0,1,45*DEGTORAD).normalize()) * qPrime;
qRot.normalize();
qRot.toEuler(rot);
rot*=core::RADTODEG;
retRotation = rot;
You are unique - just like everyone else.
Re: Quaternion input
You're getting the quaternion from "an electronic device." Is the coordinate system the same? Irrlicht is a left-handed system with Y up. Blender, I believe, is right-handed with Z up. I think your device probably has Z up.
-
- Posts: 18
- Joined: Thu Jun 16, 2011 2:46 pm
Re: Quaternion input
It is right handed with Z down. Do I need to invert it to switch the handedness, and then do a rotate?
The simple solution is to just realign the device so that roll/pitch are correct, but I'd think that I can also do this in software. I just have to figure out how.
The simple solution is to just realign the device so that roll/pitch are correct, but I'd think that I can also do this in software. I just have to figure out how.
You are unique - just like everyone else.
Re: Quaternion input
Try just swapping Y and -Z.
-
- Posts: 18
- Joined: Thu Jun 16, 2011 2:46 pm
Re: Quaternion input
I tried that, but it produced an odd rotation when I pitched or rolled. I think that has to do with the order of operations in the Euler rotation.
You are unique - just like everyone else.
Re: Quaternion input
BUT YOU SAID you were receiving *quaternions* from your "electronic device." Are you trying to tell me that you are first converting them to Euler angles?