Stuff
[opengl.git] / assignment-4 / report.latex
1 \documentclass{article}
2 \usepackage{fullpage}
3 \usepackage{graphicx}
4 \usepackage{minted}
5 \begin{document}
6 \title{Hierarchical animation}
7 \author{Luke Lau 15336810}
8 \maketitle
9
10 \includegraphics[width=\textwidth]{chest0}
11 \includegraphics[width=\textwidth]{chest1}
12
13 \section{Loading models with AssImp}
14 I created a Model class that handles loading in the model from AssImp.
15 It has an internal class for each Node (\texttt{aiNode}) and a struct for Mesh (\texttt{aiMesh}).
16 \inputminted{c++}{../model.hpp}
17
18 Each mesh stores a vector of all its vertices, as well as a list of all the indices of these vertices that it needs to draw. By storing the vertices in a \texttt{GL\_ARRAY\_BUFFER} and the indices in a \texttt{GL\_ELEMENT\_ARRAY\_BUFFER}, this allows faces that reuse multiple vertices to be drawn with
19 \mintinline{c++}{glDrawElements(GL\_TRIANGLES, mesh.numIndices, GL\_UNSIGNED\_INT, 0)}, rather than \mintinline{c++}{glDrawArray(..)}.
20 The AssImp triangulation post-processing flag ensures that each face is a triangle, so that \texttt{GL\_TRIANGLES} can be used throughout.
21
22 \inputminted[firstline=6,lastline=72]{c++}{../model.cpp}
23
24 \section{Node hierarchy}
25
26 The nodes are stored in an hierarchical structure. The pretransform-vertices post-processing flag had to be disabled to prevent AssImp from flattening out the hierarchy, but this then allows for hierarchical animation to be done at each individual mesh in a single loaded object.
27
28 By naming each of the nodes (objects in blender) and setting them as parents, I was able to use \mintinline{cpp}{aiNode.FindNode(const char* name)} to access them from my program.
29
30         \includegraphics[width=\textwidth]{blender}
31
32 Each node object has a model variable which is then used in conjunction with its parent's model (and blender transformation) to work out the global transformation.
33 \inputminted[firstline=92,lastline=110]{c++}{../model.cpp}
34
35 Together with the ability to access nodes by name and set an individual transformation, defining the hierarchical animation can be done like so.
36
37 \inputminted[firstline=181,lastline=198,gobble=1]{c++}{../main.cpp}
38
39 \end{document}