RandomAxess 132 Report post Posted May 24, 2004 Just a couple questions on Quaternions for rotations; Just to note, i''m assuming OpenGL stuff, since that''s what i learnt Let''s say that i''m starting with a camera at the origin, with the vUp vector as (0,1,0). If i want to rotate, say, 10 degrees (converted into radians) to the right, i would take the current axis and rotation i''m at (which i''m assuming would be zero) and then form the quaternion for the resulting rotation, and multiply them together? THis is a very simple example, but i guess i can generalize it, so lets say i''m arbitrarily positioned in space, and want to rotate to the right, i just take the current quaternion and multiply that by the resultant quaternion, and that''s what i''d be using to input the glRotate values? Thanks a lot in advance! 0 Share this post Link to post Share on other sites

yugami 122 Report post Posted May 24, 2004 heres a synopsis of how i do quaternian rotation. bear with me as it''s been a while, my quaterion is setup w/ s and a vertex as internals.find the sine of your rotation angle. Mult y of vUp by that, set that to quaternion1''s vectorset the s member of quaternion1 to the cos of the angle.set quaternion2''s s to the cos of the angle also.set quaternion2''s vector vUp * -(sine of angle)setup quaternion3 to s =1 and the vertex = the vertex to rotatequaternion4 = quaternion1 * quaternion3 * quaternion2the rotated vertex is now the vertex segment of quaternion4, do with it what you will.you can internalize all this into your quaternion setup, this is just a rundown of how i have it setup 0 Share this post Link to post Share on other sites

jyk 2095 Report post Posted May 25, 2004 "Let''s say that i''m starting with a camera at the origin, with the vUp vector as (0,1,0). If i want to rotate, say, 10 degrees (converted into radians) to the right, i would take the current axis and rotation i''m at (which i''m assuming would be zero) and then form the quaternion for the resulting rotation, and multiply them together?"This is more or less correct.Somewhere in your quaternion class you''ll want a function that takes an axis/angle representation and converts it to quaternion form. The conversion goes like this:q.x = sin(angle / 2)axis.xq.y = sin(angle / 2)axis.yq.z = sin(angle / 2)axis.zq.w = cos(angle / 2)You''ll start with a unit quaternion that represents your initial orientation. To rotate 10 degrees to the right, you would create a new quaternion with axis 0, 1, 0 and angle 10 degrees, and multiply it by your original quaternion. The resulting quaternion is your new orientation.Keep in mind that to rotate left or right, you have to rotate around the object''s up vector. As long as you only yaw, this will remain 0, 1, 0. But once you pitch or roll your local up vector will change.There are functions to convert a quaternion to a matrix, and your up vector (as well as your side and forward vectors) can be extracted from this matrix. 0 Share this post Link to post Share on other sites