Sign in to follow this  
taigonwon

Rotation about an arbitrary axis

Recommended Posts

taigonwon    122
Hello everyone, I am a beginner to graphics programming using opengl, so my question probably sounds very simple. I real app. if someone can help me on this. I never took any linear algebra so, all this matrix stuffs are getting me VERY confused. Basicly I am writing a basic fight simulator, and I am trying to get row, yaw, and pitch to work. I want my camera to rotate about its own local axis, not world axis. For example, if my camera/plane first does a 10 degree row, the current transformation matrix will become something like this, +0.984808 -0.173648 +0.000000 +0.000000 +0.173648 +0.984808 +0.000000 +0.000000 +0.000000 +0.000000 +1.000000 +0.000000 +0.000000 +0.000000 +0.000000 +1.000000 Now if I want to do a pitch, I need rotate around the [+0.984808 -0.173648 +0.000000] vector not [1, 0, 0]. So the current transformation matrix becomes, +0.984808 -0.173648 +0.000000 +0.000000 (remains the same) +up_vec_x +up_vec_y +up_vec_z +0.000000 +fwd_vec_x +fwd_vec_y +fwd_vec_z +0.000000 +0.000000 +0.000000 +0.000000 +1.000000 How do I compute the unknown values? I really hope what I am thinking is the correct way to do this. Also, I know I am asking alot here, but an example code will really help me to understand faster. Thank you very much.

Share this post


Link to post
Share on other sites
kSquared    1356
You'll want to look here to do it the transformation-matrix way.

If you feel comfortable with it, a more efficient way to do it is to use quaternions, the four-dimensional generalizations of complex numbers.

Given angle θ in radians and unit vector u = ai + bj + ck, define:

q0 = cos(θ/2)
q1 = a*sin(θ/2)
q2 = b*sin(θ/2)
q3 = c*sin(θ/2)

Then the rotation matrix to apply to u is:

row 1:
col 0 --> (q0² + q1² - q2² - q3²),
col 1 --> 2(q1q2 - q0q3),
col 2 --> 2(q1q3 + q0q2)

row 2:
col 0 --> 2(q2q1 + q0q3),
col 1 --> (q0² - q1² + q2² - q3²),
col 2 --> 2(q2q3 - q0q1)

row 3:
col 0: --> 2(q3q1 - q0q2),
col 1: --> 2(q3q2 + q0q1)
col 2: --> (q0² - q1² - q2² + q3²)


You can read more about an explanation of the quaternion method here, and more on quaternions in general here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this