# Converting world rotation to body rotation

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

## Recommended Posts

Hi guys

I am reading the pitch/bank/heading values of a camera in this flightsimulator. But I have a problem in that they are relative to world, not body.

In the example image, the aircraft is banked 25 deg to the left. The camera bank values reflect this. However, the camera bank angle relative to the aircraft is 0. This latter value is what I would like to calculate. Things get a little more complicated when I pan around to the left in this image. The bank angle becomes the pitch angle. Any suggestions?

##### Share on other sites

Well... Here is how I would do it:

There is world coordinates where all the objects should be located toward it. So that you can know exactly where the plane is regarding a given origin (let's say the airport). To my opinion, you should not have any rotation in this coordinate system.

And there is the object coordinate, one for each plane. This should allow to orientate the plane (pitch, yaw and roll). This object coordinate should be defined on the world coordinates of the plane (so you define a new origin and orientation at the world coordinates of the plane). For this to work well, all plane should be designed the same way (for example the nose of the plane should always be aligned with the +x coordinate).

For the cameras, if they move just like the plane, they should belong to new coordinates just like the object coordinates of the plane (since they follow the same moves like the plane). So for this kind of cameras following the plane, you'll have one new object coordinate for each. For the other cameras, if they belong to the airport, or any static location, you'll then have a new coordinate system at these locations. And you will adapt their rotations so that they can follow the plane.

To do that, you'll need some good matrix manipulations (mainly stack manipulations).

For sure, you should never mix pitch, roll and so on. If this happens to be the same as the plane, or another plane, or anything else, this is just a coincidence, this does not mean you have to use this new coordinate system.

##### Share on other sites
I think you misunderstood me a bit.... I didn't design the system. The camera data is literally the raw view matrix. It gets rotated by the aircraft rotation as well as eyepoint rotations. I am trying to reverse the aircraft rotation of the camera view direction so I can get view direction relative to what is inside the aircraft for the purposes of a custom 3D sound environment. Edited by Naruto-kun

##### Share on other sites

I'm very confused by your description, but if you have matrices, it should be pretty easy if you know the matrix algebra.

First, if you have the camera/view matrix, understand that its data is inverted (backwards) from an object's matrix. So all the math is backwards for the camera. Usually there is a matrix inversion function to calculate that for you.

The camera may be attached to the plane. It probably is to some extent. So, usually that's a matter of multiplying the object's world matrix times the camera matrix or some similar chain.

It sounds like you could do the math as normal, but invert the camera matrix and then rotate it 180 degrees to get the answer you want.

But you said that it is rotating globally, and you want it to rotate locally. I believe there are two ways to achieve this. Either move it to the origin 0,0,0 when doing the rotation and then move it back. Or, reverse the order of multiplication. Matrix multiplication is not commutative. So, the order you do the multiplication in matters.

##### Share on other sites

You can't know anything intrinsically about the plane orientation just from the camera orientation alone. If there is another data source you can use to get the plane orientation, you can just compare the two.

##### Share on other sites

Something is rotated in world to be as A in world. Something else is rotated in world to be as B in world.

How much B is rotated relative to A, is exactly the ration of B rotated by inverse rotation of A - this gives relative rotation of B towards A.

relAB= B*A-1

relAB is rotation matrix that relates rotation of B relative to A if they are in same space.

##### Share on other sites
I do have the plane orientation data. I'm just wondering how I should build the rotation matrix from it (inverse or something?) which I can then use to get the camera rotation values relative to the plane rather than the world.

##### Share on other sites

I do have the plane orientation data. I'm just wondering how I should build the rotation matrix from it (inverse or something?) which I can then use to get the camera rotation values relative to the plane rather than the world.

Camera is constructed from world space relative parameters (yaw, pitch roll, or up,front,right, all exist in world), so if you explain camera transformation as relative to some other transformation=space, you will get a bogus camera when applying those. Why do you ask this relative transformation, of what is that for? Camera view matrix construction hardly...

Also, your follow up question of this topic is totaly ..... bogus.

##### Share on other sites
I need the camera rotation for custom 3D sound engine purposes. Since I didn't create the camera (it is created internally by the simulator and I have to use a bit of reverse engineering to get hold of it) I need to be able to transform it so that I know where it is looking relative to the nose of the aircraft. Edited by Naruto-kun

##### Share on other sites

I need to be able to transform it so that I know where it is looking relative to the nose of the aircraft.

Should have said sooner, that is quite trivial to find out.

So I understand that you want roientation difference between camera lookat vector and plane nose.

- plane nose- be it a direction unit vector of your preference, you can detect it to be a vector in object space- even one of the base axises of object space, for example X axis, (1,0,0) vector.

- transform this object space vector/axis to world space, by world transformation matrix of plane

- now you have plane direction vector and camera lookat vector, both in common space, now you can compare them

- lookat vector is unit vector as well, so dot product between lookat vector and plane direction vector will tell you cosine of angle between them, ranging from 1->-1 as 0 dgrees to 180 degrees, but both directions- left or right, but that should be sufficient for your information against sound. You can even make cross products of them and compare those too if there is more in orientation against the sound- if it is a less univarsaling difference by observer.

##### Share on other sites
Thanks a bunch. Apologies for the misunderstanding.

##### Share on other sites

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

## 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

• ### Forum Statistics

• Total Topics
628724
• Total Posts
2984404

• 25
• 11
• 10
• 16
• 14