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!. HovererHowever I can't find where i makeI'm making the mistake withingwithin rotation function.
LetsLet's say I have a a cube in 3d space at (xyz)(x=11,y=5 5,z=2 2) if I am not wrong the position in 4D is p=0+i+5j+2kp = 0 + i + 5j + 2k, and the orientation and rotation (0,0,0,0)(0, 0, 0, 0) in 4D space is q=1+0i+0j+0kq = 1 + 0i + 0j + 0k
Now I want to rotate it by 30 degrees along y-axis.
q = cos(a / 2) + (i xix + j yjy + k zkz)sin(a/2) So 30 degrees along y-axis is q=0.96+0.25j now:
Pout=q*Pin*conPout = q * Pin * con(q) Q=q*Pin=Q = q * Pin = (0.96+096 + 0.25j) * (0+1i+5j+2k0 + 1i + 5j + 2k) = -1.25+1.46+4.8+1.67 shall25 I+ normalizing1.46 it+ now4.8 or+ not? 1.67 Shall I normalize it now or not?
conj(q)=0 = 0.96 - 0.25j Pout=Q*conPout = Q * con(q)=0+1 = 0 + 1.81+4,92+181 + 4.3292 + 1.Normalized32 Normalized:
q q=0+0= 0 + 0.33i+033i + 0.91j+091j + 0.22k This is definitely the wrong answer according to this site
Rotating the object along the Y-axis by 30 degrees from a point (0,0,0) gives the correct result just by computing q.if If I use the above algorithm and multiply it by Pin I get (0,0,0,0)
Can you show me how to do it right step by step?
alsoAlso how do I to orbit one point along another. Lets say I have the given point above and I want it to orbit around the point (x=22,y=10 10,z= -2) using quaternions.
AlsoAnd when I manage to get the correct quaternion, how do I use it in the proper way along with opeGLopenGL glRotetefglRotatef.?
SOSo far my program runs like thatthis:
- quaternion=xQuaternion = x,y y,z z of object
- Compute RotatioRotation by X degrees along axes.
- Quaternion to Axis Angle
- glRotetef
glRotatef(by result of point 3) - quaternion=Quaternion = result of point 2
- goGo to point 2
- goGo to step 1
Do I always have to change quaternions to Axis-angles, or maybe there is there another way which allowsallow me to represent the rotation without conversion?