• Advertisement
Sign in to follow this  

Correct Way to Apply Rotations.

This topic is 3954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

*Updated* Dear All, I've currently got a sphere, which I'm trying to rotate with some GUI controls. I've got a dial to rotate around the Z axis, and I've got a little joystick which you can drag around to rotate in the X,Y axis. The first thing I did to try and do this was to just create a rotation matrix. However hte problem with that is when I rotate in Z axis, the other two axis rotate, so when the user moves the joystick right, the sphere no longe rotates right, but up. To fix this I decided I needed to rotate around an arbitrary axis. So using the joystick position I create an axis and rotate around that. That works exactly like I want it two with two problems. First, how do I add the Z rotation component to this? Secondly, whenever the joystick crosses the origin, the sphere spins around before starting to rotate in the correct way. Below is the code I'm using : Vector3 axisx; Quaternion final; double kX=mKnobX-mCompassX;//How far the tip of the joystick is from its origin double kY=mKnobY-mCompassY; double kZ=0; if(kX!=0&&kY!=0)//Prevent Division by Zero { axisx.x=-kY/sqrt(kX*kX+kY*kY+kZ*kZ); axisx.y=kX/sqrt(kX*kX+kY*kY+kZ*kZ); axisx.z=kZ/sqrt(kX*kX+kY*kY+kZ*kZ); final.SetAxisAndRotation(axisx,mCameraRotate); double xx = final.v.x * final.v.x; double xy = final.v.x * final.v.y; double xz = final.v.x * final.v.z; double xw = final.v.x * final.s; double yy = final.v.y * final.v.y; double yz = final.v.y * final.v.z; double yw = final.v.y * final.s; double zz = final.v.z * final.v.z; double zw = final.v.z * final.s; mInternalCamera[0] = 1 - 2 * ( yy + zz ); mInternalCamera[1] = 2 * ( xy - zw ); mInternalCamera[2] = 2 * ( xz + yw ); mInternalCamera[4] = 2 * ( xy + zw ); mInternalCamera[5] = 1 - 2 * ( xx + zz ); mInternalCamera[6] = 2 * ( yz - xw ); mInternalCamera[8] = 2 * ( xz - yw ); mInternalCamera[9] = 2 * ( yz + xw ); mInternalCamera[10] = 1 - 2 * ( xx + yy ); mInternalCamera[3] = mInternalCamera[7] = mInternalCamera[11] = mInternalCamera[12] = mInternalCamera[13] = mInternalCamera[14] = 0; mInternalCamera[15] = 1; } return mInternalCamera; Maybe I'm approching this task from the wrong angle? Jesse [Edited by - laeuchli on June 26, 2007 2:53:46 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement