- Home /
How good is my "Quaternion" code efficiency?
Hello,
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.
Yes but this may not work: see my answer.
I will "appear" to work because you are in a special case where one component is zero. But the angle variation will not be linear, unless you know how to recompute the w-component. But in this case you are just reinventing the wheel.
@kryptos - I have one answer from Nicolas, is that you?
Thanks guys. I might have to find another way then. I will have to see. Is there any tips you guys could give me.
I am trying to control a falling object. Hence, my plane is x and z. So I move in a 2 - dimensional way (XZ). Could give me an idea where I could rotate the object?
Like you see my code above - I get the input and apply to the rotation.
Thanks guys.
Answer by Kryptos · Jul 13, 2012 at 02:26 PM
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.
NIcolas, that documentation lead to the concern actually. Thanks man. I will have to look into other options and try to find a way.
First - Quaternion.AngleAxis.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
[Solved] Help on a rotation issue for a Top-Down view? 1 Answer
[SOLVED] Derive an equation from a graph? 1 Answer
How to create a damped harmonic oscillation? 1 Answer
Audio: how do I immediately play a new audioclip without delay(code included)? 2 Answers