
I'll use the OMAF coordinate system which defines the viewer looking out the $x$-axis with $z$-axis up and the $y$-axis to the left. Given a yaw angle $\phi$ and a pitch angle $\theta$ we transform the direction vector $(u,v,w)$ onto the view axis $(1,0,0)$ by first performing a clockwise rotation about the $z$-axis by $\phi$ followed by a counter-clockwise rotation about the $y$-axis by $\theta:$
$$
\left[\begin{array}{c}1\\0\\0\end{array}\right] = R_y(\theta) \cdot R_z(-\phi) \left[\begin{array}{c}u\\v\\w\end{array}\right]
$$
We then solve for $(u,v,w)$ and get
$$
\left[\begin{array}{c}u\\v\\w\end{array}\right] = R_z(\phi) \cdot R_y(-\theta) \left[\begin{array}{c}1\\0\\0\end{array}\right]
$$
$$
\left[\begin{array}{c}u\\v\\w\end{array}\right] = \left[\begin{array}{ccc}\cos\phi & -\sin\phi & 0 \\ \sin\phi & \cos\phi & 0\\ 0 & 0 & 1 \end{array}\right]\left[\begin{array}{ccc}\cos\theta & 0 & -\sin\theta \\ 0 & 1 & 0 \\ \sin\theta & 0 & \cos\theta \end{array}\right] \left[\begin{array}{c}1\\0\\0\end{array}\right] =
\left[\begin{array}{c}\cos\phi\cos\theta \\ sin\phi \cos\theta \\ \sin\theta \end{array}\right]
$$
which is your classical spherical to cartesian transformation where $\phi$ is the azimuthal angle and $\theta$ is the elevation angle. Note that the roll angle does not enter into the equation since it merely defines a rotation about the direction vector which does not alter the direction vector.
If you happen to be using OpenGL conventions where the viewer is looking out the $-z$-axis and the $y$-axis is "up" and the $x$-axis is to the right you will use the direction $(u',v',w') = (-v,w,-u).$