\documentclass{article}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{minted}
\begin{document}
\title{Assignment 2}
\author{Luke Lau 16336810}
\maketitle

\setminted[c++]{stripall,linenos,breaklines,tabsize=4}

\section{3D}
For 3D, I first had to add an additional number of vertices to create a square pyramid model:

\inputminted[firstline=181,lastline=198,gobble=1]{c++}{../main.cpp}

The vertex shader then got 3 new matrices: the model, view and projection matrices.

\inputminted{glsl}{../vertex.glsl}

These matrices are computed and bound during the display function:

\inputminted[firstline=36,lastline=45,gobble=2]{c++}{../main.cpp}
\inputminted[firstline=62,lastline=62,gobble=2]{c++}{../main.cpp}

\texttt{GL\_DEPTH\_TEST} also needed to be enabled so that each side of pyramid was drawn in the correct order (lower Z values first, higher Z values last).

\section{Transformations and Animations}

Various scale, rotation and translation transformations can be performed by manipulating the model matrix.
To animate it, the amount that the model is transformed by can be multiplied with the elapsed time at the time of drawing.
\inputminted[firstline=47,lastline=59,gobble=2]{c++}{../main.cpp}
It was important to translate the model into its position in the world first, before performing any of the rotation or scaling, otherwise the rotation/scaling ended up affecting its position.

\section{Multiple Pyramids}
Originally I planned on duplicating the vertices stored in the vertex buffer, but as it turns out is sufficient enough to redraw the same 12 vertices and just translate them beforehand.

\begin{figure}[!htb]
\minipage{0.32\textwidth}
  \includegraphics[width=\linewidth]{plain}
  \caption{The pyramids with no transformations}
\endminipage\hfill
\minipage{0.32\textwidth}
  \includegraphics[width=\linewidth]{rotateAndScale}
  \caption{Scaling and rotation applied}
\endminipage\hfill
\minipage{0.32\textwidth}
  \includegraphics[width=\linewidth]{translate}
  \caption{Sinusoidal translations, individual to each pyramid}
\endminipage
\end{figure}

\section{Camera and movement}

I handle keyboard input by storing a map of which keys are currently pressed down, and then updating the position on a timer.
\inputminted[firstline=210,lastline=246]{c++}{../main.cpp}

The yaw used above is calculated alongside the pitch based on mouse movement.
\inputminted[firstline=248,lastline=271]{c++}{../main.cpp}

By working on the pitch and yaw of the camera, we can calculate the direction the camera should be facing. This is stored in the \texttt{camFront} vector.
This is combined with \texttt{camUp}, which defines the roll of the camera, and is used to calculate the view matrix with \mintinline{c++}{glm::lookAt}.
Since we don't want the camera to be angled on its side, \texttt{camUp} is left as just the $y$ normal vector.



\end{document}
