3
votes

I need to create an up vector for when the camera looks at any angle (except directly down or up because the up vector would be perpendicular to the y-axis).

The up vector has to be perpendicular to the line of sight of-course. When the line of sight isn't along the y-axis, you can imagine a circle around the eye and the line of sight where the up vector could be. On this circle, there will be a point which goes further up the y-axis than any other point. This is what I want my up-vector to be.

I'm sure I can work out a solution but I'm guessing people would have done this plenty of times before and I want to have the most effective solution.

My camera, when using this at least, wont look directly down or up the y-axis so there is no problem there.

2

2 Answers

3
votes

gluLookAt does not require that the up vector you provide be perpendicular to the direction you’re looking. So you can just use 0,1,0.

If you really, really want to come up with a perpendicular vector, take a look at the man page for gluLookAt and do what they're doing to make u

17
votes

Most commercial games use the cross product to generate a perpendicular.

  • Normalize your look vector.

  • Take the cross product of your look vector and a vector of 0,1,0. This gives you your right vector.

  • Take the cross product of your right vector and your look vector. This is your new up vector, which is a perpendicular to your original look vector.