# Question How do I read the rotation in degrees of a VR Camera?

Discussion in 'VR' started by apaul, Nov 16, 2022.

1. ### apaul

Joined:
Jun 24, 2013
Posts:
8
I am trying to record the angular rotation in degrees (x,y,z) from the OVRPlayerController Centre Camera to read the head rotation of the player.

I am using Camera.main.transform.eulerAngles.x (y and z) to record it. Is this the right approach?

Or should I read the rotation of the OVRCameraRig?

2. ### DevDunk

Joined:
Feb 13, 2020
Posts:
2,502
Camera.main should be your VR camera, but I suggest to make a Camera (or Transform) variable where you put the camera in. Then it should just read that transform.
OVRCameraRig is the whole player I think, don't think thats what you want

3. ### apaul

Joined:
Jun 24, 2013
Posts:
8

The issue I am having is that the data I get in eulerAngles/ degrees has a lot of outliers or gimbal lock issues. I am not an advanced programmer, so I don't know the straightforward way of converting Quaternions to Degrees. I can't seem to get my way into figuring this problem out.

Is there a simple way to get that done in Unity? Below is how I am recording the data from the camera.

Code (CSharp):
1.
2.         Quaternion camData = Camera.main.transform.rotation;
3.         Vector3 eRotation = Camera.main.transform.eulerAngles;
4.
5.         x = camData.x;
6.         y = camData.y;
7.         z = camData.z;
8.         w = camData.w;
9.
10.         x1 = eRotation.x;
11.         y1 = eRotation.y;
12.         z1 = eRotation.z;

4. ### DevDunk

Joined:
Feb 13, 2020
Posts:
2,502
That's what eulerangles does. What do you want to do?

5. ### apaul

Joined:
Jun 24, 2013
Posts:
8
I want the accurate camera rotation values in angular degrees or radians for the x, y and z axis. I am unable to do that and don't know how to do that mathematically through programming.

I haven't found any working excel macros/ formulas that I can use on the values that I am recording either. I am lost about how to deal with this even after reading through countless posts online.

6. ### JuanGuzmanH

Joined:
Feb 8, 2018
Posts:
48
Sorry. Im not able to understand what do you mean with outliers or gimbal lock issues.

You are reading the data properly from the camera, why this data is not useful for you? You need maybe an offset? or to get the orientation related to another object?

DevDunk likes this.
7. ### apaul

Joined:
Jun 24, 2013
Posts:
8
* When an object in 3D space loses a degree of freedom and can only rotate within two dimensions, it’s called gimbal lock. Gimbal lock can occur with Euler angles if two axes become parallel. If you don’t convert the rotational values to Euler angles in your script, the use of quaternions should prevent gimbal lock. *

The data is not useful anymore as it suddenly jumps from 0 degrees to 359 on each axis when I am measuring the rotation. For example, if the rotation starts at 8 degrees and keeps going down, it shifts to 359 just after it hits the 0 mark when I am trying to capture the head rotation data.

Please see the y axis rotation value on the excel sheet.

8. ### DevDunk

Joined:
Feb 13, 2020
Posts:
2,502
It can definitely still be useful. So again, what do you want to do with the info

9. ### JuanGuzmanH

Joined:
Feb 8, 2018
Posts:
48
The data looks good and coherent for me. If your problem is to keep constant the representation of the angles, for example always positive angles, just add 360 to those angles with negative values.
From my understanding the data is not jumping , 0 degrees and 359 has only one degree of diference and is the same distance in degrees than 0 and 1 degree.

DevDunk likes this.
10. ### apaul

Joined:
Jun 24, 2013
Posts:
8
Thank you for the reply. I will try to apply what you have said and come back with feedback.