Elegant handling of the up vector in glm::lookat

Hi,

I use the glm::lookAt function as replacement for gluLookAt.
I know the math behind this function which is pretty straight
forward.

But one thing I was always wondering is how to handle the
up vector when you want to have a camera that can really
look free in all directions, even straight up (0,1,0) or
straight down (0,-1,0).

Of course you could detect this case and just pass a
different vector like (0,0,1) as up vector. But it could
happen that the camera starts to “spin” when the direction
vector becomes parallel to the (0,1,0) up vector and you
suddenly pass a different up vector (the roll of the
camera suddenly changes).

So how do they solve this in space combat games where you
can fly in all directions without having this ugly camera
roll “reset” when the vectors become parallel and the
default (0,1,0) vector cannot be used anymore?

Please note that I know that the purpose of the up vector
is NOT to define the camera roll. That is not my point.

Help is really appreciated!

Thanks

So how do they solve this in space combat games where you
can fly in all directions without having this ugly camera
roll “reset” when the vectors become parallel and the
default (0,1,0) vector cannot be used anymore?

You don’t use lookAt anymore. The orientation would generally be stored as a quaternion. When the ship rotates, the quaternion is rotated as well.

I see. Thanks!