Hello again…okay, my next project is a 3D space combat almost-sim.

The ship should be able to pitch and roll depending on the joystick positions. Unfortunately, I’m encountering a problem that I believe is called gimbal lock. I’ve heard that this can be corrected with quaternion math, but my math education isn’t advanced enough yet for me to understand this. Can anyone direct me to any useful libraries/engines/code snippets or techniques that wouldn’t be too complex? Thanks.

Gimbal lock is not solved with quaternions. Gimbal lock is an effect of the rotation representation you use, not how you realize those rotations. So it’s just as easy to run into it with quaternions as with matrix rotations, and you can avoid it as easily with matrix rotations as with quaternions.

The Gimbal lock is an effect of Euler angle rotations, and switching to quaternions, but preserving the underlaying Euler angle rotation system, will not eliminate the Gimbal lock problem. If you solve it with quaternions, you have solved it with matrix rotations also.

What you have to do to avoid Gimbal lock is to not use Euler angles. Look into axis/angle rotation systems instead, in which case quaternions are useful.

Also, but I’m not entirely sure, I don’t think you can ever run into the Gimbal lock problem by only using two euler angles. You need three angles to even have a chance. Rotate first angle by a certain amount so the two remaining rotation axes are the same and you lose one degree or freedom. With two rotation angles, you still have the remaining degree of freedom left for use.

Okay…maybe my problem isn’t gimbal lock. I’ll describe it to you.

So, you know that I want my ship to pitch and roll. Whenever my pitch is at zero degrees, my roll works perfectly. However, when I pitch down 90, my roll becomes yaw. I think I described my problem wrong…how can I fix this?

You may need additional code to adjust rotation speed.
Even more… you can use absolute values from joystick as delta values… when player pull or push joystic more, ship will rotate faster.

Hmmm…what type of variable is “mat4”, and what’s “BuildRotationMatrix”?

I understand what you’re getting at with how the rotation will increase with the joystick angle…I’m not sure how this can solve my problem; I don’t understand those types mentioned above. Could you please explain them, or where you got them?

pfff… It’s a pseudocode. I suppose you already have your own math library. In short…
mat4 is 4x4 matrix
BuildRotationMatrix(roll, pitch) should build 4x4 matrix based on rool and pitch value.
a = b is equal to a = a b

So, you know that I want my ship to pitch and roll. Whenever my pitch is at zero degrees, my roll works perfectly. However, when I pitch down 90, my roll becomes yaw. I think I described my problem wrong…how can I fix this?
What you describe here sounds a lot like you apply pitch and roll in the wrong order.

@aramil:
When you fly a space ship… your controls should be applyed relative from ship orientation. You can’t apply absolute rotations.

Sarcasm… not… Since you didn’t know what is mat4 I was think it is better to explain multiplication too. Maybe im not precise enough… It was matrix multiplication, ie. matrix composition.