I'm using unity3d to create a six-degree of freedom flying game. The game takes in input from a standard dual-stick gamepad (like the Logitech f310).
In unity each of the gamepad's joystick's axes are stored as a float value range from a negative minimum to a positive maximum. Minimum value when the joystick is pushed all the way down, maximum value when the joystick is pushed all the way up, and zero when the joystick is centered at rest. (see diagram)
This gives me three float values which can then store as a 3 vector for which I want to use to rotate my object.
inputVector = new Vector3(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"), Input.GetAxis("Pitch"));
In unity3d a gameobject's rotation/orientation is stored in a quaternion. this is a mathematical structure that can represent rotation in 3d like a 3x3 matrix, but with fewer variables and without being sensitive to small angles, doesn't suffer from gimbal lock like Euler angles, and also rotations represented with it can be combined easily without issue unlike angle-axis representation.
With all that out of the way, I'm trying use my "input" vector (or at least the three separate values for my three joystick axes) to rotate my quaternion so I can have 3D rotational movement without singularities like gimbal lock and such.
I already know that unity has two functions related to this, Quaterion.Euler()
and Quaternion.AngleAxis()
but both of these have issues when dealing with 3D rotations, .Euler()
gives gimbal lock, and .AngleAxis()
ignores the magnitude of the individual axes being input which I suppose is the reason for no smooth rotations.
I've looked far and wide and not found a solution that fits my bill. Either I'm missing something or maybe I need to do the reverse of a quaternion rotation a point in 3D, but I need assistance.