• Advertisement
Sign in to follow this  

Reversing a combined local/world rotation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys

I have a bit of a challenge here. It is best illustrated in the below screenshots:

In this scene, the camera is linked in hierarchy to the cone. The cone has 0 rotation on it. The camera is rotated to the left (yaw motion) by 15 degrees (see the Z value in the bottom right corner).
pERCxNH.png

I then rotate the cone upwards (pitch motion on the X axis) by 30 degrees using the World transform. But then I switch from the World transform to the local and rotate the cone around the Y axis (roll motion) by -25 deg (ie to the left). The camera is linked to the cone and follows it through these motions. You can see the rotation values in the bottom right corner.
OGVPnY9.png

The above illustrates a problem I am trying to solve using reverse engineered data from a flight simulator. I have the camera world rotation angles, and the aircraft (represented by the cone) world rotation angles in pitch and heading(yaw). My end goal is to calculate the camera rotation angle relative to the local aircraft rotation angles. But I am getting thrown for a loop by the switch to local in roll axis. Anyone have any suggestions?

Share this post


Link to post
Share on other sites
Advertisement

I don't understand well the problem because you say the camera is linked to the cone so this hierarchy to be clear :

Cone
  -->Camera

So, if the cone rotate or move, the camera follows the cone, the transform of the camera is only an offset from the cone transform.

Here the formulas :

LocalToWorld = local * parentWorld
WorldToLocal = world * inverse(parentWorld)
Edited by Alundra

Share this post


Link to post
Share on other sites
Yes the camera follows the cone and can be offset from it.

I'm not sure I follow exactly though. The cone has its own local transformation which affects the world transformation as well as the camera. Basically, if I roll the cone by -25 deg, set the pitch of the cone to 0, and then rotate the camera heading(yaw) by -90 deg, the camera transform will show a heading of -90 deg, a bank angle of 0, and a pitch angle of -25 deg. If I rotate the camera heading back to 0, pitch will be the same as the cone (0) and roll will be the same as the cone (-25). I need to calculate the local angles of the camera relative to the cone so that if I rotate the camera heading by -90 deg, no matter what pitch/roll values I will get the a heading of -90 deg, pitch 0, bank 0.

Share this post


Link to post
Share on other sites

If the Cone is the root, the local transformation is the same as the world transformation.

To compute one transformation relative to another you have to use the formula : worldTransformation * inverse(OtherWorldTransformation)

This formula will convert the world transformation to a relative from the other world transformation.

Share this post


Link to post
Share on other sites

I'm at work, so I can't see the pictures, but if I understand what you are trying to do........

 

Keep track of two separate rotations (be sure to use quaternions). One for the camera and the other for the aircraft. The camera one is an "offset" of the aircraft. I would do this in two steps:

-Calculate the camera's position and rotation:

      -multiply the two quaternions and convert it to a matrix

      -transform your camera's position by that matrix

      -add the aircraft's position to your camera's position to get a "real location"

      -the camera's "look-at" should always point toward the aircraft (update your camera's view matrix)

-setup the aircraft's render matrix

      -create the aircraft's render matrix from its quaternion

      -position the aircraft in front of the camera to the specified distance

      -render........

Share this post


Link to post
Share on other sites
I see I am still not quite understood....I tried Alundra's idea (multiplying the camera rotation matrix by the inverse aircraft rotation matrix and then decomposing the resultant matrix into its Euler angles as per this site: http://nghiaho.com/?page_id=846 )
However, this is the result I get. As you can see in this picture, the camera pitch and bank relative to the aircraft are correct (0), as is the heading (-48.83).

87buw3z.png

In this next picture, the camera angle relative to the aircraft is again correct in pitch (-38.78) and bank and heading (0).

R3j80R2.png

The moment I combine a pitch and heading change however, this is what I get. Bank should still be 0 but as you can see it isn't. Any suggestions?

jxnennD.png Edited by Naruto-kun

Share this post


Link to post
Share on other sites

what is it you're trying to accomplish? odds are there is an easier way. i've done some work on flight sim code and local rotations, and have never heard of folks having to resort to such ugliness.  

nice graphics BTW!  need any testers? <g>.

Share this post


Link to post
Share on other sites

there is a formula for extracting the global xr and yr eulers from a 3d direction vector.

you could global un-rotate the plane to look down z with no roll (left hand system), and global un-rotate  the camera by the same amount, then use the algo with local instead of global axes - i'm pretty sure.  as i recall, the same can be done with the right vector instead of the forward vector to get the roll.

but it sounds like you're trying to position the camera with respect to the plane. there, one usually moves the camera with respect to the plane, then applies the plane's world mat to get the final position. or are you trying to back solve? IE- you know the plane's orientation, and the final camera angle, and are trying to determine the pilot's head rotation? i believe the method described above would get you that.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement