<p>It's happening because they just happened to define the rotation matrix with counterclockwise rotation direction, which is the common convention for polar$\rightarrow$cartesian coordinate system transformation. If you <a href="https://www.google.ca/search?q=polar%20to%20cartesian%20coordinates&amp;espv=2&amp;biw=1920&amp;bih=911&amp;source=lnms&amp;tbm=isch&amp;sa=X&amp;ved=0ahUKEwj_6qCA-K3QAhXi7YMKHcmQCwUQ_AUIBigB&amp;dpr=1#imgrc=_" rel="nofollow noreferrer">google for the transformation</a>, you'll see that the angle is universally shown to rotate to the counterclockwise direction like below</p>

<p><a href="https://i.sstatic.net/DU3pS.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DU3pS.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2016-11-16T20:41:15.820Z
Only the yaw is inverted, the pitch works as expected.
user5488
CC BY-SA 3.0
2016-11-16T20:55:11.100Z
Are you saying that the rotation doesn't happen to the counterclockwise direction with increasing angles in your coordinate system?
JarkkoL
CC BY-SA 3.0
2016-11-16T21:09:44.730Z
It is counterclockwise on the Y axis (the yaw), i.e. increasing the angle (or looking right) causes the fixed object the camera is looking at to go right, but clockwise on the X axis (the pitch), increasing the angle (looking up) causes the object to go down as expected.
user5488
CC BY-SA 3.0
2016-11-17T22:18:57.007Z
What's the coordinate system you are using (x=right, etc)?
JarkkoL
CC BY-SA 3.0
2016-11-17T22:45:38.080Z
Right handed system with +x is right, +y is up
user5488
CC BY-SA 3.0
2016-11-17T23:28:39.883Z
Ok, so in that case both rotate to the same direction about their respective rotation axes (x- and y-axis for pitch & yaw respectively) and you get the behaviour you defined, as expected. If YOU expect different rotation direction, then you just have to transpose the matrix like you said, or negate the angle.
JarkkoL
CC BY-SA 3.0
2016-11-18T15:52:35.830Z
Negating the yaw won't make the matrix consistent with the definition of the view matrix (i.e. the inverse of the camera world matrix). It would mean that `Ry Rpᵀ T⁻¹` while it should have been `Ryᵀ Rpᵀ T⁻¹`.
user5488
CC BY-SA 3.0
2016-11-18T16:02:54.773Z
If you negate the yaw angle, you don't need to transpose the yaw matrix. Personally I think it's better to negate the angle.
JarkkoL
CC BY-SA 3.0
2016-11-16T18:55:06.673Z
2016-11-16T18:55:06.673Z
JarkkoL
<p>I'm trying to construct a FPS view matrix for my OpenGL renderer using yaw and pitch angles instead of the typical <code>LookAt</code> view matrix.</p>

<p>The view matrix is the inverse of the camera world transform $\mathbf{M}_{\textrm{view}} = (\mathbf{T}\mathbf{R}_p\mathbf{R}_y)^{-1}$, hence:</p>

<p>$$\small\begin{align}
(\mathbf{T}\mathbf{R}_p\mathbf{R}_y)^{-1} &amp;= \mathbf{R}_y^{T}\mathbf{R}_p^{T}\mathbf{T}^{-1} \\
&amp;= \begin{bmatrix}
\cos{y} &amp; 0 &amp; \sin{y} &amp; 0 \\
0 &amp; 1 &amp; 0 &amp; 0 \\
-\sin{y} &amp; 0 &amp; \cos{y} &amp; 0 \\
0 &amp; 0 &amp; 0 &amp; 1
\end{bmatrix}^T
\begin{bmatrix}
1 &amp; 0 &amp; 0 &amp; 0 \\
0 &amp; \cos{p} &amp; -\sin{p} &amp; 0 \\
0 &amp; \sin{p} &amp; \cos{p} &amp; 0 \\
0 &amp; 0 &amp; 0 &amp; 1
\end{bmatrix}^T
\begin{bmatrix}
1 &amp; 0 &amp; 0 &amp; e_0 \\
0 &amp; 1 &amp; 0 &amp; e_1 \\
0 &amp; 0 &amp; 1 &amp; e_2 \\
0 &amp; 0 &amp; 0 &amp; 1
\end{bmatrix}^{-1} \\
&amp;=
\begin{bmatrix}
\cos{y} &amp; 0 &amp; -\sin{y} &amp; 0\\
0 &amp; 1 &amp; 0 &amp; 0 \\
\sin{y} &amp; 0 &amp; \cos{y} &amp; 0\\
0 &amp; 0 &amp; 0 &amp; 1
\end{bmatrix}
\begin{bmatrix}
1 &amp; 0 &amp; 0 &amp; 0\\
0 &amp; \cos{p} &amp; \sin{p} &amp; 0\\
0 &amp; -\sin{p} &amp; \cos{p} &amp; 0\\
0 &amp; 0 &amp; 0 &amp; 1
\end{bmatrix}
\begin{bmatrix}
1 &amp; 0 &amp; 0 &amp; -e_0\\
0 &amp; 1 &amp; 0 &amp; -e_1\\
0 &amp; 0 &amp; 1 &amp; -e_2\\
0 &amp; 0 &amp; 0 &amp; 1\\
\end{bmatrix} \\
&amp;=
\begin{bmatrix}
\cos{y} &amp; \sin{p}\sin{y} &amp; -\cos{p}\sin{y} &amp; -e_0\cos{y} - e_1\sin{p}\sin{y} + e_2\cos{p}\sin{y}\\
0 &amp; \cos{p} &amp; \sin{p} &amp; -e_0 \cdot 0 - e_1 \cos{p} - e_2 \sin{p}\\
\sin{y} &amp; -\cos{y}\sin{p} &amp; \cos{p}\cos{y} &amp; -e_0\sin{y} + e_1\cos{y}\sin{p} - e_2\cos{p}\cos{y}\\
0 &amp; 0 &amp; 0 &amp; 1
\end{bmatrix}
\end{align}$$</p>

<p>Every step is double checked using WolframAlpha.</p>

<p>The implementation:</p>

<pre class="lang-cpp prettyprint-override"><code>inline Matrix4
FPSViewRH(const Vector3&amp; eyePosition, float yaw, float pitch) noexcept
{
  yaw = Utils::Radians(yaw);
  pitch = Utils::Radians(pitch);

  const auto sinYaw = std::sin(yaw);
  const auto cosYaw = std::cos(yaw);

  const auto sinPitch = std::sin(pitch);
  const auto cosPitch = std::cos(pitch);

  const Vector3 i{cosYaw, sinPitch * sinYaw, -cosPitch * sinYaw};
  const Vector3 j{0, cosPitch, sinPitch};
  const Vector3 k{sinYaw, -cosYaw * sinPitch, cosPitch * cosYaw};

  return {
    {i[0], i[1], i[2], -i.Dot(eyePosition)},
    {j[0], j[1], j[2], -j.Dot(eyePosition)},
    {k[0], k[1], k[2], -k.Dot(eyePosition)},
    {0,    0,    0,    1},
  };
}
</code></pre>

<p>It works fine except that <em>the yaw is inverted</em>, i.e. increasing the angle causes the object to go right while it should go left.</p>

<p>I can negate the yaw angle or change every $\sin{y}$ to $-\sin{y}$, but I don't really understand <em>why this is happening</em>?</p>

CC BY-SA 4.0
2020-09-26T17:51:08.510Z
In case it provides any help, according to https://www.3dgep.com/understanding-the-view-matrix/#Look_At_Camera some signs are changed, which would not make sense according to me, as it does not make sense with the rotation matrix multiplication results. You can check that in the FPS camera section
rustyBucketBay
CC BY-SA 4.0
2020-09-26T18:00:00.157Z
Oh In the case if the example provided it says that "The basic theory of this camera model is that we want to build a camera matrix that first rotates pitch angle about the X axis, then rotates yaw angle about the Y axis, then translates to some position in the world" that means that the order of the rotation is inverted. So if I do RpT * RyT, the signs are correct. Sorry if that was confusing
rustyBucketBay
<transformations><camera-matrix>
Inverted yaw angle in the view matrix
user5488
# Inverted yaw angle in the view matrix

(Asked by: username_0 on 2016-11-15)

I'm trying to construct a FPS view matrix for my OpenGL renderer using yaw and pitch angles instead of the typical `LookAt` view matrix.

The view matrix is the inverse of the camera world transform $\mathbf{M}\_{\textrm{view}} = (\mathbf{T}\mathbf{R}\_p\mathbf{R}\_y)^{-1}$, hence:

$$\small\begin{align}
(\mathbf{T}\mathbf{R}\_p\mathbf{R}\_y)^{-1} &= \mathbf{R}\_y^{T}\mathbf{R}\_p^{T}\mathbf{T}^{-1} \\
&= \begin{bmatrix}
\cos{y} & 0 & \sin{y} & 0 \\
0 & 1 & 0 & 0 \\
-\sin{y} & 0 & \cos{y} & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}^T
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & \cos{p} & -\sin{p} & 0 \\
0 & \sin{p} & \cos{p} & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}^T
\begin{bmatrix}
1 & 0 & 0 & e\_0 \\
0 & 1 & 0 & e\_1 \\
0 & 0 & 1 & e\_2 \\
0 & 0 & 0 & 1
\end{bmatrix}^{-1} \\
&=
\begin{bmatrix}
\cos{y} & 0 & -\sin{y} & 0\\
0 & 1 & 0 & 0 \\
\sin{y} & 0 & \cos{y} & 0\\
0 & 0 & 0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0\\
0 & \cos{p} & \sin{p} & 0\\
0 & -\sin{p} & \cos{p} & 0\\
0 & 0 & 0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & -e\_0\\
0 & 1 & 0 & -e\_1\\
0 & 0 & 1 & -e\_2\\
0 & 0 & 0 & 1\\
\end{bmatrix} \\
&=
\begin{bmatrix}
\cos{y} & \sin{p}\sin{y} & -\cos{p}\sin{y} & -e\_0\cos{y} - e\_1\sin{p}\sin{y} + e\_2\cos{p}\sin{y}\\
0 & \cos{p} & \sin{p} & -e\_0 \cdot 0 - e\_1 \cos{p} - e\_2 \sin{p}\\
\sin{y} & -\cos{y}\sin{p} & \cos{p}\cos{y} & -e\_0\sin{y} + e\_1\cos{y}\sin{p} - e\_2\cos{p}\cos{y}\\
0 & 0 & 0 & 1
\end{bmatrix}
\end{align}$$

