- Home /
Quaternion, Eulers and Problems
Good afternoon. I have the following problem with conversion of quaternions. For the explanation I will write the direct code:
float zAn = 40;
float yAn = -56;
Quaternion myq = Quaternion.Euler(0, 0, zAn);
Cube.rotation = myq;
Cube.Rotate(Vector3.right, yAn, Space.self);
Quaternion myqD = Cube.rotation;
Cube.Rotate(Vector3.forward, -zAn, Space.world);
Debug.Log("MyAng " + Cube.eulerAngles.x + " " + Cube.eulerAngles.y + " " + Cube.eulerAngles.z);
From debug I see (-56, 0, 0). That that also is necessary to me. But a problem that at me myqD is known only. How to calculate zAn if myqD is known only? Thanks in advance for the help.
Answer by maxoja · Dec 30, 2013 at 11:37 AM
when you call a variable like Quaternion or Vector3, they wont be update from Cube by itself. It just hang on that value you set in the line so if you want to make it realtime you should set the value of myqD again after you Rotate the Cube.
Just move the this line down to the bottom before the Debugging.
Quaternion myqD = Cube.rotation;
I'm not sure if my answer is what you want to know so please comment after you read this, I hope it works :)
@maxoja I this value of a quaternion (from a gyroscope). I at first write Cube.rotation = myqD, where with myqD - a gyroscope quaternion. I need to make a certain conversion that eulerAngles were as (xAn, yAn, 0). Conversion shall be provided in a look:
Cube.Rotate(Vector3.forward, -zAn, Space.world);
Space.world - a main component. I need to find zAn angle from a quaternion. Above in the question I wrote, what conversions it is possible to receive a gyroscope quaternion. But I don't manage to solve the reverse problem (from a quaternion to receive those angles which participate in initial conversion. And it not eulerAngles).