GLKit – Transforming A Vector With A Quaternion

OpenGL 3d axes

Since I haven’t seen this on Stackoverflow, the following is a method to transform a vector (GLKVector3) based on an attitude quaternion (GLKQuaternion).

First, assume that you have a GLKVector3 as input, call it inputVector3. inputVector3 could be yaw, pitch, and roll influences from an aircraft’s control surfaces or thruster output on a spacecraft. You know your vehicle’s attitude and have calculated that attitude into a quaternion. So, the goal is to have the inputVector3 transformed into an ivar, say GLKVector3 deltaV, that is in terms of the vehicle’s attitude.


- (GLKVector3)transformVector3:(GLKVector3)inputVector3 withAttitudeQuaternion:(GLKQuaternion)attitudeQuaternion
{
GLKVector3 deltaV = inputVector3;

//Always ensure that your attitude quaternion has been normalized
attitudeQuaternion = GLKQuaternionNormalize(attitudeQuaternion);

//Convert the normalized attitude quaternion into a GLKMatrix3.
GLKMatrix3 tempQMatrix3 = GLKMatrix3MakeWithQuaternion(attitudeQuaternion);

//Since v' = v T, where T is a transform matrix, multiply
//the attitudeQuaternion GLKMatrix3 with the necessary GLKVector3.
deltaV = GLKMatrix3MultiplyVector3(tempQM3, deltaV);

return deltaV;
}

Screenshots-A Legal Way To Get Screenshots

Note: Please remember that this post is over 5-years old, is not therefore current, so code at your own risk.

Screenshot 2011 03 25 04 23 15Well, Screenshots is finally done. So, what took so long since the last post about Screenshots on March 7th?

The worst thing about having perfectionist attributes is that sometimes they are detriments. Take, for example, my initial Screenshots demo app. Yes, it worked in so much as it did demonstrate that by using Apple’s Q&A 1702, 1703, 1704, and 1714 you could get they type of screen shot, or screen image, that you could by using UIGetScreenImage(). But it was…how best to put it, so ugly that not even its coder (I) could love it. So I rewrote it. All of it. And then I added features. Yeah…like I said, a detriment.

Ok…so what took so long?

 

More…