Wednesday, March 23, 2011

A message for Yombo (but also for all who can help me)

I write here because i've no way to put all into twitter :) and because i haven't your email address.

I'll talk about my issue with quaternions.

So, i've changed a lot the code, hoping that it solves my problem but nothing changes.

Now the "lookAt" function doesn't receive a vector, but two angles: pitch and yaw. First i compute the pitch rotation (Quaternion q), then the yaw rotation (Quaternion r), and last multiply the two quaternions and rotate the camera using the result.

void MyCamera::lookAt(Ogre::Real pitch, Ogre::Real yaw) {

Quaternion q(Degree(pitch), Vector3::NEGATIVE_UNIT_X);
Quaternion r(Degree(yaw), Vector3::NEGATIVE_UNIT_Y);
q=q*r;
mCamera->rotate(q);
}



This is what happens.



in the upper-left panel now i display the "right" vector of the camera. Ok?
  1. First i rotate around Y axis (yaw), keeping pitch==0 all the time: you can see that right vector has his y coords always = 0. It's correct: the y component of right vector defines the "roll" rotation. If it's always 0, camera does not rolls.
  2. Next i rotate around X (pitch), keeping yaw==0 al the time. Now the right vector is = (1,0,0), always. In the video you can see not properly (1,0,0) because of the Ogre::Real resolution, but it's something like (1,0.00000001,0.00000001). And it's correct; when i pitch changes the look at, changes the up vector, but the right vector remains normal to plane YZ. Again: the y component of right vector is always = 0, so no "roll" of the camera. Perfect.
  3. Finally i unlock both rotation and start to combine it: the camera starts to roll, and you can see tha the y component of right vector grows... if it's > 0 camera rolls left, if it's <>

My questions now are: WHY!?!? What's wrong? And what is the correct way?

Thank you for the patience. I'm a noob about rotation.

2 comments:

Yombo said...

It's perfectly logical. You are doing exactly like before, with a minimal change.
The point is that you are not storing the quaternion, and you give two absolute angles. The solution is to store the quat as the rotation state of the ship, and use _incremental_ angles to do the rotation. That way you will control the roll. I'm at qork at the moment so I'll try to give you a longer explanation later.

Yombo said...

I'm sorry PdG I didn't see the video before and now I see what happens. Please forget my previous comment.
The roll of the camera is perfectly normal. It happens because of each time the camera is rotated, there is a roll relative to the previous coordinate system. You can see this effect also in David Braven's Frontier when you select the 'easy' flight model.