Registered Member
|
How do I effectively go from a Matrix3f to a Quaternionf, given that my 3x3 is a guaranteed to be a rotation matrix, since it orthonormal?
Is not working for me, since i am getting a roll in that quat where there was none (since i constructed it). |
Moderator
|
This is the correct way to convert a 3x3 rotation matrix to a quaternion. Can you be more specific about the input matrix, the output you get and what you don't like in the result?
|
Registered Member
|
Here is what I am trying to do, Essentially building a lookat system for my graphics code. For one particular area i need the lookat parameters in euler angles. A lookat with an up vector of [0 1 0], should produce an euler angle with yaw and pitch but no roll. I am getting roll in there for some reason, so the results are off (not point at the right location).
I should also mention that I am doing this for my camera which point down neg z at identity, that is why i have that negZ bool that is set to true. I even tried this with just using the LookAtQuatf, and applying the resulting quaternion to my camera is still wrong (just off, sometimes by alot). The euler angle order i use is Yaw then Pitch then Roll, applied in that order right side multiplication applying the next transform locally. So Model is Yawed (rot about y) first then pitched (rot about x) from that yawed orientation, then rolled (rot along z) from that yawed and pitched orientation. My coord system is right handed BTW, _Z forward, X right, Y up. My code so far looks like so (not sure what I am doing wrong):
|
Moderator
|
1 - You have to normalize the xaxis vector
2 - If your system is right handed, then I guess Z is rather pointing to the backward direction, isn-it? 3 - Any reason for not using Eigen's Euler conversion routine? In your case:
4 - You can directly fill you look-at matrix with comma initializer:
|
Registered Member
|
Hmm, so I changed my LookAts to this:
And I am trying to use LookAtQuat, for testing before I use LookAtEuler. My camera class takes a quaternion as its native orientation specification. The reason why I am trying to have neg z point at the target, is that my camera at identity points down neg z. Its a wrapper on an OpenGL camera thus the neg z pointing into the screen. So with this code, I am still getting a roll in my camera, and it is still not pointing at the target. |
Moderator
|
BTW, how do check whether you all roll or not? The matrix computed by LookAt is the matrix from global to camera space so you have to extract the Yaw-Pitch-Roll components from its inverse, or extract these quantities in the other order (Roll-Pitch-Yaw or 2,0,1 using .eulerAngles(...)).
|
Registered Member
|
Just as an experiment I let the negZ bool in those functions to be false, so z-axis should be pointing at the target. When calling LookAtEuler, i am still getting a roll in z, not sure why.
|
Registered Member
|
To extract the euler angles from the quaternion I use the QuatfToEuler function i first posted:
I have used this before, and it seemed to work fine, is there a better way? |
Moderator
|
but you extract them on the global-to-camera transformation right? if that's right, then you either have to call QuatfToEuler on the inverse transformation or adapt your QuatfToEuler code to extract Roll * Pitch * Yaw instead of Yaw * Pitch * Roll.
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]