Every step is double checked using WolframAlpha.

The implementation:

```cpp
inline Matrix4
FPSViewRH(const Vector3& eyePosition, float yaw, float pitch) noexcept
{
  yaw = Utils::Radians(yaw);
  pitch = Utils::Radians(pitch);

  const auto sinYaw = std::sin(yaw);
  const auto cosYaw = std::cos(yaw);

  const auto sinPitch = std::sin(pitch);
  const auto cosPitch = std::cos(pitch);

  const Vector3 i{cosYaw, sinPitch * sinYaw, -cosPitch * sinYaw};
  const Vector3 j{0, cosPitch, sinPitch};
  const Vector3 k{sinYaw, -cosYaw * sinPitch, cosPitch * cosYaw};

  return {
    {i[0], i[1], i[2], -i.Dot(eyePosition)},
    {j[0], j[1], j[2], -j.Dot(eyePosition)},
    {k[0], k[1], k[2], -k.Dot(eyePosition)},
    {0,    0,    0,    1},
  };
}

```

It works fine except that *the yaw is inverted*, i.e. increasing the angle causes the object to go right while it should go left.

I can negate the yaw angle or change every $\sin{y}$ to $-\sin{y}$, but I don't really understand *why this is happening*?

**Tags:** transformations, camera-matrix

> **Comments:**
> **username_1**: In case it provides any help, according to https://www.3dgep.com/understanding-the-view-matrix/#Look_At_Camera some signs are changed, which would not make sense according to me, as it does not make sense with the rotation matrix multiplication results. You can check that in the FPS camera section  
> **username_1**: Oh In the case if the example provided it says that "The basic theory of this camera model is that we want to build a camera matrix that first rotates pitch angle about the X axis, then rotates yaw angle about the Y axis, then translates to some position in the world" that means that the order of the rotation is inverted. So if I do RpT * RyT, the signs are correct. Sorry if that was confusing  

---

## 1 answers

### Answer by username_2 on 2016-11-16. Score: 1

It's happening because they just happened to define the rotation matrix with counterclockwise rotation direction, which is the common convention for polar$\rightarrow$cartesian coordinate system transformation. If you [google for the transformation](https://www.google.ca/search?q=polar%20to%20cartesian%20coordinates&espv=2&biw=1920&bih=911&source=lnms&tbm=isch&sa=X&ved=0ahUKEwj_6qCA-K3QAhXi7YMKHcmQCwUQ_AUIBigB&dpr=1#imgrc=_), you'll see that the angle is universally shown to rotate to the counterclockwise direction like below

[![enter image description here](https://i.sstatic.net/DU3pS.png)](https://i.sstatic.net/DU3pS.png)

> **Comments:**
> **username_0**: Only the yaw is inverted, the pitch works as expected.  
> **username_2**: Are you saying that the rotation doesn't happen to the counterclockwise direction with increasing angles in your coordinate system?  
> **username_0**: It is counterclockwise on the Y axis (the yaw), i.e. increasing the angle (or looking right) causes the fixed object the camera is looking at to go right, but clockwise on the X axis (the pitch), increasing the angle (looking up) causes the object to go down as expected.  
> **username_2**: What's the coordinate system you are using (x=right, etc)?  
> **username_0**: Right handed system with +x is right, +y is up  
> **username_2**: Ok, so in that case both rotate to the same direction about their respective rotation axes (x- and y-axis for pitch & yaw respectively) and you get the behaviour you defined, as expected. If YOU expect different rotation direction, then you just have to transpose the matrix like you said, or negate the angle.  
> **username_0**: Negating the yaw won't make the matrix consistent with the definition of the view matrix (i.e. the inverse of the camera world matrix). It would mean that `Ry Rpᵀ T⁻¹` while it should have been `Ryᵀ Rpᵀ T⁻¹`.  
> **username_2**: If you negate the yaw angle, you don't need to transpose the yaw matrix. Personally I think it's better to negate the angle.  

---

