From: Luke Lau Date: Mon, 8 Oct 2018 17:01:52 +0000 (+0100) Subject: Add assignment 2 report X-Git-Tag: phong~2 X-Git-Url: http://git.lukelau.me/?p=opengl.git;a=commitdiff_plain;h=150ba29f1ce70777762cb7fc44e00e52339bb66e Add assignment 2 report --- diff --git a/.gitignore b/.gitignore index 0505cd2..409f1a5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,7 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake bin +*.pdf +*.aux +*.log +_minted-report diff --git a/part1.png b/assignment-1/part1.png similarity index 100% rename from part1.png rename to assignment-1/part1.png diff --git a/part2.png b/assignment-1/part2.png similarity index 100% rename from part2.png rename to assignment-1/part2.png diff --git a/part4.png b/assignment-1/part4.png similarity index 100% rename from part4.png rename to assignment-1/part4.png diff --git a/report.latex b/assignment-1/report.latex similarity index 100% rename from report.latex rename to assignment-1/report.latex diff --git a/assignment-2/plain.png b/assignment-2/plain.png new file mode 100644 index 0000000..a9927b9 Binary files /dev/null and b/assignment-2/plain.png differ 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} diff --git a/assignment-2/rotateAndScale.png b/assignment-2/rotateAndScale.png new file mode 100644 index 0000000..ce839ee Binary files /dev/null and b/assignment-2/rotateAndScale.png differ diff --git a/assignment-2/translate.png b/assignment-2/translate.png new file mode 100644 index 0000000..92cdb74 Binary files /dev/null and b/assignment-2/translate.png differ diff --git a/main.cpp b/main.cpp index 503f469..99312d3 100644 --- a/main.cpp +++ b/main.cpp @@ -42,9 +42,9 @@ void display() { glUniformMatrix4fv(viewId, 1, GL_FALSE, glm::value_ptr(view)); GLuint modelId = glGetUniformLocation(progId, "model"); - float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f; glm::mat4 model = glm::mat4(1.f); + float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f; model = glm::translate(model, glm::vec3(sin(i * 30) * 10, cos(i * 30) * 10, i * 2)); if (doRotate) { @@ -223,7 +223,7 @@ void keyboardUp(unsigned char key, int x, int y) { keyStates[key] = false; } -void idle(int _) { +void timer(int _) { float xSpeed = 0.f, ySpeed = 0.f, zSpeed = 0.f; if (keyStates['w']) zSpeed = 0.1f; @@ -288,7 +288,7 @@ int main(int argc, char** argv) { glutKeyboardFunc(keyboard); glutKeyboardUpFunc(keyboardUp); - glutTimerFunc(16, idle, 0); + glutTimerFunc(16, timer, 0); glutMotionFunc(motion); glutMouseFunc(mouse); diff --git a/report.aux b/report.aux deleted file mode 100644 index 423bc3d..0000000 --- a/report.aux +++ /dev/null @@ -1,7 +0,0 @@ -\relax -\@writefile{toc}{\contentsline {section}{\numberline {1}Fragment shader colours}{1}} -\@writefile{lol}{\contentsline {lstlisting}{fragment.glsl}{1}} -\@writefile{toc}{\contentsline {section}{\numberline {2}Two triangles}{2}} -\@writefile{toc}{\contentsline {section}{\numberline {3}Two triangles, two VAOs and two VBOs}{3}} -\@writefile{toc}{\contentsline {section}{\numberline {4}Two separate shaders}{4}} -\@writefile{lol}{\contentsline {lstlisting}{yellow.glsl}{5}} diff --git a/report.log b/report.log deleted file mode 100644 index 60a3ea9..0000000 --- a/report.log +++ /dev/null @@ -1,244 +0,0 @@ -This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2018.9.19) 22 SEP 2018 16:52 -entering extended mode - restricted \write18 enabled. - %&-line parsing enabled. -**report.latex -(./report.latex -LaTeX2e <2018-04-01> patch level 2 -Babel <3.18> and hyphenation patterns for 22 language(s) loaded. -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/base/article.cls -Document Class: article 2014/09/29 v1.4h Standard LaTeX document class -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/base/size10.clo -File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option) -) -\c@part=\count80 -\c@section=\count81 -\c@subsection=\count82 -\c@subsubsection=\count83 -\c@paragraph=\count84 -\c@subparagraph=\count85 -\c@figure=\count86 -\c@table=\count87 -\abovecaptionskip=\skip41 -\belowcaptionskip=\skip42 -\bibindent=\dimen102 -) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/preprint/fullpage.sty -Package: fullpage 1999/02/23 1.1 (PWD) -\FP@margin=\skip43 -) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/listings.sty -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/keyval.sty -Package: keyval 2014/10/28 v1.15 key=value parser (DPC) -\KV@toks@=\toks14 -) -\lst@mode=\count88 -\lst@gtempboxa=\box26 -\lst@token=\toks15 -\lst@length=\count89 -\lst@currlwidth=\dimen103 -\lst@column=\count90 -\lst@pos=\count91 -\lst@lostspace=\dimen104 -\lst@width=\dimen105 -\lst@newlines=\count92 -\lst@lineno=\count93 -\lst@maxwidth=\dimen106 - -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstmisc.sty -File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz) -\c@lstnumber=\count94 -\lst@skipnumbers=\count95 -\lst@framebox=\box27 -) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/listings.cfg -File: listings.cfg 2015/06/04 1.6 listings configuration -)) -Package: listings 2015/06/04 1.6 (Carsten Heinz) - -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/graphicx.sty -Package: graphicx 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR) - -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/graphics.sty -Package: graphics 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR) - -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/trig.sty -Package: trig 2016/01/03 v1.10 sin cos tan (DPC) -) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics-cfg/graphics.cfg -File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration -) -Package graphics Info: Driver file: pdftex.def on input line 99. - -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics-def/pdftex.def -File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex -)) -\Gin@req@height=\dimen107 -\Gin@req@width=\dimen108 -) -(./report.aux) -\openout1 = `report.aux'. - -LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 5. -LaTeX Font Info: ... okay on input line 5. -LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 5. -LaTeX Font Info: ... okay on input line 5. -LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 5. -LaTeX Font Info: ... okay on input line 5. -LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 5. -LaTeX Font Info: ... okay on input line 5. -LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 5. -LaTeX Font Info: ... okay on input line 5. -LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 5. -LaTeX Font Info: ... okay on input line 5. -\c@lstlisting=\count96 - -(/usr/local/texlive/2018basic/texmf-dist/tex/context/base/mkii/supp-pdf.mkii -[Loading MPS to PDF converter (version 2006.09.02).] -\scratchcounter=\count97 -\scratchdimen=\dimen109 -\scratchbox=\box28 -\nofMPsegments=\count98 -\nofMParguments=\count99 -\everyMPshowfont=\toks16 -\MPscratchCnt=\count100 -\MPscratchDim=\dimen110 -\MPnumerator=\count101 -\makeMPintoPDFobject=\count102 -\everyMPtoPDFconversion=\toks17 -) (/usr/local/texlive/2018basic/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty -Package: epstopdf-base 2016/05/15 v2.6 Base part for package epstopdf -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/infwarerr.sty -Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO) -) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/oberdiek/grfext.sty -Package: grfext 2016/05/16 v1.2 Manage graphics extensions (HO) - -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty -Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO) - -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/ltxcmds.sty -Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO) -))) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/oberdiek/kvoptions.sty -Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO) - -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty -Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO) - -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/etexcmds.sty -Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO) - -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/ifluatex.sty -Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO) -Package ifluatex Info: LuaTeX not detected. -) -Package etexcmds Info: Could not find \expanded. -(etexcmds) That can mean that you are not using pdfTeX 1.50 or -(etexcmds) that some package has redefined \expanded. -(etexcmds) In the latter case, load this package earlier. -))) -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty -Package: pdftexcmds 2018/01/30 v0.27 Utility functions of pdfTeX for LuaTeX (HO -) - -(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/ifpdf.sty -Package: ifpdf 2017/03/15 v3.2 Provides the ifpdf switch -) -Package pdftexcmds Info: LuaTeX not detected. -Package pdftexcmds Info: \pdf@primitive is available. -Package pdftexcmds Info: \pdf@ifprimitive is available. -Package pdftexcmds Info: \pdfdraftmode found. -) -Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4 -38. -Package grfext Info: Graphics extension search list: -(grfext) [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE -G,.JBIG2,.JB2,.eps] -(grfext) \AppendGraphicsExtensions on input line 456. - -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg -File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv -e -)) -LaTeX Font Info: External font `cmex10' loaded for size -(Font) <12> on input line 9. -LaTeX Font Info: External font `cmex10' loaded for size -(Font) <8> on input line 9. -LaTeX Font Info: External font `cmex10' loaded for size -(Font) <6> on input line 9. - (/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstlang1.sty -File: lstlang1.sty 2015/06/04 1.6 listings language file -) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstlang1.sty -File: lstlang1.sty 2015/06/04 1.6 listings language file -) -(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstmisc.sty -File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz) -) -(./fragment.glsl -LaTeX Font Info: Font shape `OT1/cmtt/bx/n' in size <10> not available -(Font) Font shape `OT1/cmtt/m/n' tried instead on input line 1. -) - -File: part1.png Graphic file (type png) - -Package pdftex.def Info: part1.png used on input line 20. -(pdftex.def) Requested size: 375.80544pt x 302.4527pt. - [1 - -{/usr/local/texlive/2018basic/texmf-var/fonts/map/pdftex/updmap/pdftex.map} <./ -part1.png>] - -File: part2.png Graphic file (type png) - -Package pdftex.def Info: part2.png used on input line 54. -(pdftex.def) Requested size: 375.80544pt x 302.4527pt. - [2 <./part2.png>] -Overfull \hbox (46.84398pt too wide) in paragraph at lines 90--92 -[][][][][][][][][][][][][][][][][][][][] - [] - - -Overfull \hbox (235.84361pt too wide) in paragraph at lines 101--103 -[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] - [] - -[3] -Overfull \hbox (21.64403pt too wide) in paragraph at lines 169--170 -[][][][][][][][][][][][][][][][][][][][][][][][][][][][] - [] - -[4] -Overfull \hbox (9.04405pt too wide) in paragraph at lines 174--175 -[][][][][][][][][][][][][][][][][][][][][][][][][][][][] - [] - -(./yellow.glsl) - -File: part4.png Graphic file (type png) - -Package pdftex.def Info: part4.png used on input line 199. -(pdftex.def) Requested size: 375.80544pt x 302.4527pt. - [5 <./part4.png>] (./report.aux) ) -Here is how much of TeX's memory you used: - 3356 strings out of 494091 - 46707 string characters out of 6163523 - 147119 words of memory out of 5000000 - 7005 multiletter control sequences out of 15000+600000 - 7448 words of font info for 27 fonts, out of 8000000 for 9000 - 319 hyphenation exceptions out of 8191 - 41i,6n,61p,275b,1582s stack positions out of 5000i,500n,10000p,200000b,80000s - -Output written on report.pdf (5 pages, 843858 bytes). -PDF statistics: - 47 PDF objects out of 1000 (max. 8388607) - 28 compressed objects within 1 object stream - 0 named destinations out of 1000 (max. 500000) - 16 words of extra memory for PDF output out of 10000 (max. 10000000) - diff --git a/report.pdf b/report.pdf deleted file mode 100644 index 151070b..0000000 Binary files a/report.pdf and /dev/null differ