Camera math: How to calculate the horizontal and vertical angle from the look at vector - Game Development Stack Exchange most recent 30 from gamedev.stackexchange.com 2019-10-17T05:18:36Z https://gamedev.stackexchange.com/feeds/question/149445 https://creativecommons.org/licenses/by-sa/4.0/rdf https://gamedev.stackexchange.com/q/149445 1 Camera math: How to calculate the horizontal and vertical angle from the look at vector MattMatt2000 https://gamedev.stackexchange.com/users/108218 2017-10-11T14:56:49Z 2017-10-11T17:52:01Z <p>I'm using the <strong>PerspectiveCamera</strong> class in C#/WPF to implement an FPS style camera.</p> <p>For that, I would need to offset the camera's horizontal and vertical angles every time the mouse is moved. The problem is that PerspectiveCamera doesn't store those angles and only provides a lookat vector.</p> <p>So, is there a way to <strong>calculate those angles from the lookat vector</strong> ?</p> https://gamedev.stackexchange.com/questions/149445/-/149447#149447 1 Answer by Bram for Camera math: How to calculate the horizontal and vertical angle from the look at vector Bram https://gamedev.stackexchange.com/users/11979 2017-10-11T16:49:14Z 2017-10-11T17:52:01Z <p>If there is no roll in your FPS camera (typically, there is not in an FPS) then all you need to do to get a yaw angle (-π..π ) from the vector is the atan2() function.</p> <p>As suggested by DMGregory, the arcsin of the z component of the forward vector gives the tilt angle.</p> <pre><code>#include &lt;math.h&gt; ... // calculate yaw const float yaw_angle = atan2f( cam_fwd.y, cam_fwd.x ); // calculate pitch const float pitch_angle = asinf( cam_fwd.z ); </code></pre> <p>This assumes you know where the camera is looking (cam_fwd.)</p>