I have a problem understanding quaternions rotation in OpenGL.
So far I have implemented all function and operators related to quaternions.They are definitely working right!.
However I can't find where I'm making the mistake within rotation function.

Let's say I have a a cube in 3d space at (xyz)(1, 5, 2) if I am not wrong the position in 4D is p = 0 + i + 5j + 2k, and the orientation and rotation (0, 0, 0, 0) in 4D space is q = 1 + 0i + 0j + 0k

a quaternion is just an orientation. when applied to a point, and or a vector then it has meaning. like saying 37 degrees about X-axis where did your start from. then your question on orbit. define your orbit plane (or are we talking about parametric equation orbits?) I might venture a ques that your using quaternions to learn about them, and because they "sound cool".
–
gardian06May 5 '12 at 18:19

If you want to orbit around a given point, just subtract that point from your source point, perform the rotation usings quaternion arithmetics, and add the point back at the end. Using your values above:

Lets say I have a a cube in a point of 3d space (x=1,y=5,z=2) if I am not wrong the position in 4D is p=0+i+5j+2k orientation and rotation (0,0,0,0) in 4D q=1+0i+0j+0k now I want to rotate it by 30 degree along y axis.

Nothing in this statement after the words "if I am not wrong" made any kind of sense.

You do not use quaternions to encode positions (unless you're using dual-quaternions and you're not). A quaternion, for the purposes of graphics, is nothing more than a fancy way to encode a rotation matrix. It is just an encoding of an orientation in space.

So there is no quaternion position.

Since you're using fixed-function rendering, if you want to apply a quaternion to the matrix stack, then you do it by generating a matrix from it and applying it to the stack with glMultMatrix. If you want to rotate an object's position based on a quaternion, then you glMultMatrix the quaternion onto the stack, then glTranslate the position onto the stack.

And you should never "change quaternions to Axis angle". There is never any reason to do so.

I have to disagree with you here. Unit quaternions are used to encode an orientation in space. Quaternions as they are are just 4D objects, and it is perfectly valid to use the w=0 hyperplane (which is a 3D subset of the 4D set of quaternions) to encode a position.
–
sam hocevarMay 5 '12 at 18:56

@Sam: Mathematically valid, yes. But of zero utility in this situation. Do you honestly think that the OP understands the mathematical validity of the concept?
–
Nicol BolasMay 5 '12 at 19:04

True, OP seems to be confused about what quaternions are useful for. But other people may read that and get the wrong idea. As for “changing quaternions to axis angle”, I wouldn't really recommend against it since it's a quick way to generate a matrix on the stack with glRotate. But yeah, again, probably not the best advice to OP.
–
sam hocevarMay 5 '12 at 19:11