An efficient way to calculate the up vector for gluLookAt, which most indicates the y axis?

I need to create a vector up when the camera looks at any angle (except for straight down or up, because the vector up will be perpendicular to the y axis).

The up vector should be perpendicular to the line of sight of the course. When the line of sight is not along the y axis, you can imagine a circle around the eyes and a line of sight where the vector may be up. There will be a point on this circle that moves farther along 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 assume that people would have done it many times before, and I want to have the most effective solution.

My camera, when used, will at least not look directly down or up on the Y axis so that there are no problems.

+3
source share
2 answers

gluLookAtIt doesn’t require that the up vector you specify is perpendicular to the direction you are looking. So you can just use 0,1,0.

If you really want to come up with a perpendicular vector, look at the man page forgluLookAt and follow what they do to do u

+3
source

Most commercial games use a cross-product to create a perpendicular.

  • Normalize your gaze vector.

  • - 0,1,0. .

  • - . , .

+14

Source: https://habr.com/ru/post/1758460/


All Articles