Camera viewport transformation from one world to the rotated world.

Hi. We are working on a viewport based 360 video streaming service and faced a difficult problem, perhaps called as the change of basis problem.

Assuming a user is watching at a point (red dot in the figure) where the main camera’s Euler angles are (20, 20, 0) in pitch, yaw, and roll angles in the original world space of which Euler angles are (0, 0, 0).

116759-ori.png

Owing to the viewport based service issue, we rotated the original world to (-20, 0, 0) angles and we want to know how the user can have the same viewport in the new world, meaning exactly watching the red sun in the middle. So, here in the rotated world, what will be the Euler angles of the headset? is our question.

116760-rotated.png

We used Quaternion.euler function to rotate the headset angle but it didn’t work as we expected. Ex) (-20, 0, 0).

This problem seems to be calculating Euler angles of an object from XYZ coordinate world to rotated XYZ coordinate world. Any suggestions? Thanks.

I would combine the two Euler Angles as Quaternions. E.g.

Quaternion camRotation = Quaternion.Euler(20,20,0);
Quaternion worldRotation = Quaternion.Euler(-20,0,0);
Quaternion result= worldRotation  * camRotation;  //Note: order is important when multiplying quaternions! (and I might have it backwards)
Vector3 resultEulers = result.eulerAngles;