How good is my "Quaternion" code efficiency?


I have been working around Quaternions and I have a single piece of Quaternion code which seems to be the base for all the operations in my iPad game. I would like to know whether my code is efficient considering for the entire life-time of the project.

Kindly do let me know if it would cost issues in the future.

reqAngle = new Quaternion ((Input.gyro.attitude.y), 0 , -(Input.gyro.attitude.x), reqAngle.w);

Code Description:

  • reqAngle is a Quaternion variable set to identity in the start call. 
  • I get the Input through gryo and not through accerleration and this forms the base for the main Input gateways for the entire project. 

My main concern is “Quaternions”.

Thank you & Please.

The quaternion first three values, although called “x”, “y”, and “z” have nothing to do with the base axis or the three rotations along those axis. They are complex numbers living in a mixed 3D-imaginary space and a 1D real space.

Quoting Unity documentation:

However, they are based on complex numbers and are not easy to understand intuitively. Thus you almost never access or modify individual Quaternion components (x,y,z,w)

You need to use the other methods from the Quaternion class, such as Quaternion.AngleAxis.