Determine the step, yaw, throw from front to top

In my openGL didactic application, I have some objects on the stage, and when I click on one of them, I want my camera to look at this object. To do this, after I define the object with a click, I calculate the front, right and right vectors of the camera, and then I need to calculate the angle of inclination, yaw, camera rotation angles. However, I absolutely do not know how I can do this, so any help would be great.

+3
source share
2 answers

In fact, you do not need to do all these calculations. just use it glLookAt(). it occupies the position of the camera, the position of where you want to look, and the vector is up and orientes the matrix of the model’s representation, respectively.

If you really want to do this with difficulty, look at my answer to this question .

+1
source

This is a matter of calculating back. From the vector frontyou should be able to easily derive yawand pitch.

If your coordinate system has x and z as gender

yaw = atan2(front.z, front.x);

The step can be calculated by normalizing frontand using asin

front.normalize();
pitch = asin(front.y);

If I have time later, I will look at the calculation roll

Otherwise, there is a good suggestion to use gluLookAt

+1
source

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


All Articles