# trouble rotating Quaternion camera

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

## Recommended Posts

hey im trying to implement a first person view Quaternion camera in my engine. So far i got it to properly rotate around either the x axis(looking up and down) OR the y axis(looking left and right) but when i rotate around both axis it does not rotate as intended. for adjusting the cameras rotation around the Y axis i did the following this is a piece of java code using my own Classes but it shuld be self explanatory where Y is the amount of degrees i wish to rotate around the Y axis and quat is the Quaternion representing my Cameras Orientation EularAngle e = new EularAngle(0,Y,0); Quaternion adjust = e.toQuaternion(); quat = multiply(quat,adjust); This works perfectly fine. changing the value of Y causes the camera to look left or right now my problem comes in when i want to rotate around both the X and Y axis. ive tried to following EularAngle e1 = new EularAngle(X,0,0); EularAngle e2 = new EularAngle(0,Y,0); Quaternion q1 = e1.toQuaternion(); Quaternion q2 = e2.toQuaternion(); Quaternion q3 = multiply(q1,q2); quat = multiply(quat,q3); ive also tried EularAngle e = new EularAngle(X,Y,0); Quaternion adjust = e.toQuaternion(); quat = multiply(quat,adjust); both of these gives me a pretty weird end results. Il appreciate any suggestions o and i dont know if this is important but my render loop implements the camera as follow: //first AxisAngle a = quat.toAxisAngle(); GL11.glRotatef(a.angle, a.x, a.y, a.z); GL11.glTranslatef(position.x,position.y,position.z); //then draw all models i should add that im very new to Quaternions since up til now my engine only used Eular Angles Thnx in Advance!

##### Share on other sites
I think a lot of people hit this very problem when they start using quaternions, I know I did :) The solution is that after each rotation, you need to use the newly rotated axis to build the next quaternion. Assuming you have a method to get a quaternion from axis/angle format, something like the following pseudocode should do what you expect:

yawQuat = QuaternionFromEulerAngles(0.0, yaw, 0.0)
convert yawQuat to matrix
pitchQuat = QuaternionFromAxisAngle("right" direction vector from matrix, pitch)
finalQuat = pitchQuat * yawQuat (or the other way around, depending on your convention)

##### Share on other sites
thnx for the reply i understand ur explanation cept for the following

convert yawQuat to matrix - do u mean a 3v3 matrix or that ur converting it to a axis angle?
and
"right" direction vector from matrix

sorry i prob dnt realy understand the term matrix with regards to 3d programming since up til now ive used nothing but Eular Angles

EDIT:

ok i found the neccesary formula to convert my quaternion to a matrix. now i just need to know what u meant with ""right" direction vector from matrix"?

thnx

[Edited by - EternityZA on January 8, 2009 2:12:15 PM]

##### Share on other sites
I'd probably read up on matrices as you'll find you need them more and more :) As a very quick and dirty explanation in the context of what I posted, your pitch rotation, which is X in your original post, acts around your object's X direction vector. You can get this vector by transforming the world or global X vector ([1, 0, 0]) by the matrix result from your yaw rotation. This will simplify into the first row or column (again depending on your matrix convention) of the matrix. I loosely termed this "right" in case that made it easier to understand, as looking at your post I expect that you treat the Y axis as "up" and Z as "forwards".

##### Share on other sites
Thnx a lot for your explanation!

i got it working :P

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
14
5. 5

• 9
• 13
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013662
×