Rotation, using Quaternions

I have the problem of rotating my object correctly. What I need is to create a line ( along x-axis) grabbed to the point so that when you move it, horizontally, vertically or a combination of those two movements, the end of the line circles part of the sphere plane and the beginning of the line stays at rest.

I am using the bullet physics engine, which provide objects like quaternions and functions to set their values eg using Euler angles or just creating 3 quaternions, filling their fields (W,X,Y,Z) and finally multiplying them, getting the final quaternion.

I've tried to use Euler angles and when I used EulerYXZ setting (only Yaw and Roll) it works well. But when I add pitch (which should be rolling in the direction of the line's axis) object's do rotate, but it doesn't circle the sphere any more. Probably my additional rotation incorporated some dislocation and I don't know how to figure it out.

Firstly, I created Quaternions which represent yaw and roll like this :

btQuaternion qx,qy,qz, 
 qx.setW(1);
 qx.setX(0);
 qx.setY(0);
 qx.setZ(0);

 qy.setW( btCos( -x*DEGREE/2.0f )); //x is the example angle value, * DEGREE provides radians
 qy.setX(0);
 qy.setY(btSin( -x*DEGREE/2.0f ));
 qy.setZ(0);

 qz.setW(btCos(( y+inclined )*DEGREE/2.0f ));
 qz.setX(0);
 qz.setY(0);
 qz.setZ( btSin( (y+inclined)*DEGREE/2.0f ));

Now I can get final quaternion by multiplying them:

TransformStick.setRotation(qx*qy*qz);

How should I add rolling along the line's axis in order not to change the line's end position ?

链接地址: http://www.djcxy.com/p/81782.html

上一篇: 旋转矩阵到四元数等价

下一篇: 旋转,使用四元数