Add belly to triangle
[opengl.git] / assignment-2 / report.latex
1 \documentclass{article}
2 \usepackage{fullpage}
3 \usepackage{graphicx}
4 \usepackage{minted}
5 \begin{document}
6 \title{Assignment 2}
7 \author{Luke Lau 16336810}
8 \maketitle
9
10 \setminted[c++]{stripall,linenos,breaklines,tabsize=4}
11
12 \section{3D}
13 For 3D, I first had to add an additional number of vertices to create a square pyramid model:
14
15 \inputminted[firstline=181,lastline=198,gobble=1]{c++}{../main.cpp}
16
17 The vertex shader then got 3 new matrices: the model, view and projection matrices.
18
19 \inputminted{glsl}{../vertex.glsl}
20
21 These matrices are computed and bound during the display function:
22
23 \inputminted[firstline=36,lastline=45,gobble=2]{c++}{../main.cpp}
24 \inputminted[firstline=62,lastline=62,gobble=2]{c++}{../main.cpp}
25
26 \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).
27
28 \section{Transformations and Animations}
29
30 Various scale, rotation and translation transformations can be performed by manipulating the model matrix.
31 To animate it, the amount that the model is transformed by can be multiplied with the elapsed time at the time of drawing.
32 \inputminted[firstline=47,lastline=59,gobble=2]{c++}{../main.cpp}
33 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.
34
35 \section{Multiple Pyramids}
36 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.
37
38 \begin{figure}[!htb]
39 \minipage{0.32\textwidth}
40   \includegraphics[width=\linewidth]{plain}
41   \caption{The pyramids with no transformations}
42 \endminipage\hfill
43 \minipage{0.32\textwidth}
44   \includegraphics[width=\linewidth]{rotateAndScale}
45   \caption{Scaling and rotation applied}
46 \endminipage\hfill
47 \minipage{0.32\textwidth}
48   \includegraphics[width=\linewidth]{translate}
49   \caption{Sinusoidal translations, individual to each pyramid}
50 \endminipage
51 \end{figure}
52
53 \section{Camera and movement}
54
55 I handle keyboard input by storing a map of which keys are currently pressed down, and then updating the position on a timer.
56 \inputminted[firstline=210,lastline=246]{c++}{../main.cpp}
57
58 The yaw used above is calculated alongside the pitch based on mouse movement.
59 \inputminted[firstline=248,lastline=271]{c++}{../main.cpp}
60
61 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.
62 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}.
63 Since we don't want the camera to be angled on its side, \texttt{camUp} is left as just the $y$ normal vector.
64
65
66
67 \end{document}