views:

72

answers:

2

Hello, 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.

THank you for any answers in advance.

+1  A: 

gluLookAt does not require 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

Jay Kominek
I thought it caused some problems with the perspective does it not? It makes no difference at all?Thank you very much for the answer.
Matthew Mitchell
Again, if you look at the gluLookAt man page, they tell you exactly what they're doing. They perpendicularize the up vector you provide, basically as lisarc describes it. (And, by the way, if you're thankful, you can up vote your answerers, and accept one of them.)
Jay Kominek
It didn't say that on the documentation I looked at. I saw many pages saying the up vector needs to be perpendicular but thank you for clearing it up.I do know how to accept an answer, yes. I was hoping for a reply before I accepted yours.
Matthew Mitchell
+1  A: 

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.

Thank you for the answer. I'll use your suggestion unless it turns out I don't need a perpendicular up vector.
Matthew Mitchell