Im actual stuck at the calculation of the 3rd Person View.
Im currently moving the Camera around its y-axis (UP vector -> vec3(0.0, 1.0, 0.0)) when holding left mouse and moving it and saving it into a viewDirection variable.
It means, the cam is looking at the viewDirection (glm::lookAt calculates the world to view matrix for me)
I can also move the cam with “WASD” keys which crosses the view direction with the up vector and the movement-speed i have set.
Now, i would like to attach my cam to an object, which im moving then with “WASD” and rotating around / up and down it with the mouse by holding left mouse key.
The calculations tutorials are using a pitch and a yaw value, to make those calcs.
How can i determine this angles with my given vectors/other values?
If the camera were an object, the sequence of transformations to place and orient it would be:
[ol]
[li] translate by target position
[/li][li] rotate about Y by heading
[/li][li] rotate about X by elevation
[/li][li] translate along Z by distance
[/li][/ol]
I.e.:
translate(target) * rotate_y(heading) * rotate_x(elevation) * translate(0,0,distance)
But the view matrix is the inverse of the camera’s transformation, so you need to invert that. Typically, you use the fact that
(A.B)-1=B-1.A-1
I.e. to invert a sequence of transformations, you invert the individual transformations and apply them in the reverse order, so:
So i have to remove my implementation with the view Direction and the up vector (world to view matrix would be the look at of the position, position + view direction and the up vector) to a translation matrix?