Quaternion input

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
MisterRose
Posts: 18
Joined: Thu Jun 16, 2011 2:46 pm

Quaternion input

Post by MisterRose »

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,
You are unique - just like everyone else.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Quaternion input

Post by serengeor »

Working on game: Marrbles (Currently stopped).
MisterRose
Posts: 18
Joined: Thu Jun 16, 2011 2:46 pm

Re: Quaternion input

Post by MisterRose »

I was able to get things mostly working. It all boiled down to a few lines of code...

Code: Select all

qRot = device->GetQuaternion();
qRot.toEuler(rot);
vector3df rot*=core::RADTODEG;
node->setRotation(rot);
 
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?

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;
Is rotation the correct thing to do, or do I need to do something else?
You are unique - just like everyone else.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Quaternion input

Post by mongoose7 »

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.
MisterRose
Posts: 18
Joined: Thu Jun 16, 2011 2:46 pm

Re: Quaternion input

Post by MisterRose »

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.
You are unique - just like everyone else.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Quaternion input

Post by mongoose7 »

Try just swapping Y and -Z.
MisterRose
Posts: 18
Joined: Thu Jun 16, 2011 2:46 pm

Re: Quaternion input

Post by MisterRose »

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.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Quaternion input

Post by mongoose7 »

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?
Post Reply