X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=assignment-2%2Freport.latex;fp=assignment-2%2Freport.latex;h=6730aa9bfb4dd75762ef3e2336fd44ddb4d90b23;hp=0000000000000000000000000000000000000000;hb=150ba29f1ce70777762cb7fc44e00e52339bb66e;hpb=5fa27af6222eab1f43e6ca01f1c37cbfa1d86fcd;ds=sidebyside diff --git a/assignment-2/report.latex b/assignment-2/report.latex new file mode 100644 index 0000000..6730aa9 --- /dev/null +++ b/assignment-2/report.latex @@ -0,0 +1,67 @@ +\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}