├── .gitignore ├── Course description GT1 NHTV ├── Example implementation.txt ├── GT1-Prog Course Information.pdf ├── GT1-Prog Course Information.tex ├── PhD course description.txt ├── Staff information.pdf ├── Staff information.tex └── Testing criteria GT1.xlsm ├── License.md ├── Modulewijzer ├── Cijfers Wis8.xlsx ├── Modulewijzer WIS8.pdf ├── Modulewijzer WIS8.tex ├── build │ └── Modulewijzer WIS8.pdf ├── comptabel.pdf ├── img │ ├── comptabel.pdf │ └── logo.png ├── logo.jpg └── tex │ ├── AlgemeneOmschrijving.tex │ ├── Bijlage1.tex │ ├── Bijlage2.tex │ ├── Bijlage3.tex │ ├── Modulebeschrijving.tex │ ├── Programma.tex │ ├── Toetsing.tex │ ├── Voorblad.tex │ └── build │ └── Modulebeschrijving.pdf └── Slides ├── Lecture - missing pieces ├── Lecture - missing pieces.pdf ├── Lecture - missing pieces.tex └── nhtvslides.sty ├── Lecture 0 ├── Lecture 0.pdf ├── Lecture 0.tex └── nhtvslides.sty ├── Lecture 1 ├── Lecture 1.pdf ├── Lecture 1.tex ├── Pics │ ├── Fig2_15.PNG │ ├── Fig2_3.PNG │ └── Torque_animation.png └── nhtvslides.sty ├── Lecture 2 ├── Lecture 2.pdf ├── Lecture 2.tex ├── Pics │ ├── Fig1.PNG │ ├── Fig2.PNG │ ├── Fig3.PNG │ ├── Fig4.PNG │ ├── Fig5.PNG │ ├── Midpoint_method.png │ └── RK4.png └── nhtvslides.sty ├── Lecture 3 ├── Lecture 3.pdf ├── Lecture 3.tex ├── Pics │ └── Kill_me_please.png └── nhtvslides.sty ├── Lecture 4 ├── Lecture 4.pdf ├── Lecture 4.tex └── nhtvslides.sty ├── Lecture 5 ├── Lecture 5.pdf ├── Lecture 5.tex ├── Pics │ ├── ContactManifold.png │ ├── ConvexPolyhedra.png │ ├── ConvexPolyhedron.png │ ├── EdgeEdgeIntersection.png │ ├── EdgeToEdgeCross.png │ ├── EdgeToEdgeCross2.png │ ├── Fig6_19.PNG │ ├── Fig6_20.PNG │ ├── PlaneEdgeClipping.png │ ├── PlaneVertexClipping.png │ ├── ReferenceFace.png │ ├── ReferenceFaceSideways.png │ ├── Rel_Vel.png │ ├── ScaleOfSeparatingAxis.png │ ├── SeparatingAxesIn2D.PNG │ ├── SeparationOfVertex.PNG │ ├── Stacking.png │ └── TranslationOfSeparatingAxis.png └── nhtvslides.sty ├── Lecture 6 ├── Lecture 6.pdf ├── Lecture 6.tex ├── Pics │ ├── ContactConstraint.PNG │ ├── DistanceConstraint.PNG │ └── VirtualWork.png └── nhtvslides.sty ├── Lecture 7 ├── Lecture 7.pdf ├── Lecture 7.tex ├── Pics │ ├── MovingSpheres.png │ └── SpacePartitioning.PNG └── nhtvslides.sty ├── Lecture 8 ├── Lecture 8.pdf ├── Lecture 8.tex └── nhtvslides.sty └── Lecture 9 ├── Lecture 9.pdf ├── Lecture 9.tex ├── Pics ├── DeltaAngle.png ├── GearPlot.png ├── RotationRadius.png ├── SlipAngleCurve.png ├── SlipRatioCurve.png ├── SlipRatioCurveApprox.png └── WeightTransfer.png └── nhtvslides.sty /.gitignore: -------------------------------------------------------------------------------- 1 | ## Core latex/pdflatex auxiliary files: 2 | *.aux 3 | *.lof 4 | *.log 5 | *.lot 6 | *.fls 7 | *.out 8 | *.toc 9 | 10 | ## Intermediate documents: 11 | *.dvi 12 | *-converted-to.* 13 | # these rules might exclude image files for figures etc. 14 | # *.ps 15 | # *.eps 16 | # *.pdf 17 | 18 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 19 | *.bbl 20 | *.bcf 21 | *.blg 22 | *-blx.aux 23 | *-blx.bib 24 | *.brf 25 | *.run.xml 26 | 27 | ## Build tool auxiliary files: 28 | *.fdb_latexmk 29 | *.synctex 30 | *.synctex.gz 31 | *.synctex.gz(busy) 32 | *.pdfsync 33 | 34 | ## Auxiliary and intermediate files from other packages: 35 | 36 | # algorithms 37 | *.alg 38 | *.loa 39 | 40 | # achemso 41 | acs-*.bib 42 | 43 | # amsthm 44 | *.thm 45 | 46 | # beamer 47 | *.nav 48 | *.snm 49 | *.vrb 50 | 51 | #(e)ledmac/(e)ledpar 52 | *.end 53 | *.[1-9] 54 | *.[1-9][0-9] 55 | *.[1-9][0-9][0-9] 56 | *.[1-9]R 57 | *.[1-9][0-9]R 58 | *.[1-9][0-9][0-9]R 59 | *.eledsec[1-9] 60 | *.eledsec[1-9]R 61 | *.eledsec[1-9][0-9] 62 | *.eledsec[1-9][0-9]R 63 | *.eledsec[1-9][0-9][0-9] 64 | *.eledsec[1-9][0-9][0-9]R 65 | 66 | # glossaries 67 | *.acn 68 | *.acr 69 | *.glg 70 | *.glo 71 | *.gls 72 | 73 | # gnuplottex 74 | *-gnuplottex-* 75 | 76 | # hyperref 77 | *.brf 78 | 79 | # knitr 80 | *-concordance.tex 81 | *.tikz 82 | *-tikzDictionary 83 | 84 | # listings 85 | *.lol 86 | 87 | # makeidx 88 | *.idx 89 | *.ilg 90 | *.ind 91 | *.ist 92 | 93 | # minitoc 94 | *.maf 95 | *.mtc 96 | *.mtc0 97 | 98 | # minted 99 | _minted* 100 | *.pyg 101 | 102 | # morewrites 103 | *.mw 104 | 105 | # nomencl 106 | *.nlo 107 | 108 | # sagetex 109 | *.sagetex.sage 110 | *.sagetex.py 111 | *.sagetex.scmd 112 | 113 | # sympy 114 | *.sout 115 | *.sympy 116 | sympy-plots-for-*.tex/ 117 | 118 | # todonotes 119 | *.tdo 120 | 121 | # xindy 122 | *.xdy 123 | 124 | # WinEdt 125 | *.bak 126 | *.sav 127 | -------------------------------------------------------------------------------- /Course description GT1 NHTV/Example implementation.txt: -------------------------------------------------------------------------------- 1 | You can find example implementations of some of the assignments in the website 2 | 3 | https://casanova.codeplex.com/ 4 | 5 | under the tab 6 | 7 | DOWNLOADS 8 | 9 | Pick the archive named 10 | 11 | PHYSICS SAMPLES 12 | 13 | 14 | 15 | Remember to install OpenAL. The easiest (and recommended) way is to install the latest version of MonoGame, which sets up all the needed dependencies. 16 | -------------------------------------------------------------------------------- /Course description GT1 NHTV/GT1-Prog Course Information.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Course description GT1 NHTV/GT1-Prog Course Information.pdf -------------------------------------------------------------------------------- /Course description GT1 NHTV/GT1-Prog Course Information.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{listings} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage[T1]{fontenc} 6 | \usepackage[hyphens]{url} 7 | 8 | \begin{document} 9 | 10 | \textbf{Course name:} Physics 11 | 12 | \textbf{Course code:} GT1 (FGA2.GT1-03) 13 | 14 | \textbf{Academic year:} 2013-2014 15 | 16 | \textbf{Lecturer:} Giuseppe Maggiore 17 | 18 | \textbf{Number of EC's:} 4 19 | 20 | 21 | \section{Introduction} 22 | In this document we describe the \textit{Physics} course. 23 | 24 | The course aims at teaching how basic rigid body physics can be simulated in real-time on a modern computer. 25 | 26 | The objective is for students to be able to: \textit{(i)} intuitively understand the basic equations of rigid body physics; \textit{(ii)} know how to translate those equations into a working physics engine; and \textit{(iii)} know the trade-offs that a physics engine must chose between. 27 | 28 | At the end of the course the students will be able to program a simplified, robust, and general purpose physics engine. 29 | 30 | The course will require \textit{multiple assignments}, roughly one after each lecture or two. The various assignments build towards a working physics engine. Each assignment requires handing in two deliverables: \textit{(i)} a working program, its source, its compiled executable, and a video of the program running; \textit{(ii)} a written discussion and description of the implementation. The program is built \footnote{In either C++ (recommended) or C\# (acceptable)} in groups of two to three students, while the discussion is handed in (and written) by each student individually. 31 | 32 | 33 | \subsection{Relation to other courses} 34 | The course is related the preceding \textbf{Programming 1} through \textbf{4} courses, in that it requires students to be fluent with structured, higher level programming language such as C++. The course is also related with the \textbf{Mathematics 1} through \textbf{4} courses, in that it requires students to work with mathematical functions, derivatives, integrals, differential equations, numerical methods, trigonometry, and algebra. 35 | 36 | 37 | \subsection{Relation to the industry} 38 | In modern games, physics is not just an interesting addition; rather, it is a necessary component that is expected to work flawlessly. 39 | 40 | In order to be able to delivery correct-looking physics simulations in games, a practitioner needs to understand the underlying theoretical framework of rigid body (Newtonian) physics. Moreover, a physics engine developer must be aware of the mainstream techniques for performing (and optimizing) collision detection and also collision resolution through impulse computation in the presence of (multiple, simultaneous) constraints. 41 | 42 | Even in those cases when an existing, off-the-shelf physics engine is used, knowledge of the above topics is a requirement in order to be able to make an informed choice. 43 | 44 | Moreover, the computation of external forces to the bodies of a physics engine (whether custom or existing) are an extremely important aspect that needs to be modelled separately. Depending on the game setting, different forces will be at play: friction, Earth-surface-gravity, general gravity, Magnusson, tires on asphalt, wings on air, etc. Studying such forces is a requisite for being able to use a physics engine to build a domain specific physical simulation. 45 | 46 | 47 | \subsection{Competences} 48 | The course relates to competences \textbf{P3.Game Engine}, and \textbf{P4.Development with Resource Constraints}. 49 | 50 | 51 | \subsection{Course learning objectives} 52 | The learning objectives of this course are the following, marked with the corresponding voice of Bloom's Taxonomy: 53 | 54 | \begin{itemize} 55 | \item \textbf{Build} a basic kinematic simulator with RK2 or RK4. The simulator tracks position, velocity, rotation, angular rotation, mass, intertia tensor of arbitrary convex polytopes. \textbf{Understand} the difference in precision, stability, and performance of different integration methods. \textbf{Understand} numerical drift for rotation matrices and quaternions, and how to compensate through normalization. 56 | \item \textbf{Build} a system for SAT computation of arbitrary convex polytopes. \textbf{Understand} the various kinds of contact manifold determination, and build at least one. 57 | \item \textbf{Understand} how to reduce the number of expensive collision tests with broad-phase methods such as bounding spheres, bins, and axis algined bounding boxes (AABBs). \textbf{Build} AABBs collision detection with the method of overlapping intervals. \textbf{Understand} how to reduce the number of SAT tests by exploiting the symmetry of a convex polytope. 58 | \item \textbf{Understand} the Projected Gauss-Seidel method. \textbf{Build} an impulse-based collision response system for all pairs of objects simultaneously. 59 | \item \textbf{Understand} forces from various domains of physics: gravity, friction, springs, bullets, and cars. \textbf{Build} at least one of those into the simulation. 60 | \end{itemize} 61 | 62 | 63 | \section{Course structure} 64 | \subsection{Number of hours} 65 | 2 hours per week, contact time, and approximately 92 hours total study time. 66 | 67 | 68 | \subsection{Attendance policy} 69 | Attendance is not mandatory but students may miss valuable information if they do not attend the classes. 70 | 71 | 72 | \subsection{Teaching method} 73 | Traditional frontal lectures. 74 | 75 | 76 | \section{Assessment \& deadlines} 77 | The course has a series of assessments: \textit{(i)} a series of pieces that end up becoming a physics engine, each divided in a \textit{group assignment of coding} and an \textit{individual assignment of writing a report}. 78 | 79 | All assessments must qualify for a full pass (6+) in order for the course to pass. 80 | 81 | 82 | \subsection{Assignment: building a physics engine} 83 | This assignment requires groups \textbf{of up to four} students to write a C++ or C\# physics engine. This assignment is not graded directly, but only indirectly thorugh of assignment 2. 84 | 85 | The grading criteria will be: 86 | \begin{itemize} 87 | \item performance 30\% 88 | \item general purpose structure 30\% 89 | \item credibility/correctness of the physical simulation 30\% 90 | \item quality of the description document 10\% 91 | \end{itemize} 92 | 93 | The partial assignments are: 94 | \begin{itemize} 95 | \item Build a basic kinematic simulator with RK2 or RK4 (20\%) 96 | \item SAT/contact manifold computation (at least for OBBs, better for arbitrary meshes) (20\%) 97 | \item Collision culling with bounding spheres, AABBs, and bins (20\%) 98 | \item Collision response (20\%) 99 | \item Forces for domain-specific scenarios (20\%) 100 | \end{itemize} 101 | 102 | The partial assignments are due, alternatively: 103 | \begin{itemize} 104 | \item the end of the week after presentation in class (bonus $\times 1.1$), printed, with CD, in the lecturer's pigeon-hole 105 | \item at the end of the course, all together (no bonus); the deadline in this case is \textit{Friday of the exam week, at midnight} 106 | \end{itemize} 107 | 108 | 109 | 110 | \section{Materials} 111 | \subsection{Literature} 112 | The course will be based on: 113 | 114 | \begin{itemize} 115 | \item The book \textit{Game Physics - Second Edition}, by David Eberly 116 | \item The book \textit{Physics for game programmers}, by Grant Palmer 117 | \item The paper \textit{Iterative Dynamics with Temporal Coherence}, by Erin Catto 118 | \item The tutorial \textit{Car physics for games}, by Marco Monster 119 | \item The Siggraph '97 course notes \textit{An Introduction to Physically Based Modeling: Rigid Body Simulation I - Unconstrained Rigid Body Dynamics} by David Baraff 120 | \end{itemize} 121 | 122 | 123 | \subsection{Software packages} 124 | The course will make use of Visual Studio 2010 or newer, with any graphics library associated such as DirectX, OpenGL, XNA, MonoGame, etc. 125 | 126 | 127 | \section{Lecture topics} 128 | The lectures will cover the following topics, approximately one per lecture: 129 | 130 | \begin{itemize} 131 | \item \textbf{Topic 1 - basic concepts from physics}: translational and rotational Newtonian physics, numerical integration, equations of motion for a system of bodies 132 | \item \textbf{Topic 2 - narrow phase of collision detection}: separating axis, collision response 133 | \item \textbf{Topic 3 - broad phase of collision detection}: axis aligned bounding boxes, bounding spheres, etc. 134 | \item \textbf{Topic 4 - simultaneous resolution of multiple constraints}: constraints as a system of equations, the Gauss-Seidel method 135 | \item \textbf{Topic 5 - force computation}: ballistic forces (Magnusson, friction, gravity), car forces, plane forces, etc. \item \textbf{Optional topic 1 - preprocessing of models for collision detection} BSP for faster collision detection 136 | \item \textbf{Optional topic 2 - preprocessing of generic models} calculating the \textit{inertia tensor} of arbitrary polytopes 137 | \end{itemize} 138 | 139 | Topic 5, and the optional topics may not be entirely included in the lectures. Precedence will be given to correct assimilation of the previous topics, and the final schedule will also be dependent on the students response to the topics. 140 | 141 | \section{Conclusions} 142 | In this document we described the \textit{Physics} course. The course focuses on understanding basic physics, and learning how to build a basic physics engine for games. 143 | 144 | At the end of the course the students will be able to understand the structure of a physics engine, and will know how to build their own. 145 | 146 | \end{document} 147 | -------------------------------------------------------------------------------- /Course description GT1 NHTV/PhD course description.txt: -------------------------------------------------------------------------------- 1 | Program: The course aims at teaching how basic rigid body physics can be simulated in real-time on a modern computer. 2 | The objective is for students to be able to: (i) understand the basic equations of rigid body physics; (ii) know how to translate those equations into a working physics engine; and (iii) know the trade-offs that a physics engine must chose between. The topics covered are: 3 | - linear kinematics 4 | - rotational kinematics and momentum of inertia 5 | - numerical drift, differential equations, and matrix/quaternion normalization 6 | - separating axis test 7 | - clipping, edge/edge, edge/plane, vertex/plane intersections, and contact manifold generation 8 | - collision response with impulse-based methods through setting up and numerical solution of a system of linear equations 9 | - algorithms for the narrow phase of collision detection 10 | At the end of the course the students will be able to program a robust and general purpose physics engine. 11 | 12 | 13 | 14 | Number of hours: 14 hours of frontal lectures, approx. 70 hours of study time 15 | 16 | 17 | Final test: a prototype physics engine capable kinematics simulation, collision detection, and collision response. 18 | 19 | 20 | Level: PhD course 21 | -------------------------------------------------------------------------------- /Course description GT1 NHTV/Staff information.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Course description GT1 NHTV/Staff information.pdf -------------------------------------------------------------------------------- /Course description GT1 NHTV/Staff information.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{listings} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage[T1]{fontenc} 6 | \usepackage[hyphens]{url} 7 | \usepackage{hyperref} 8 | 9 | \begin{document} 10 | 11 | %\paragraph{2-Programming and Indie Staff information} 12 | 13 | \paragraph{Course code:} FGA2.GT1-03 (Physics) 14 | 15 | \paragraph{Academic year:} 2013-2014 16 | 17 | \paragraph{Lecturer:} Giuseppe Maggiore 18 | 19 | \paragraph{Contact info:} \href{mailto:maggiore.g@ade-nhtv.nl}{maggiore.g@ade-nhtv.nl} 20 | 21 | \paragraph{Appointment day:} Friday, all day, in the IGAD programming teachers' room (N1.308) at the main building 22 | 23 | 24 | \end{document} -------------------------------------------------------------------------------- /Course description GT1 NHTV/Testing criteria GT1.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Course description GT1 NHTV/Testing criteria GT1.xlsm -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Giuseppe Maggiore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Modulewijzer/Cijfers Wis8.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/Cijfers Wis8.xlsx -------------------------------------------------------------------------------- /Modulewijzer/Modulewijzer WIS8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/Modulewijzer WIS8.pdf -------------------------------------------------------------------------------- /Modulewijzer/Modulewijzer WIS8.tex: -------------------------------------------------------------------------------- 1 | \documentclass[titlepage, a4paper, openbib, 10pt]{article} 2 | 3 | %##################################### 4 | %Usepackages en installingen 5 | \usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry} 6 | \usepackage[pdftex]{graphicx} 7 | \usepackage{fancyhdr} 8 | \usepackage{paralist} 9 | \usepackage{sectionbox} 10 | \usepackage[dutch]{babel} 11 | \usepackage{chngcntr} 12 | \usepackage{cite} 13 | \usepackage{url} 14 | \usepackage{makeidx} 15 | \usepackage{enumitem} 16 | \usepackage{tocloft} 17 | \usepackage{listliketab} 18 | \usepackage[table]{xcolor} 19 | \usepackage{tabularx} 20 | \usepackage{epsfig} 21 | \usepackage{pdflscape} 22 | \usepackage{pdfpages} 23 | \usepackage{float} 24 | \usepackage{multirow} 25 | \usepackage{rotating} 26 | \usepackage[utf8]{inputenc} 27 | \usepackage{listings} 28 | \lstset{language=C, 29 | basicstyle=\ttfamily\footnotesize, 30 | frame=shadowbox, 31 | mathescape=true, 32 | showstringspaces=false, 33 | showspaces=false, 34 | breaklines=true} 35 | 36 | %\usepackage{showframe} %tmp 37 | %##################################### 38 | %Nieuwe commando's 39 | \newcommand{\HRule}{\rule{\linewidth}{1pt}} 40 | \newcommand{\organisatie}{\uppercase{Hogeschool Rotterdam / CMI}} 41 | \newcommand{\modulenaam}{Numerical approximation for physics simulations} 42 | \newcommand{\modulecode}{\uppercase{TINWIS01-8}} 43 | \newcommand{\stdPunten}{2 ects} 44 | \renewcommand{\author}{Gerard van Kruining, Giuseppe Maggiore} 45 | 46 | \definecolor{lichtGrijs}{RGB}{169,169,169} 47 | 48 | 49 | 50 | %##################################### 51 | %Index en styling 52 | \setlength{\cftbeforesecskip}{10pt} 53 | \setlength\parindent{0pt} 54 | \makeindex 55 | \graphicspath{{img}} 56 | \counterwithin{figure}{subsection} 57 | \pagestyle{fancy} 58 | \setcounter{secnumdepth}{5} 59 | \setcounter{tocdepth}{5} 60 | 61 | %##################################### 62 | % Alles voor header/footer 63 | \fancyhf[HL]{\nouppercase{\textit{\leftmark}}} 64 | \setlength{\headheight}{36pt} 65 | \lhead{\uppercase{\footnotesize Module guide}} 66 | \chead{\footnotesize \organisatie} 67 | \rhead{\includegraphics[width=0.09\textwidth]{img/logo}} 68 | 69 | \lfoot{\scriptsize \modulenaam} 70 | \cfoot{\scriptsize \today} 71 | \rfoot{\small \thepage} 72 | 73 | \renewcommand{\headrulewidth}{0.4pt} 74 | \renewcommand{\footrulewidth}{0.4pt} 75 | %##################################### 76 | 77 | \begin{document} 78 | 79 | %##################################### 80 | %Titlepage 81 | \begin{titlepage} 82 | \thispagestyle{fancy} 83 | \input{tex/Voorblad} 84 | \end{titlepage} 85 | 86 | %####### Contentpagina ######## 87 | %\renewcommand{\baselinestretch}{1.5}\normalsize 88 | %\tableofcontents 89 | %\newpage 90 | %\listoffigures 91 | %\newpage 92 | %\listoftables 93 | %\newpage 94 | 95 | %########### Inhoud ########### 96 | 97 | \shadowsectionbox 98 | \include{tex/Modulebeschrijving} 99 | \newpage 100 | \include{tex/AlgemeneOmschrijving} 101 | \newpage 102 | \include{tex/Programma} 103 | \newpage 104 | \include{tex/Toetsing} 105 | %############################## 106 | 107 | \newpage 108 | %\bibliographystyle{plain} 109 | %\bibliography{references} 110 | %\newpage 111 | \input{tex/Bijlage1} 112 | %\newpage 113 | %\input{tex/Bijlage2} 114 | %\newpage 115 | %\input{tex/Bijlage3} 116 | \printindex 117 | 118 | 119 | \end{document} 120 | -------------------------------------------------------------------------------- /Modulewijzer/build/Modulewijzer WIS8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/build/Modulewijzer WIS8.pdf -------------------------------------------------------------------------------- /Modulewijzer/comptabel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/comptabel.pdf -------------------------------------------------------------------------------- /Modulewijzer/img/comptabel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/img/comptabel.pdf -------------------------------------------------------------------------------- /Modulewijzer/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/img/logo.png -------------------------------------------------------------------------------- /Modulewijzer/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/logo.jpg -------------------------------------------------------------------------------- /Modulewijzer/tex/AlgemeneOmschrijving.tex: -------------------------------------------------------------------------------- 1 | \section{Algemene omschrijving} 2 | The overall goal of the course is to provide a detailed answer to the questions: 3 | \begin{itemize} 4 | \item what are the kinematics equations? 5 | \item how does a physical simulation work? 6 | \end{itemize} 7 | 8 | In this section we discuss further the full breadth of what the course covers, plus the desired level of skills achieved by the students. 9 | 10 | \subsection{Introduction} 11 | Simulation of the physical world is one of the most powerful fields of application of modern programming disciplines. Thanks to such simulations it is possible to set up virtual experiments, build virtual reality worlds, and many more modern complex applications. \\ 12 | 13 | Since analytical solutions are very rarely available, building such simulations requires the use of approximation techniques, which themselves are also applied to many other fields such as computer vision, artificial intelligence, and robotics. \\ 14 | 15 | The goal of the course is to provide a definition of the physical laws of kinematics, and of numerical approximations of complex dynamics. Moreover, we shall learn how to translate this knowledge into a working physical simulator. \\ 16 | 17 | \subsection{Relationship with other teaching units} 18 | This module builds over all modules of programming, and is also strongly connected with previous knowledge about mathematics, and linear algebra. \\ 19 | 20 | \subsection{Learning tools} 21 | Obligatory: 22 | \begin{itemize} 23 | \item Presentations and sources presented during lectures (found on N@tschool); 24 | \item Assignments to work on during practicums (found on N@tschool); 25 | \item Text editors: Emacs, Notepad++, Visual Studio, Xamarin Studio, etc. 26 | \end{itemize} 27 | Facultative: 28 | \begin{itemize} 29 | \item Book: Game Physics, author: David Eberly 30 | \item Book: Friendly F\# (Fun with game physics), authors: Giuseppe Maggiore, Marijn Tamis, Giulia Costantini 31 | \end{itemize} 32 | -------------------------------------------------------------------------------- /Modulewijzer/tex/Bijlage1.tex: -------------------------------------------------------------------------------- 1 | \section*{Appendix 1: Examination matrix} 2 | \begin{tabular}{|p{7cm}|p{3.5cm}|p{5cm}|} 3 | \hline 4 | Learning goal & Dublin descriptors & Assignments \\ 5 | \hline 6 | The student is able to distinguish the aspect of kinematics: linear and rotational motion, and associated forces 7 | & 1, 5 8 | & 1, 2 \\ 9 | \hline 10 | The student is able to give advice over the design and realisation of a kinematics simulation 11 | & 1, 3, 5 12 | & Documentation of all \\ 13 | \hline 14 | The student is able to design the structure and architecture of a kinematics simulation 15 | & 1, 3, 4 16 | & 1, 2 \\ 17 | \hline 18 | The student is able to realise a working kinematics simulation 19 | & 2 20 | & All \\ 21 | \hline 22 | The student is able to communicate in correct Dutch or English, using the correct jargon, about physics simulations and kinematics, etc. 23 | & 2 24 | & Documentation of all \\ 25 | \hline 26 | \end{tabular} 27 | 28 | \vspace{1cm} 29 | 30 | Dublin-descriptoren: 31 | \begin{enumerate} 32 | \item Knowledge and insight 33 | \item Application of knowledge and insight 34 | \item Making judgments 35 | \item Communication 36 | \item Learning skills 37 | \end{enumerate} 38 | 39 | -------------------------------------------------------------------------------- /Modulewijzer/tex/Bijlage2.tex: -------------------------------------------------------------------------------- 1 | \section*{Bijlage 2: Voorbeeldtoets} 2 | Dit hoofdstuk bevat de beschrijving van de procedures om voor beoordeling in aanmerking te komen.\\ Bijvoorbeeld voldoende aanwezigheid, 80\% van de opdrachten hebben ingeleverd, presentaties hebben verricht etc.\\ Verder wordt zo gedetailleerd mogelijk beschreven hoe er tot een cijfer wordt gekomen en welke rollen er door docenten en ander betrokkenen hierbij vervuld worden. \\ Geef een verantwoording van de toets; wat wordt getoetst, waarom is voor deze vorm gekozen.\\ Vul een toetsmatrijs in voor de toets (zie bijlage).\\ Beschrijf ook duidelijk de \textbf{herkansingsmogelijkheden}. \\ Neem in geval van een schriftelijk tentamen een voorbeeldtoets op als bijlage.\\ Geef daarbij per deelvraag het aantal te verdienen punten aan. \\ Bij een schriftelijk rapport. Geef de beoordelingscriteria aan met daarbij de mogelijke score en de onderlinge weging. \\ Toetsduur: \\ Hoe en wanneer krijgt de student feedback?\\ -------------------------------------------------------------------------------- /Modulewijzer/tex/Bijlage3.tex: -------------------------------------------------------------------------------- 1 | \section*{Bijlage 3: Studielast normering in ects} 2 | Dit hoofdstuk bevat de beschrijving van de procedures om voor beoordeling in aanmerking te komen.\\ Bijvoorbeeld voldoende aanwezigheid, 80\% van de opdrachten hebben ingeleverd, presentaties hebben verricht etc.\\ Verder wordt zo gedetailleerd mogelijk beschreven hoe er tot een cijfer wordt gekomen en welke rollen er door docenten en ander betrokkenen hierbij vervuld worden. \\ Geef een verantwoording van de toets; wat wordt getoetst, waarom is voor deze vorm gekozen.\\ Vul een toetsmatrijs in voor de toets (zie bijlage).\\ Beschrijf ook duidelijk de \textbf{herkansingsmogelijkheden}. \\ Neem in geval van een schriftelijk tentamen een voorbeeldtoets op als bijlage.\\ Geef daarbij per deelvraag het aantal te verdienen punten aan. \\ Bij een schriftelijk rapport. Geef de beoordelingscriteria aan met daarbij de mogelijke score en de onderlinge weging. \\ Toetsduur: \\ Hoe en wanneer krijgt de student feedback?\\ -------------------------------------------------------------------------------- /Modulewijzer/tex/Modulebeschrijving.tex: -------------------------------------------------------------------------------- 1 | \section*{Module description} 2 | \begin{tabularx}{\textwidth}{|>{\columncolor{lichtGrijs}} p{.26\textwidth}|X|} 3 | \hline 4 | \textbf{Module name:} & \modulenaam\\ 5 | \hline 6 | \textbf{Module code: }& \modulecode\\ 7 | \hline 8 | \textbf{Number of ECTS \newline and number of individual study hours:} & This module gives \stdPunten ECTS, which corresponds to 56 hours. 9 | \begin{itemize} 10 | \item 5 $\times$ 120 minutes frontal lecture 11 | \item 3 $\times$ 120 minutes practicum 12 | \item the rest is individual study 13 | \end{itemize} \\ 14 | \hline 15 | \textbf{Examination:} & Practical assignments \\ 16 | \hline 17 | \textbf{Course structure:} & Lectures and practicums \\ 18 | \hline 19 | \textbf{Required knowledge:} & All programming course, linear algebra. \\ 20 | \hline 21 | \textbf{Learning tools:} & 22 | \begin{itemize} 23 | \item Book: Game Physics, author: David Eberly 24 | \item Book: Friendly F\# (Fun with game physics), authors: Giuseppe Maggiore, Marijn Tamis, Giulia Costantini 25 | \item Text editors: Emacs, Notepad++, Visual Studio, Xamarin Studio, etc. 26 | \end{itemize} \\ 27 | \hline 28 | \textbf{Connects to \newline competencies :} & 29 | \begin{center} 30 | \includegraphics[width=7cm]{img/comptabel.pdf} 31 | \end{center}\\ 32 | \hline 33 | \end{tabularx} 34 | \newpage 35 | 36 | \begin{tabularx}{\textwidth}{|>{\columncolor{lichtGrijs}} p{.26\textwidth}|X|} 37 | \hline 38 | \textbf{Overall learning goal:}& 39 | The student is able to describe, define, and then implement numerical approximation techniques to physics simulations. \\ 40 | \hline 41 | \textbf{Detailed learning goals:}& 42 | \begin{itemize} 43 | \item The student is able to distinguish the aspect of kinematics: linear and rotational motion, and associated forces (learning goal \textit{analysis}); 44 | \item The student is able to give advice over the design and realisation of a kinematics simulation (learning goal \textit{advice}); 45 | \item The student is able to design the structure and architecture of a kinematics simulation (learning goal \textit{design}); 46 | \item The student is able to realise a working kinematics simulation (learning goal \textit{realisation}); 47 | \item The student is able to communicate in correct Dutch or English, using the correct jargon, about physics simulations and kinematics, etc. (learning goal \textit{communication}). 48 | \end{itemize} 49 | \ \\ 50 | \hline 51 | \textbf{Module responsible:} & \author\\ 52 | \hline 53 | \textbf{Date:} & \today \\ 54 | \hline 55 | \end{tabularx} 56 | \newpage 57 | -------------------------------------------------------------------------------- /Modulewijzer/tex/Programma.tex: -------------------------------------------------------------------------------- 1 | \section{Content} 2 | \paragraph*{Structure of lectures} 3 | The lectures are an adaptation of traditional frontal lectures. In order to improve attention and retention, the following interactive elements are also used: 4 | \begin{inparaenum}[\itshape i\upshape)] 5 | \item questions and quizzes to the class, followed by discussion; 6 | \item short group assignments, followed by discussion. 7 | \end{inparaenum} 8 | 9 | 10 | \paragraph*{List of topics} 11 | The following is a comprehensive and detailed list of the program of the course: 12 | \begin{enumerate} 13 | \item Linear motion 14 | \item Rotational motion 15 | \item Linear acceleration 16 | \item Rotational acceleration 17 | \item Inertia tensor 18 | \item Euler integration 19 | \item Runge-Kutta integration 20 | \item Quaternions 21 | \item Time-derivative of matrices 22 | \item Time-derivative of quaternions 23 | \end{enumerate} 24 | \ \\ 25 | 26 | -------------------------------------------------------------------------------- /Modulewijzer/tex/Toetsing.tex: -------------------------------------------------------------------------------- 1 | \section{Testing and evaluation} 2 | In this section we discuss the testing procedure of this course, and the grading criteria. 3 | 4 | \subsection{Overall description} 5 | 6 | This module is tested with a series of practical assignments. These assignments can be found on N@tschool. \\ 7 | 8 | Foreword and notes: 9 | \begin{itemize} 10 | \item The practical assignments determine the final grade. 11 | \item The practical assignments are made up of elements of an interpreter or a compiler which is either incomplete or wrongly built. The students task is that of extending or fixing such elements. 12 | \item The practical assignments can be made in pairs. 13 | \item The practical assignments must contain extensive, individually written documentation. 14 | \end{itemize} 15 | \ \\ 16 | 17 | This manner of examination is chosen for the following reasons: 18 | \begin{itemize} 19 | \item By reading existing sources students must read and reason about code (learning goals \textit{analysis} and \textit{advice}). 20 | \item By correcting or extending the sources students must write code (learning goals \textit{design} and \textit{realisation}). 21 | \item By writing documentation students must communicate about their code (learning goal \textit{communication}). 22 | \end{itemize} 23 | 24 | \ \\ 25 | The grade of each practicum assignment is determined by: 26 | \begin{itemize} 27 | \item The correctness of the underlying physical and approximation rules (60\%). 28 | \item Completeness and clarity of the documentation (40\%). 29 | \end{itemize} 30 | 31 | \subsection{Assignments} 32 | 33 | \paragraph{Assignment 1 - linear motion} 34 | Students must define an Euler-integrated simulation over position, velocity (or linear momentum) and force. 35 | 36 | \paragraph{Assignment 2 - rotational motion} 37 | Students must define an Euler-integrated simulation over rotation, angular velocity (or angular momentum) and torque. 38 | 39 | \paragraph{Assignment 2B - Gram-Schmidt ortho-normalization} 40 | Students must define a Gram-Schmidt ortho-normalization. 41 | 42 | \paragraph{Assignment 2C - quaternions} 43 | Students must replace rotation matrices with quaternions. 44 | 45 | \paragraph{Assignment 3 - Runge-Kutta integration} 46 | Students must replace the Euler integration with a Runge-Kutta integration of order 4. 47 | 48 | \subsection{Grades} 49 | Assignments 1, 2, and 3 are obligatory. With these assignments the maximum grade possible is a seven. The other assignments are all optional and give each one and a half additional point. 50 | 51 | \begin{tabularx}{\textwidth}{|>{\columncolor{lichtGrijs}} p{3cm}|X|} 52 | \hline 53 | \textbf{Assignments:} & \textbf{Value in grades} \\ 54 | \hline 55 | 1, 2, 3 & 7 \\ 56 | \hline 57 | 2B & 1.5 \\ 58 | \hline 59 | 2C & 1.5 \\ 60 | \hline 61 | \end{tabularx} 62 | 63 | 64 | \subsection{Deadlines} 65 | The assignments must be handed in, printed on paper, before the end of the last lecture on week 8 of the period. \textit{Herkansing} can be done by handing in the assignments before the end of week 1 of the following period (that would be right after the summer holiday). 66 | 67 | \subsection{Feedback} 68 | It is possible to discuss the assignments (and their evaluation) during the practicum lectures, or during week 10 of the period (the same holds for the \textit{herkansing}, but in reference to the following period). 69 | -------------------------------------------------------------------------------- /Modulewijzer/tex/Voorblad.tex: -------------------------------------------------------------------------------- 1 | \ 2 | \vspace{5cm} 3 | 4 | \begin{center} 5 | 6 | 7 | \Large \textbf \organisatie 8 | 9 | \vspace{1.5cm} 10 | 11 | \HRule \\[0.4cm] 12 | 13 | \Huge \textbf \modulenaam 14 | 15 | \vspace{1.7cm} 16 | 17 | \Large \textbf \modulecode 18 | 19 | \vspace{0.4cm} 20 | 21 | \HRule \\[1.5cm] 22 | \end{center} 23 | \vfill 24 | 25 | % Author and supervisor 26 | \begin{tabular}{l l} 27 | ECTS: & \stdPunten\\ 28 | Module responsible: & \author\\ 29 | \end{tabular} 30 | -------------------------------------------------------------------------------- /Modulewijzer/tex/build/Modulebeschrijving.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Modulewijzer/tex/build/Modulebeschrijving.pdf -------------------------------------------------------------------------------- /Slides/Lecture - missing pieces/Lecture - missing pieces.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture - missing pieces/Lecture - missing pieces.pdf -------------------------------------------------------------------------------- /Slides/Lecture - missing pieces/Lecture - missing pieces.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Missing pieces} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{slide}{An actual physics engine?}{Points of difference}{ 25 | \item How far are we from an actual, commercial engine? 26 | \item Turns out, not very 27 | \item There are some topics we did not touch 28 | \item Some others that we did not deepen enough 29 | \item All in all, what you have seen so far is the hard core of a physics engine 30 | }\end{slide} 31 | 32 | \begin{slide}{An actual physics engine?}{Points of difference}{ 33 | \item GJK vs SAT 34 | \pause 35 | \item Constant rotational velocity 36 | \pause 37 | \item SAT with BSP for the meshes 38 | \pause 39 | \item Inertia tensor derivation 40 | \begin{itemize} 41 | \item For known shapes 42 | \item For arbitrary meshes 43 | \end{itemize} 44 | \pause 45 | \item Inverse kinematics 46 | \begin{itemize} 47 | \item Standalone 48 | \item Within the collision response system 49 | \end{itemize} 50 | }\end{slide} 51 | 52 | \begin{frame}{That's it} 53 | \begin{block}{\center The course is over} 54 | \center 55 | \fontsize{18pt}{7.2}\selectfont 56 | Thank you! 57 | \end{block} 58 | \end{frame} 59 | 60 | \end{document} 61 | 62 | 63 | \begin{slide}{SECTION}{SLIDE}{ 64 | \item i 65 | }\end{slide} 66 | 67 | \begin{frame}[fragile]{SLIDE} 68 | \begin{lstlisting} 69 | CODE 70 | \end{lstlisting} 71 | \end{frame} 72 | 73 | \begin{frame}{SLIDE} 74 | \center 75 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 76 | \end{frame} 77 | -------------------------------------------------------------------------------- /Slides/Lecture - missing pieces/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 0/Lecture 0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 0/Lecture 0.pdf -------------------------------------------------------------------------------- /Slides/Lecture 0/Lecture 0.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Syllabus} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{slide}{Syllabus}{List of topics}{ 25 | \item \textbf{Topic 1 - basic concepts from physics}: translational and rotational Newtonian physics, numerical integration, equations of motion for a system of bodies 26 | \item \textbf{Topic 2 - narrow phase of collision detection}: separating axis, collision response 27 | \item \textbf{Topic 3 - broad phase of collision detection}: axis aligned bounding boxes, bounding spheres, etc. 28 | \item \textbf{Topic 4 - simultaneous resolution of multiple constraints}: constraints as a system of equations, the Gauss-Seidel method 29 | \item \textbf{Topic 5 - force computation}: ballistic forces (Magnusson, friction, gravity), car forces, plane forces, etc. 30 | }\end{slide} 31 | 32 | \begin{slide}{Syllabus}{List of topics}{ 33 | \item \textbf{Optional topic 1 - preprocessing of models for collision detection} BSP for faster collision detection 34 | \item \textbf{Optional topic 2 - preprocessing of generic models} calculating the \textit{inertia tensor} of arbitrary polytopes 35 | }\end{slide} 36 | 37 | \begin{slide}{Syllabus}{List of materials}{ 38 | \item The book \textit{Game Physics - Second Edition}, by David Eberly 39 | \item The book \textit{Physics for game programmers}, by Grant Palmer 40 | \item The paper \textit{Iterative Dynamics with Temporal Coherence}, by Erin Catto 41 | \item The tutorial \textit{Car physics for games}, by Marco Monster 42 | \item The Siggraph '97 course notes \textit{An Introduction to Physically Based Modeling: Rigid Body Simulation I - Unconstrained Rigid Body Dynamics} by David Baraff 43 | }\end{slide} 44 | 45 | \begin{slide}{Syllabus}{Assignments}{ 46 | \item Due 47 | \begin{itemize} 48 | \item The end of the week after presentation in class (possible time bonus) 49 | \item All together at the end of the course 50 | \end{itemize} 51 | \item Group work for coding (max three students) 52 | \item Individual work for the report (what will actually be graded) 53 | }\end{slide} 54 | 55 | \begin{slide}{Syllabus}{List of assignments}{ 56 | \item Build a basic kinematic simulator with RK2 or RK4 (20\%) 57 | \item SAT/contact manifold computation (at least for OBBs, better for arbitrary meshes) (20\%) 58 | \item Collision culling with bounding spheres, AABBs, and bins (20\%) 59 | \item Collision response (20\%) 60 | \item Forces for domain-specific scenarios (20\%) 61 | }\end{slide} 62 | 63 | \begin{frame}{That's it} 64 | \center 65 | \fontsize{18pt}{7.2}\selectfont 66 | Thank you! 67 | \end{frame} 68 | 69 | \end{document} 70 | 71 | 72 | \begin{slide}{SECTION}{SLIDE}{ 73 | \item i 74 | }\end{slide} 75 | 76 | \begin{frame}[fragile]{SLIDE} 77 | \begin{lstlisting} 78 | CODE 79 | \end{lstlisting} 80 | \end{frame} 81 | 82 | \begin{frame}{SLIDE} 83 | \center 84 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 85 | \end{frame} 86 | -------------------------------------------------------------------------------- /Slides/Lecture 0/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 1/Lecture 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 1/Lecture 1.pdf -------------------------------------------------------------------------------- /Slides/Lecture 1/Lecture 1.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Basic concepts from physics} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{frame}{Table of contents} 25 | \tableofcontents 26 | \end{frame} 27 | 28 | \section{Body kinematics} 29 | \begin{slide}{Introduction}{Kinematics}{ 30 | \item Study of motion 31 | \item \textit{Position}, \textit{Velocity}, and \textit{Acceleration} 32 | \item \textit{Rotation}, \textit{Angular velocity}, and \textit{Torque} 33 | \item Cartesian coordinates in 2D and in 3D 34 | }\end{slide} 35 | 36 | \begin{slide}{Introduction}{Forces}{ 37 | \item Newton's laws of motion 38 | }\end{slide} 39 | 40 | \begin{slide}{Introduction}{Momenta}{ 41 | \item Linear momentum 42 | \item Angular momentum 43 | }\end{slide} 44 | 45 | \begin{slide}{Introduction}{Angular momentum}{ 46 | \item Center of mass 47 | \item Inertia tensor 48 | \item Torque 49 | }\end{slide} 50 | 51 | \begin{slide}{Particle kinematics}{XY particle}{ 52 | \item We start with a particle moving across the $xy$ plane 53 | \item Position at time $t$ is $r(t) = (x(t),y(t))$ %x(t)\iota + y(t)\jmath$ where $\iota=(1,0), \jmath=(0,1)$ 54 | %\begin{itemize} 55 | %\item (or $(x(t),y(t))$ in tupled version) 56 | %\end{itemize} 57 | }\end{slide} 58 | 59 | \begin{slide}{Particle kinematics}{XY particle}{ 60 | \item Velocity at time $t$ is $v(t) = \dot r = (\dot x,\dot y)$ \footnote{a dot above denotes derivation over time; this means that $\dot x = \frac{dx}{dt}$} 61 | \item Speed is $|v|$ 62 | \item Acceleration is $a(t) = \dot v = \ddot r = (\ddot x, \ddot y)$ 63 | }\end{slide} 64 | 65 | \begin{slide}{Particle kinematics}{XY particle}{ 66 | \item Tangent is $T(t) = \frac{v}{|v|}$ % = (\cos(\phi(t)),\sin(\phi(t)))$ \footnote{$\phi = atan \frac{v_y}{v_x}$} 67 | \item Normal is $N(t)$ and is perpendicular to $T$ % = (-\sin(\phi(t)),\cos(\phi(t)))$ 68 | \item $r,T,N$ is the \textit{moving frame} of the particle (or body space, or local space) 69 | }\end{slide} 70 | 71 | \begin{slide}{Particle kinematics}{XY particle motion with respect to frame}{ 72 | \item $v = |v|T = \dot s T$ 73 | \item $a = \dot v =$ % \frac{d}{dt}(\dot s T) = \ddot s T + \dot s \frac{dT}{dt} = \ddot s T + \dot s^2 \frac{dT}{ds}$ \footnote{The last step is obtained by multiplying by $\frac{ds}{dt}\frac{dt}{ds}$} 74 | %\item Since $\frac{dT}{ds} = \frac{d\phi}{ds}N$, the acceleration is therefore $a = \ddot s T + \dot s^2 \frac{d\phi}{ds}N$ 75 | %\begin{itemize} 76 | %\item $\ddot s T$ is the \textit{tangential acceleration} 77 | %\item $\dot s^2 \frac{d\phi}{ds}N$ is the \textit{centripetal} (\textit{normal}) acceleration perpendicular to the direction of motion 78 | %\end{itemize} 79 | }\end{slide} 80 | 81 | \begin{slide}{Particle kinematics}{XYZ particle}{ 82 | \item We now consider a particle moving in space 83 | \item Position at time $t$ is $r(t) = (x(t),y(t),z(t))$ %where $\iota=(1,0,0), \jmath=(0,1,0), \ell=(0,0,1)$ 84 | %\begin{itemize} 85 | %\item (or $(x(t),y(t),z(t))$ in tupled version) 86 | %\end{itemize} 87 | }\end{slide} 88 | 89 | \begin{slide}{Particle kinematics}{XYZ particle}{ 90 | \item Velocity at time $t$ is $v(t) = \dot r = (\dot x, \dot y, \dot z)$ 91 | \item Speed is $|v|$ 92 | \item Acceleration is $a(t) = \dot v = \ddot r = (\ddot x, \ddot y, \ddot z)$ 93 | }\end{slide} 94 | 95 | \begin{slide}{Particle kinematics}{XYZ particle}{ 96 | \item Tangent is $T(t) = \frac{v}{|v|}$ 97 | \item We have an infinite set of possible vectors normal to $T$ 98 | }\end{slide} 99 | 100 | \begin{frame}{SLIDE} 101 | \center 102 | \includegraphics[width=5cm]{Pics/Fig2_3.png} 103 | \end{frame} 104 | 105 | \begin{slide}{Particle kinematics}{XYZ particle}{ 106 | \item Normal $N$ is perpendicular to $T$ 107 | \item We are missing an axis to have a complete frame 108 | \item Binormal is $B = T \times N$ 109 | %\begin{itemize} 110 | %\item $\frac{dB}{ds} = -\tau N$ 111 | %\item $\tau$ is the \textit{torsion} of the curve 112 | %\item tendency of the curve to bend out of the $TN$ plane 113 | %\end{itemize} 114 | \item $r,T,N,B$ is the \textit{moving frame} of the particle (or body space, or local space) 115 | }\end{slide} 116 | 117 | \begin{slide}{Body kinematics}{Rigid body}{ 118 | \item $R = \left[ T\ N\ B \right] $ put in matrix form ($T, N, B$ are used as \textit{columns} of the matrix) is the \textit{rotation matrix} of the body 119 | \item $r(t) = R(t)r_0 + x(t)$ where $x(t)$ is the position of the \textit{center} of the body 120 | \item $\omega(t)$, a vector, is the angular velocity of the body 121 | \begin{itemize} 122 | \item Its direction $\frac{\omega(t)}{|\omega(t)|}$ is the rotation axis 123 | \item Its magnitude $|\omega(t)|$ is in $rad/s$ 124 | \end{itemize} 125 | }\end{slide} 126 | 127 | \begin{slide}{Particle kinematics}{Rigid body rotation}{ 128 | \item We need to study $\dot r(t)$, in order to determine $\dot R$ 129 | \item We decompose $r(t)$ into $a,b$ where $a$ is parallel to $\omega$ and $b$ is perpendicular 130 | \begin{itemize} 131 | \item linearly moving component 132 | \item rotating component 133 | \end{itemize} 134 | \item The instantaneous velocity of $r(t)$ is $\dot r = \omega(t) \times b = \omega(t) \times (a+b) = \omega(t) \times r(t)$ 135 | }\end{slide} 136 | 137 | % PIC 138 | 139 | \begin{slide}{Particle kinematics}{Rigid body rotation}{ 140 | \item We now consider the inertial frames, which are the columns of the rotation matrix 141 | \item We compute $\dot T = \omega(t) \times T$, $\dot N = \omega(t) \times N$, and $\dot B = \omega(t) \times B$ 142 | \item These are the velocities of the axes of the inertial frame 143 | \item Also known as the columns of $\dot R$ 144 | }\end{slide} 145 | 146 | \section{Newton's laws} 147 | \begin{slide}{Newton's laws}{Topic}{ 148 | \item Inertia, the tendency of an object to remain in motion 149 | \item Force, the mechanism through which inertia is changed 150 | }\end{slide} 151 | 152 | %\begin{textslide}{Newton's laws}{First law}{ 153 | %In the absence of external forces, an object at rest will remain at rest. If the object is in motion and no external forces act on it, the object remains in motion with constant velocity. (Only forces can change an object’s motion.) 154 | %}\end{textslide} 155 | 156 | %\begin{textslide}{Newton's laws}{Second law}{ 157 | %For an object of constant mass over time, its acceleration a is proportional to the force $F$ and inversely proportional to the mass $m$ of the object: $a=\frac{F}{m}$. We normally see this written as $F=ma$. If the mass changes over time, the more general statement of the law is $F=\frac{d}{dt}(mv) + \frac{dm}{dt}v$, where $v$ is the velocity of the object. The quantity $mv$ is the linear momentum of the object. Thus, the second law states that the application of an external force on an object causes a change in the object's momentum over time. (An object's path of motion is determined from the applied forces.) 158 | %}\end{textslide} 159 | 160 | %\begin{textslide}{Newton's laws}{Third law}{ 161 | %If a force is exerted on one object, there is a force of equal magnitude but opposite direction on some other body that interacts with it. (Action and reaction always occur between interacting objects.) 162 | %}\end{textslide} 163 | 164 | \begin{slide}{Newton's laws}{About the laws}{ 165 | \item The \textbf{second law} is the one we work the most with 166 | \item Mass is assumed to be always constant, so $F=\frac{d}{dt}(mv) = m\frac{d}{dt}v = ma$ 167 | \item Each of the vector quantities of position, velocity, and acceleration is measured with respect to some arbitrary but fixed coordinate system, referred to as the \textit{inertial frame}, or global space 168 | }\end{slide} 169 | 170 | \section{Torque} 171 | \begin{slide}{Torque}{From force to torque}{ 172 | \item Removing log nuts with a wrench 173 | \item Exert a force on the end of the wrench, the nut turns 174 | \item The longer the wrench, the easier (but slower) the nut turns 175 | }\end{slide} 176 | 177 | \begin{frame}{SLIDE} 178 | \center 179 | \includegraphics[width=4cm]{Pics/Torque_animation.png} 180 | \end{frame} 181 | 182 | \begin{slide}{Torque}{Definition}{ 183 | \item The \textit{ease} of turning is proportional to the length of the wrench and the force applied 184 | \item This product is referred to as \textit{torque} or \textit{moment of force} 185 | \item Torque is defined as $\tau = r \times F$ 186 | \begin{itemize} 187 | \item Direction of torque is axis (and direction) of rotation 188 | \item Length of torque is in $rad/s$ 189 | \end{itemize} 190 | }\end{slide} 191 | 192 | \begin{slide}{Torque}{Multiple torques}{ 193 | \item Multiple torques (just like forces) are simply added together 194 | \item $\tau = \sum_i r_i \times F_i$ (discrete body) or $\tau = \int r \times F dr$ (continuous body) 195 | }\end{slide} 196 | 197 | \section{Momenta} 198 | \begin{slide}{Momenta}{Momenta}{ 199 | \item Quantification of Newton's \textbf{Second Law} 200 | \item How much \textit{motion} does the body have? 201 | \begin{itemize} 202 | \item \textbf{A lot} means that a lot of force is needed to change it 203 | \item \textbf{Little} means that little force is needed to change it 204 | \end{itemize} 205 | }\end{slide} 206 | 207 | \begin{slide}{Momenta}{Linear momentum}{ 208 | \item How much linear \textit{motion} does the body have? 209 | \item $p=mv=\sum_i m_i v_i=\int_R v\ dm$ 210 | %\item Linear momentum is conserved in a system 211 | %\begin{itemize} 212 | %\item W.r.t. all bodies $\frac{dP}{dt} = 0$ 213 | %\end{itemize} 214 | \item Force integrates linear momentum directly 215 | \item $\frac{dp}{dt} = \frac{d(mv)}{dt} = m \frac{dv}{dt} = ma = F$ 216 | }\end{slide} 217 | 218 | \begin{slide}{Momenta}{Angular momentum}{ 219 | \item How much rotational \textit{motion} does the body have? 220 | \item $L=r \times p=m r \times v$ 221 | \item Right-hand rule of cross-product: 222 | \begin{itemize} 223 | \item Angular momentum refers to the tendency of the body to rotate around a given axis, $L$ 224 | \item The longer the axis, the harder it is to stop the rotation 225 | \end{itemize} 226 | }\end{slide} 227 | 228 | %\begin{slide}{Momenta}{Angular momentum}{ 229 | %\item $L=\sum_i m_i r_i \times v_i=\int_R r \times v dm$ 230 | %\item Angular momentum is conserved in a system 231 | %\begin{itemize} 232 | %\item w.r.t. all bodies $\frac{dL}{dt} = 0$ 233 | %\end{itemize} 234 | %}\end{slide} 235 | 236 | \begin{slide}{Momenta}{Angular momentum}{ 237 | \item Just like the derivative of linear momentum is force... 238 | \item ...angular momentum derived yields torque (when the body does not change shape) 239 | \item $\frac{dL}{dp} = \tau$ 240 | %\begin{eqnarray} 241 | %\frac{dL}{dp} &=& \frac{d r \times p}{dt} \\ 242 | %&=& r \times \frac{dp}{dt} + \frac{dr}{dt} \times p \\ 243 | %&\circeq& r \times F \\ 244 | %&=& \tau 245 | %\end{eqnarray} 246 | }\end{slide} 247 | 248 | \section{Center of mass} 249 | \begin{slide}{Center of mass}{Tracking particles?}{ 250 | \item Do we really need to track all the particles of a rigid body? 251 | \item No! 252 | \begin{itemize} 253 | \item Too slow 254 | \item \textit{Center} of mass 255 | \item Properties of the motion \textit{of the whole body} 256 | \item Rigid body behaves as if all the mass were concentrated at a single point 257 | \end{itemize} 258 | \item We compute the center of mass by a weighted average of the body particles relative positions and their respective masses 259 | %\begin{itemize} 260 | %\item $\sum_i m_i g (x_i - \bar x) = 0$ 261 | %\end{itemize} 262 | }\end{slide} 263 | 264 | \begin{slide}{Center of mass}{One dimension}{ 265 | \item A wooden plank with two \textit{weights} at the extremes 266 | \item Center of mass is $\bar x = \frac{m_1 x_1 + m_2 x_2}{m_1 + m_2} = x_1 \frac{m_1}{m_1+m_2} + x_2 \frac{m_2}{m_1+m_2}$ 267 | }\end{slide} 268 | 269 | \begin{frame}{SLIDE} 270 | \center 271 | \includegraphics[width=5cm]{Pics/Fig2_15.png} 272 | \end{frame} 273 | 274 | %\begin{slide}{Center of mass}{One dimension}{ 275 | %\item Multiple \textit{weights} along the plank 276 | %\item Center of mass \footnote{From now on, $M = \sum_i m_i$} is $\bar x = \frac{\sum_i m_i x_i}{M}$ 277 | %\pause 278 | %\item For a continuous mass, replace summation with integral 279 | %\item $\bar x = \frac{\int_l x \delta(x) dx}{\int_l delta(x) dx}$ 280 | %}\end{slide} 281 | 282 | \begin{slide}{Center of mass}{Two dimensions}{ 283 | \item Center of mass is $\bar x = \frac{\sum_i m_i x_i}{M}$, where $x_i$ is a 2D vector \footnote{Component-wise, the result is $(\bar x,\bar y) = (\frac{\sum_i m_i x_i}{M},\frac{\sum_i m_i y_i}{M})$} 284 | %\pause 285 | %\item For a continuous mass, replace summation with integral 286 | %\item $\bar x = \frac{\int_l x \delta(x) dx}{\int_l delta(x) dx}$ 287 | }\end{slide} 288 | 289 | \begin{slide}{Center of mass}{Three dimensions}{ 290 | \item Center of mass is $\bar x = \frac{\sum_i m_i x_i}{M}$, where $x_i$ is a 3D vector 291 | %\pause 292 | %\item For a continuous mass, replace summation with integral 293 | %\item $\bar x = \frac{\int_l x \delta(x) dx}{\int_l delta(x) dx}$ 294 | }\end{slide} 295 | 296 | \begin{slide}{Center of mass}{Force projection}{ 297 | \item When an external force $F_{\text{ext}}$ is applied to a body from some position, $r_f$ 298 | \item We use the center of mass to split the force between linear and torque 299 | \item $F = F_{\text{ext}} \cdot \frac{(r_f - \bar x)}{|(r_f - \bar x)|}$, $\tau = F_{\text{ext}} \times (r_f - \bar x)$ 300 | }\end{slide} 301 | 302 | \section{Moments of inertia} 303 | \begin{slide}{Moments of inertia}{Moments of inertia}{ 304 | \item \textit{How difficult is it to set an object into rotation around an axis?} 305 | \item Rotational equivalent to mass for linear movement 306 | }\end{slide} 307 | 308 | %\begin{slide}{Moments of inertia}{Moment of inertia in 1D}{ 309 | %\item The more a particle weighs, or the further from the center, the harder to set the object into rotation 310 | %\item For the whole body we sum the contributions of each particle: $I = \sum_i m_i (x_i - \bar x)^2 = \sum_i m_i x_i^2 - m \bar x^2$ 311 | %}\end{slide} 312 | 313 | \begin{slide}{Moments of inertia}{Moment of inertia in 2D}{ 314 | \item A single number, because in 2D we can only rotate in one plane 315 | \item $I = \sum_i m_i |(x_i,y_i) - (\bar x, \bar y)| ^2 = \sum_i m_i (x_i^2 + y_i^2) - m(\bar x^2, \bar y^2)$ 316 | }\end{slide} 317 | 318 | \begin{slide}{Moments of inertia}{Moment of inertia in 3D}{ 319 | \item Harder to express, because suddenly we can rotate along an infinite number of axes 320 | \item Let us engineer this from the angular momentum of a particle of the body 321 | \item Consider a particle 322 | \begin{itemize} 323 | \item Located at relative vector $r$ 324 | \item Moving with linear velocity $v = \omega \times r$ 325 | \end{itemize} 326 | }\end{slide} 327 | 328 | \begin{slide}{Moments of inertia}{Mass matrix in 3D}{ 329 | \item $L_i = r_i \times m_i v_i = m_i r_i \times (\omega \times r_i) = J\omega$ 330 | \item $J_i = m_i \left[ \begin{matrix} 331 | y_i^2 + z_i^2 & -x_iy_i & -x_iz_i \\ 332 | -x_iy_i & x_i^2 + z_i^2 & -y_iz_i \\ 333 | -x_iz_i & -y_iz_i & y_i^2 + z_i^2 \\ 334 | \end{matrix} \right] $ 335 | \item $L_i = J_i\omega$, just like $P = mv$ 336 | \item For the whole body, we sum all the $J_i$ matrices of the particles 337 | \item $J = \sum_i J_i$, $L = J \omega$ 338 | \item $J$ must be recalculated from the rotated body, because $r_i = R r_0 + \bar x$ 339 | }\end{slide} 340 | 341 | \section{Whole kinematics} 342 | \begin{slide}{Whole kinematics}{Whole kinematics}{ 343 | \item Position, integrated from velocity $\dot x = v$ 344 | \item Velocity, derived from linear momentum $v = \frac{P}{m}$ 345 | \item Linear momentum, integrated from force $\dot P = F_{\text{ext}} \cdot \frac{(r_f - \bar x)}{|(r_f - \bar x)|}$ 346 | }\end{slide} 347 | 348 | \begin{slide}{Whole kinematics}{Whole kinematics}{ 349 | \item Rotation, integrated from angular velocity $\dot R = [\omega \times T\ \omega \times N\ \omega \times B]$ 350 | \item Angular velocity, derived from angular momentum $\omega = J^{-1} L$ 351 | \item Angular momentum, integrated from torque $\dot L = \tau = \frac{(r_f - \bar x)}{|(r_f - \bar x)|} \times F_{\text{ext}}$ 352 | }\end{slide} 353 | 354 | \begin{frame}{That's it} 355 | \center 356 | \fontsize{18pt}{7.2}\selectfont 357 | Thank you! 358 | \end{frame} 359 | 360 | \end{document} 361 | -------------------------------------------------------------------------------- /Slides/Lecture 1/Pics/Fig2_15.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 1/Pics/Fig2_15.PNG -------------------------------------------------------------------------------- /Slides/Lecture 1/Pics/Fig2_3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 1/Pics/Fig2_3.PNG -------------------------------------------------------------------------------- /Slides/Lecture 1/Pics/Torque_animation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 1/Pics/Torque_animation.png -------------------------------------------------------------------------------- /Slides/Lecture 1/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 2/Lecture 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Lecture 2.pdf -------------------------------------------------------------------------------- /Slides/Lecture 2/Lecture 2.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Differential equations} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{frame}{Table of contents} 25 | \tableofcontents 26 | \end{frame} 27 | 28 | \section{Introduction} 29 | \begin{slide}{Introduction}{Differential equation}{ 30 | \item Equations of the form $\dot x = f(x,t)$ 31 | \item $x$ is the state of the system (an ``array of floats'') 32 | \item $f$ is the function that computes the derivative of $x$ with respect to time 33 | \item General purpose toolbox for dealing with them 34 | }\end{slide} 35 | 36 | \begin{slide}{Introduction}{How does this apply to us?}{ 37 | \item $x$ is the state of all our rigid bodies 38 | \item $f$ gives us the derivative of the state: velocity, acceleration, \textit{angular velocity}, torque 39 | }\end{slide} 40 | 41 | \begin{frame}{Introduction} 42 | \begin{tabular}{| c | c |} 43 | \hline 44 | $x$ & $f(x)$ \\ 45 | \hline 46 | position & velocity \\ 47 | velocity/linear momentum & acceleration/force \\ 48 | rotation & \textit{angular velocity} ($\omega \star R$) \\ 49 | angular velocity/angular momentum & angular acceleration/torque \\ 50 | \hline 51 | \end{tabular} 52 | \end{frame} 53 | 54 | \section{Numerical solutions} 55 | \begin{slide}{Numerical solutions}{Numerical solutions}{ 56 | \item We cannot just compute the state at time $t$ 57 | \item There is no closed form for it, unless the problem is really simple \footnote{Yeah, you wish :)} 58 | \item We look for an \textit{approximate} solution 59 | }\end{slide} 60 | 61 | \begin{slide}{Numerical solutions}{Field of derivatives}{ 62 | \item We know how to compute $f$ 63 | \item This means that we can compute the \textit{field of slopes} of $x$ 64 | }\end{slide} 65 | 66 | \begin{frame}{Slope field} 67 | \center 68 | \includegraphics[width=7cm]{Pics/Fig1.png} 69 | \end{frame} 70 | 71 | \begin{slide}{Numerical solutions}{Field of derivatives}{ 72 | \item Start at $x_0$ 73 | \item Follow the slope 74 | \item Discrete steps 75 | }\end{slide} 76 | 77 | \begin{frame}{Following the slope} 78 | \center 79 | \includegraphics[width=7cm]{Pics/Fig2.png} 80 | \end{frame} 81 | 82 | \section{Euler's method} 83 | \begin{slide}{Numerical solutions}{Euler's method}{ 84 | \item Big, discrete steps along the slope: $x(t+h) = x(t) + h \dot x(t)$ 85 | \item Actually works correctly and \textit{may be acceptable} in some cases 86 | \item If it is acceptable, it's simple to code and fast to run 87 | \item Otherwise it requires a very small time-step to compensate (more computation!) 88 | }\end{slide} 89 | 90 | \begin{frame}{Euler's method} 91 | \center 92 | \includegraphics[width=7cm]{Pics/Fig3.png} 93 | \end{frame} 94 | 95 | \begin{slide}{Numerical solutions}{Euler's method}{ 96 | \item Why may Euler's method not work? 97 | \item Euler's method is 98 | \begin{itemize} 99 | \item Inaccurate, that is it may jump from one trajectory to another 100 | \item Not stable, that is it may increase the energy of the state where it should decrease 101 | \end{itemize} 102 | }\end{slide} 103 | 104 | \begin{frame}{Euler's method} 105 | \center 106 | \includegraphics[width=7cm]{Pics/Fig4.png} 107 | \end{frame} 108 | 109 | \section{Deriving more sophisticated methods} 110 | \begin{slide}{Numerical solutions}{Taylor series}{ 111 | \item Any function can be expressed as the infinite sum of its derivatives 112 | \item $x(t+h) = x(t) + h \dot x(t) + \frac{h^2}{2} \ddot x(t) + \dots + \frac{h^n}{n!} \frac{d^n}{dt^n}x(t) + \dots$ 113 | \pause 114 | \item We can \textit{truncate} this summation to \textit{approximate} the original function 115 | \item All differential equations solvers are based on this technique 116 | }\end{slide} 117 | 118 | \begin{slide}{Numerical solutions}{Deriving Euler's method}{ 119 | \item $x(t+h) = x(t) + h \dot x(t) + \frac{h^2}{2} \ddot x(t) + \dots + \frac{h^n}{n!} \frac{d^n}{dt^n}x(t) + \dots$ 120 | \item $x(t+h) \approx x(t) + h \dot x(t)$ 121 | }\end{slide} 122 | 123 | \begin{slide}{Numerical solutions}{Deriving the midpoint method}{ 124 | \item $x(t+h) \approx x(t) + h \dot x(t) + \frac{h^2}{2} \ddot x(t)$ 125 | \pause 126 | \item We must now compute $\ddot x(t)$ 127 | \item $\ddot x = \frac{d}{dt} \dot x = \frac{d}{dt} f(x(t)) = f'(x(t)) \dot x = f'(x(t)) f(x(t))$ 128 | }\end{slide} 129 | 130 | \begin{slide}{Numerical solutions}{Deriving the midpoint method}{ 131 | \item $\ddot x = f'(x(t)) f(x(t))$ 132 | \item We now approximate $f$ with Euler's method 133 | \item $f(x_0 + \Delta x) = f(x_0) + \Delta x f'(x_0)$ 134 | }\end{slide} 135 | 136 | \begin{slide}{Numerical solutions}{Deriving the midpoint method}{ 137 | \item We (arbitrarily) choose $\Delta x = \frac{h}{2} f(x_0)$ (which is an acceptable solution, check units of measure!) 138 | \item Substitute the approximation of $f$ 139 | \item $f(x_0 + \frac{h}{2} f(x_0)) = f(x_0) + \frac{h}{2} f(x_0) f'(x_0)$ 140 | \item We multiply both sides by $h$: 141 | \item $h(f(x_0 + \frac{h}{2} f(x_0)) - f(x_0)) = \underbrace{\frac{h^2}{2} f(x_0) f'(x_0)}_{\frac{h^2}{2} \ddot x}$ 142 | }\end{slide} 143 | 144 | \begin{slide}{Numerical solutions}{Deriving the midpoint method}{ 145 | \item $x(t+h) \approx x(t) + h \dot x(t) + \frac{h^2}{2} \ddot x(t)$ 146 | \item $\ddot x = f'(x(t)) f(x(t))$ 147 | \item $h(f(x_0 + \frac{h}{2} f(x_0)) - f(x_0)) = \frac{h^2}{2} f(x_0) f'(x_0) = \frac{h^2}{2} \ddot x$ 148 | \pause 149 | \item $x(t+h) \approx x(t) + h \dot x(t) + h(f(x_0 + \frac{h}{2} f(x_0)) - f(x_0))$ 150 | }\end{slide} 151 | 152 | \begin{slide}{Numerical solutions}{Deriving the midpoint method}{ 153 | \item $x(t+h) \approx x(t) + h \dot x(t) + h(f(x_0 + \frac{h}{2} f(x_0)) - f(x_0))$ 154 | \item We sample the derivative at the midpoint of the step, hence the name 155 | }\end{slide} 156 | 157 | \begin{frame}{RK2} 158 | \center 159 | \includegraphics[width=6cm]{Pics/Midpoint_method.png} 160 | \end{frame} 161 | 162 | \begin{slide}{Numerical solutions}{About the midpoint method}{ 163 | \item $x(t+h) \approx x(t) + h \dot x(t) + h(f(x_0 + \frac{h}{2} f(x_0)) - f(x_0))$ 164 | \item We compute $f$ twice; in general though, the higher number of evaluations of $f$ in advanced methods is more than offset by the far smaller time step needed 165 | }\end{slide} 166 | 167 | \begin{slide}{Numerical solutions}{RK4}{ 168 | \item The ``best'' numerical method though is RK4 169 | \item $k_1 = h f(x_0)$, $k_2 = h f(x_0 + \frac{k_1}{2})$, $k_3 = h f(x_0 + \frac{k_2}{2})$, $k_4 = h f(x_0 + \frac{k_3}{2})$ 170 | \item $x(t+h) = x_0 + \frac{1}{6} k_1 + \frac{1}{3} k_2 + \frac{1}{3} k_3 + \frac{1}{6} k_4$ 171 | }\end{slide} 172 | 173 | \begin{frame}{RK4} 174 | \center 175 | \includegraphics[width=6cm]{Pics/RK4.png} 176 | \end{frame} 177 | 178 | \section{The ``best'' method?} 179 | \begin{slide}{Numerical solutions}{To the stars and beyond?}{ 180 | \item Why not use RK5, RK6, or even more? 181 | \item Is it not more precise after all? 182 | \pause 183 | \item Suspense :) 184 | \pause 185 | \item NO! 186 | \item We can approximate the higher order derivatives with the first derivative only so far 187 | \item After a while we are just not inserting any new information 188 | \item Very high order methods would only work if we could reliably compute third or fourth order derivatives 189 | \item Otherwise we insert spurious oscillations and new errors in the system 190 | }\end{slide} 191 | 192 | \begin{frame}{That's it} 193 | \center 194 | \fontsize{18pt}{7.2}\selectfont 195 | Thank you! 196 | \end{frame} 197 | 198 | \end{document} 199 | 200 | 201 | \begin{slide}{SECTION}{SLIDE}{ 202 | \item i 203 | }\end{slide} 204 | 205 | \begin{frame}[fragile]{SLIDE} 206 | \begin{lstlisting} 207 | CODE 208 | \end{lstlisting} 209 | \end{frame} 210 | 211 | \begin{frame}{SLIDE} 212 | \center 213 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 214 | \end{frame} 215 | -------------------------------------------------------------------------------- /Slides/Lecture 2/Pics/Fig1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Pics/Fig1.PNG -------------------------------------------------------------------------------- /Slides/Lecture 2/Pics/Fig2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Pics/Fig2.PNG -------------------------------------------------------------------------------- /Slides/Lecture 2/Pics/Fig3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Pics/Fig3.PNG -------------------------------------------------------------------------------- /Slides/Lecture 2/Pics/Fig4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Pics/Fig4.PNG -------------------------------------------------------------------------------- /Slides/Lecture 2/Pics/Fig5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Pics/Fig5.PNG -------------------------------------------------------------------------------- /Slides/Lecture 2/Pics/Midpoint_method.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Pics/Midpoint_method.png -------------------------------------------------------------------------------- /Slides/Lecture 2/Pics/RK4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 2/Pics/RK4.png -------------------------------------------------------------------------------- /Slides/Lecture 2/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 3/Lecture 3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 3/Lecture 3.pdf -------------------------------------------------------------------------------- /Slides/Lecture 3/Lecture 3.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Integration, rotation matrices, and quaternions} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{frame}{Table of contents} 25 | \tableofcontents 26 | \end{frame} 27 | 28 | \section{Integration and rotation} 29 | \begin{slide}{Integration and rotation}{Integration and rotation}{ 30 | \item We integrate $L$ from $\tau$ 31 | \item We integrate $w$ from $L$ and $J^-1$ 32 | \item We integrate $R$ from $w$ 33 | }\end{slide} 34 | 35 | \begin{slide}{Integration and rotation}{Issues}{ 36 | \item \textit{Issue 1:} recomputing $J$ from every particle of the body and at every tick is too slow 37 | \item \textit{Issue 2:} integrating $R$ slowly ``breaks it'', meaning that $[T\ N\ B]$ is not a rotation anymore 38 | }\end{slide} 39 | 40 | \section{Caching J} 41 | \begin{slide}{Caching J}{Issue 1: body shape}{ 42 | \item $J$ represents the tendency of the body to resist rotation 43 | \item But the body just moves and rotates, it does not change shape 44 | \item We should be able to simply recompute $J$ from its initial value and the rotation 45 | }\end{slide} 46 | 47 | \begin{frame}{Caching J} 48 | \begin{block}{$J$ from $J_{body}$} 49 | \begin{eqnarray} 50 | J &=& \sum_i(|r_i(t)|^2I - r_i(t) r_i^T(t)) \\ 51 | &=& \sum_i(|R r_i(t_0)|^2I - R r_i(t_0) r_i^T(t_0) R^T) \\ 52 | &=& \sum_i(|r_i(t_0)|^2I - R r_i(t_0) r_i^T(t_0) R^T) \\ % rotation keeps length 53 | &=& \sum_i(|r_i(t_0)|^2 R R^T - R r_i(t_0) r_i^T(t_0) R^T) \\ % R R^T = I 54 | &=& \sum_i(R |r_i(t_0)|^2 R^T - R r_i(t_0) r_i^T(t_0) R^T) % scalar and matrix multiplication is commutative 55 | \end{eqnarray} 56 | \end{block} 57 | \end{frame} 58 | 59 | \begin{frame}{Caching J} 60 | \begin{block}{$J$ from $J_{body}$} 61 | \begin{eqnarray} 62 | J &=& \sum_i(R |r_i(t_0)|^2 R^T - R r_i(t_0) r_i^T(t_0) R^T) \\ % scalar and matrix multiplication is commutative 63 | &=& \sum_i R(|r_i(t_0)|^2 - r_i(t_0) r_i^T(t_0)) R^T \\ % grouping 64 | &=& R \left( \sum_i (|r_i(t_0)|^2 - r_i(t_0) r_i^T(t_0)) \right) R^T \\ % grouping 65 | &=& R J_{body} R^T 66 | \end{eqnarray} 67 | \end{block} 68 | \end{frame} 69 | 70 | \begin{slide}{Caching J}{$J^{-1}$ from $J_{body}{-1}$}{ 71 | \item We need $J^{-1}$ more than $J$ 72 | \item We can compute it without an inversion though 73 | \item We compute (just once) $J_{body}^{-1}$ 74 | \item $J^{-1} (R J_{body} R^T)^{-1} = R J_{body}^{-1} R^T$ 75 | }\end{slide} 76 | 77 | \section{Orthonormalization of $R$} 78 | \begin{slide}{Orthonormalization of $R$}{Issue 2: $R$ is a rotation matrix}{ 79 | \item $R = [T\ N\ B]$ 80 | \item The vectors $T$, $N$, and $B$ must be of unit length and orthonormal ($T \cdot N = 0, T \cdot B = 0, \dots$) 81 | \item As we integrate $R$, this stops being true 82 | \item $R$ stops being just a rotation matrix, and also incorporates some scale and some skew 83 | \item This is very bad! 84 | }\end{slide} 85 | 86 | \begin{frame}{Boxes stop being boxes} 87 | \center 88 | \includegraphics[height=5cm]{Pics/Kill_me_please.png} 89 | \end{frame} 90 | 91 | \begin{slide}{Orthonormalization of $R$}{Gram-Schimdt method}{ 92 | \item $\hat R = [\hat T\ \hat N\ \hat B]$ 93 | \item We normalize $T = \frac{\hat T}{|\hat T|}$ 94 | \item We remove the projection of $\hat N$ over $T$: $\hat N' = \hat N - \hat N (\hat N \cdot T)$ 95 | \item We normalize $N = \frac{\hat N'}{|\hat N'|}$ 96 | \item We compute $B = T \times N$ 97 | }\end{slide} 98 | 99 | \begin{slide}{Orthonormalization of $R$}{Gram-Schimdt method}{ 100 | \item Lot of useless computation 101 | \item Matrix representation very redundant 102 | \item $\hat B$ is completely unneeded and is ignored! 103 | }\end{slide} 104 | 105 | \section{Using quaternions} 106 | \begin{slide}{Using quaternions}{About quaternions}{ 107 | \item We just need a single rotation around an axis (which is an arbitrary rotation in 3D) 108 | \item Less degrees of freedom means less drift and less need for normalization 109 | }\end{slide} 110 | 111 | \begin{slide}{Using quaternions}{Quaternion primer}{ 112 | \item Let us consider a rotation matrix around the Z axis 113 | \item $R_0 = \left[ \begin{matrix} 114 | \cos \theta & -\sin \theta & 0 \\ 115 | \sin \theta & \cos \theta & 0 \\ 116 | 0 & 0 & 1\\ 117 | \end{matrix} \right] = 118 | \left[ \begin{matrix} 119 | c & -s & 0 \\ 120 | s & c & 0 \\ 121 | 0 & 0 & 1 \\ 122 | \end{matrix} \right]$ 123 | }\end{slide} 124 | 125 | \begin{slide}{Using quaternions}{Quaternion primer}{ 126 | \item Any vector $v$ on the XY plane rotated by $R_0$ remains on XY, rotated around Z by an angle $\theta$ 127 | \item Any vector $v$ on the Z axis rotated by $R_0$ remains (identical) on Z 128 | }\end{slide} 129 | 130 | \begin{slide}{Using quaternions}{Quaternion primer}{ 131 | \item Let us transform this rotation into an arbitrary rotation $R_1$ around an axis $d$ and of angle $\theta$ 132 | \item We consider an \textit{orthonormal basis} $a,b,d$ 133 | \item We perform a \textit{basis change} of $R_0$ onto $a,b,d$ 134 | }\end{slide} 135 | 136 | \begin{slide}{Using quaternions}{Quaternion primer}{ 137 | \item We need to build $R_1$ such that 138 | \begin{itemize} 139 | \item $R_1 a = ca + sb$ 140 | \item $R_1 b = -sa + cb$ 141 | \item $R_1 d = d$ 142 | \end{itemize} 143 | \item That is $R_1 \underbrace{[a\ b\ d]}_P = \underbrace{[a\ b\ d]}_P R_0$ 144 | \item $P^{-1} = P^T$, so $R_1 = P R_0 P^T = c(aa^T + bb^T) + s(ba^T - ab^T) + dd^T$ 145 | }\end{slide} 146 | 147 | \begin{slide}{Using quaternions}{Quaternion primer}{ 148 | \item $R_1 = c(aa^T + bb^T) + s(ba^T - ab^T) + dd^T$ 149 | \item This means that we can now construct a rotation matrix from an axis and an angle 150 | \item Unfortunately we also need two ``dummy'' vectors $a$ and $b$ 151 | \item Any pair of those suffices, as long as they are correctly related to $d$ 152 | \item We now remove the explicit dependency on them 153 | }\end{slide} 154 | 155 | \begin{slide}{Using quaternions}{Quaternion primer}{ 156 | \item Consider a vector expressed in relationship to $a,b,d$: $v = \underbrace{\alpha}_{a \cdot v} a + \underbrace{\beta}_{b \cdot v} b + \underbrace{\delta}_{d \cdot v} d$ 157 | \item We now consider two arbitrary but useful quantities: 158 | \item $d \times v = d \times (\alpha a + \beta b + \delta d) = \alpha d \times a + \beta d \times b + \delta d \times d = -\beta a + \alpha b = Dv = \left[ \begin{matrix} 159 | 0 & -d_z & d_y \\ 160 | d_z & 0 & -d_x \\ 161 | -d_y & d_x & 0 \\ 162 | \end{matrix} \right] v$ 163 | \item $d \times (d \times v) = d \times (-\beta a + \alpha b) = -\alpha a - \beta b = D^2v$ 164 | }\end{slide} 165 | 166 | \begin{slide}{Using quaternions}{Quaternion primer}{ 167 | \item Now let us study the progression of $Iv, Dv, D^v$ 168 | \item $Iv = v = \alpha a + \beta b + \delta d = aa^Tv + bb^Tv + dd^Tv$, so $I = aa^T + bb^T + dd^T$ 169 | \item $Dv = \alpha b - \beta a = ba^Tv - ab^Tv$, so $D = ba^T-ab^T$ 170 | \item $D^2v = -\alpha a - \beta b = \delta d - v = dd^Tv - v$, so $D^2 = dd^T - I$ 171 | }\end{slide} 172 | 173 | \begin{slide}{Using quaternions}{Quaternion primer}{ 174 | \item We combine those three into $R_1 = c(aa^T + bb^T) + s(ba^T - ab^T) + dd^T$ 175 | \item $I = aa^T + bb^T + dd^T$, $D = ba^T-ab^T$, $D^2 = dd^T - I$ 176 | \pause 177 | \item $R_1 = c(I - dd^T) + sD + dd^T$ 178 | \item $R_1 = I + sD + (1-c)D^2$ 179 | }\end{slide} 180 | 181 | \begin{slide}{Using quaternions}{Quaternion primer}{ 182 | \item We can now compute $R_1 = I + sD + (1-c)D^2$ from just $d, \theta$ 183 | \item Moreover, we can rotate a vector without even building $R_1$ 184 | \begin{eqnarray} 185 | R_1v &=& (I + s D + (1-c)D^2)v \\ 186 | &=& Iv + s D v + (1-c)D^2 v \\ 187 | &=& v + s d\times v + (1-c)d \times (d \times v) 188 | \end{eqnarray} 189 | }\end{slide} 190 | 191 | \begin{slide}{Using quaternions}{Quaternion primer}{ 192 | \item Any representation of $d$ and $\theta$ would be fine 193 | \item A particularly convenient one is $[\cos \frac{\theta}{2}, \sin \frac{\theta}{2} d]$ 194 | }\end{slide} 195 | 196 | \section{Time derivative of a quaternion} 197 | \begin{slide}{Deriving quaternions}{Derivative of rotation matrix}{ 198 | \item We studied how to compute $\dot R$ from $R$ and $\omega$ 199 | \item If we represent rotations with quaternions, we need to compute $\dot q$ 200 | }\end{slide} 201 | 202 | \begin{slide}{Deriving quaternions}{Derivative of quaternion}{ 203 | \item Given the current orientation $q(t_0)$ and angular velocity $\omega(t_0)$ 204 | \item Assuming very small $t-t_0$ 205 | \item The derivative of the original quaternion is $\frac{d}{dt}\underbrace{[\cos \frac{|\omega(t_0)|(t-t_0)}{2}, \frac{\omega(t_0)}{|\omega(t_0)|} \sin \frac{|\omega(t_0)|(t-t_0)}{2}]}_{\omega \text{ converted to a quaternion}} q(t_0)$ 206 | }\end{slide} 207 | 208 | \begin{slide}{Deriving quaternions}{Derivative of quaternion}{ 209 | \item $\frac{d}{dt}[\cos \frac{|w(t_0)|(t-t_0)}{2}, \frac{w(t_0)}{|w(t_0)|} \sin \frac{|w(t_0)|(t-t_0)}{2}] q(t_0)$ 210 | \item We now derive the $w$ part ($q(t_0)$ is a constant) and replace $t$ with $t_0$ because we want to know the value of the derivative at the current time $t_0$ 211 | \item $[-\frac{|\omega(t_0)|}{2} \sin \frac{|\omega(t_0)|(t_0-t_0)}{2}, \frac{\omega(t_0)}{|\omega(t_0)|} \frac{|\omega(t_0)|}{2} \cos \frac{|\omega(t_0)|(t-t_0)}{2}] q(t_0)$ 212 | \item $[-\frac{|\omega(t_0)|}{2} \sin 0, \frac{\omega(t_0)}{|\omega(t_0)|} \frac{|\omega(t_0)|}{2} \cos 0] q(t_0)$ 213 | \item $[0, \frac{\omega(t_0)}{2}] q(t_0) = \frac{1}{2} [0, \omega(t_0)] q(t_0)$ 214 | }\end{slide} 215 | 216 | \begin{slide}{Deriving quaternions}{Derivative of quaternion}{ 217 | \item At least remember this: 218 | \item $\dot q = \frac{1}{2} [0, \omega] q$ 219 | }\end{slide} 220 | 221 | \section{Kinematics source code} 222 | \begin{frame}[fragile]{Kinematics source code} 223 | \begin{lstlisting} 224 | // initialization 225 | RigidBody* body[n]; 226 | double t = ; 227 | double dt = ; 228 | for (int i = 0; i < n; ++i) { 229 | // Set the initial state of the rigid bodies. 230 | body[i] = new RigidBody(...); 231 | 232 | // Part of the physics tick. 233 | for (i = 0; i < n; ++i) { 234 | body[i].Update(t, dt); 235 | t += dt; 236 | } 237 | \end{lstlisting} 238 | \end{frame} 239 | 240 | \begin{frame}[fragile]{Kinematics source code} 241 | \begin{lstlisting} 242 | struct RigidBody { 243 | RigidBody (double m, matrix inertia, Function force, Function torque); 244 | 245 | // force/torque function format 246 | typedef vector ( *Function ) ( 247 | double, // time of application 248 | point, // position 249 | quaternion, // orientation 250 | ... // whole state of body, one var at a time 251 | ) 252 | ); 253 | 254 | // Runge-Kutta fourth order differential equation solver 255 | void Update (double t, double dt); 256 | \end{lstlisting} 257 | \end{frame} 258 | 259 | \begin{frame}[fragile]{Kinematics source code} 260 | \begin{lstlisting} 261 | protected: 262 | // convert (Q,P,L) to (R,V,W) 263 | void Convert (quaternion Q, vector P, vector L, matrix& R, vector& V, vector& W) const; 264 | // constant quantities 265 | double m_mass, m_invMass; 266 | matrix m_inertia, m_invInertia; 267 | // state variables 268 | vector m_X; // position 269 | quaternion m_Q; // orientation 270 | vector m_P; // linear momentum 271 | vector m_L; // angular momentum 272 | \end{lstlisting} 273 | \end{frame} 274 | 275 | \begin{frame}[fragile]{Kinematics source code} 276 | \begin{lstlisting} 277 | // derived state variables 278 | matrix m_R; // orientation matrix 279 | vector m_V; // linear velocity vector 280 | m_W; // angular velocity 281 | // force and torque functions 282 | Function m_force; Function m_torque; 283 | }; 284 | \end{lstlisting} 285 | \end{frame} 286 | 287 | \begin{frame}[fragile]{Kinematics source code} 288 | \begin{lstlisting} 289 | void RigidBody::Convert (quaternion Q, vector P, vector L, matrix& R, vector& V, vector& W) const { 290 | Q.ToRotationMatrix(R); 291 | V = m_invMass*P; 292 | W = R*m_invInertia*Transpose(R)*L; 293 | } 294 | \end{lstlisting} 295 | \end{frame} 296 | 297 | \begin{frame}[fragile]{Kinematics source code} 298 | \begin{lstlisting} 299 | void RigidBody::Update (double t, double dt) { 300 | double halfdt = 0.5 * dt, sixthdt = dt / 6.0; 301 | double tphalfdt = t + halfdt, tpdt = t + dt; 302 | \end{lstlisting} 303 | \end{frame} 304 | 305 | \begin{frame}[fragile]{Kinematics source code} 306 | \begin{lstlisting} 307 | vector XN, PN, LN, VN, WN; 308 | quaternion QN; 309 | matrix RN; 310 | // A1 = G(t,S0), B1 = S0 + (dt / 2) * A1 311 | vector A1DXDT = m_V; 312 | quaternion A1DQDT = 0.5 * m_W * m_Q; 313 | vector A1DPDT = m_force(t,m_X,m_Q,m_P,m_L,m_R,m_V,m_W); 314 | vector A1DLDT = m_torque(t,m_X,m_Q,m_P,m_L,m_R,m_V,m_W); 315 | XN = m_X + halfdt * A1DXDT; 316 | QN = m_Q + halfdt * A1DQDT; 317 | PN = m_P + halfdt * A1DPDT; 318 | LN = m_L + halfdt * A1DLDT; 319 | Convert(QN,PN,LN,RN,VN,WN); 320 | \end{lstlisting} 321 | \end{frame} 322 | 323 | \begin{frame}[fragile]{Kinematics source code} 324 | \begin{lstlisting} 325 | // A2 = G(t + dt / 2,B1), B2 = S0 + (dt / 2) * A2 326 | vector A2DXDT = VN; 327 | quaternion A2DQDT = 0.5 * WN * QN; 328 | vector A2DPDT = m_force(tphalfdt,XN,QN,PN,LN,RN,VN,WN); 329 | vector A2DLDT = m_torque(tphalfdt,XN,QN,PN,LN,RN,VN,WN); 330 | XN = m_X + halfdt * A2DXDT; 331 | QN = m_Q + halfdt * A2DQDT; 332 | PN = m_P + halfdt * A2DPDT; 333 | LN = m_L + halfdt * A2DLDT; 334 | Convert(QN,PN,LN,RN,VN,WN); 335 | \end{lstlisting} 336 | \end{frame} 337 | 338 | \begin{frame}[fragile]{Kinematics source code} 339 | \begin{lstlisting} 340 | // A3 = G(t + dt / 2,B2), B3 = S0 + dt * A3 341 | vector A3DXDT = VN; 342 | quaternion A3DQDT = 0.5 * WN * QN; 343 | 344 | vector A3DPDT = m_force(tphalfdt,XN,QN,PN,LN,RN,VN,WN); 345 | vector A3DLDT = m_torque(tphalfdt,XN,QN,PN,LN,RN,VN,WN); 346 | XN = m_X + dt * A3DXDT; 347 | QN = m_Q + dt * A3DQDT; 348 | PN = m_P + dt * A3DPDT; 349 | LN = m_L + dt * A3DLDT; 350 | Convert(QN,PN,LN,RN,VN,WN); 351 | \end{lstlisting} 352 | \end{frame} 353 | 354 | \begin{frame}[fragile]{Kinematics source code} 355 | \begin{lstlisting} 356 | // A4 = G(t + dt,B3), 357 | // S1 = S0 + (dt / 6) * (A1 + 2 * A2 + 2 * A3 + A4) 358 | vector A4DXDT = VN; 359 | quaternion A4DQDT = 0.5 * WN * QN; 360 | vector A4DPDT = m_force(tpdt,XN,QN,PN,LN,RN,VN,WN); 361 | vector A4DLDT = m_torque(tpdt,XN,QN,PN,LN,RN,VN,WN); 362 | m_X = m_X + sixthdt*(A1DXDT + 2.0*(A2DXDT + A3DXDT) + A4DXDT); 363 | m_Q = m_Q + sixthdt*(A1DQDT + 2.0*(A2DQDT + A3DQDT) + A4DQDT); 364 | m_P = m_P + sixthdt*(A1DPDT + 2.0*(A2DPDT + A3DPDT) + A4DPDT); 365 | m_L = m_L + sixthdt*(A1DLDT + 2.0*(A2DLDT + A3DLDT) + A4DLDT); 366 | Convert(m_Q,m_P,m_L,m_R,m_V,m_W); 367 | } 368 | \end{lstlisting} 369 | \end{frame} 370 | 371 | 372 | \begin{frame}{That's it} 373 | \center 374 | \fontsize{18pt}{7.2}\selectfont 375 | Thank you! 376 | \end{frame} 377 | 378 | \end{document} 379 | -------------------------------------------------------------------------------- /Slides/Lecture 3/Pics/Kill_me_please.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 3/Pics/Kill_me_please.png -------------------------------------------------------------------------------- /Slides/Lecture 3/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 4/Lecture 4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 4/Lecture 4.pdf -------------------------------------------------------------------------------- /Slides/Lecture 4/Lecture 4.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Building a physics engine - part 1: architecture} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \section{Physics engine basics} 25 | \begin{slide}{Physics engine basics}{Main goals}{ 26 | \item Apply Newton's law of motion $F = ma$ to linear and rotational movement (easy) 27 | \item Ensure no interpenetration of moving objects (absolutely \textbf{not easy}) 28 | }\end{slide} 29 | 30 | \begin{slide}{Physics engine basics}{Interpenetration avoidance}{ 31 | \item Find pairs of touching objects 32 | \item Find time of contact 33 | \item Find points of contact 34 | \item Apply forces to ensure no interpenetration/stacking/etc. 35 | }\end{slide} 36 | 37 | \begin{slide}{Physics engine basics}{Finding colliding pairs}{ 38 | \item Broad-phase collision detection with AABBs 39 | \item Medium-phase collision detection with bounding volumes (BS, OBB) 40 | \item Narrow-phase collision detection to find exact time and points of contact 41 | }\end{slide} 42 | 43 | \begin{slide}{Physics engine basics}{Collision response}{ 44 | \item Between pairs of objects: easy, just apply the laws of conservation of momentum 45 | \item How about between multiple objects, maybe even stacked? 46 | \item Solving in pairs does not work! 47 | \item We need to solve all of these constraints at the same time 48 | }\end{slide} 49 | 50 | \begin{slide}{Physics engine basics}{Collision response and constraints}{ 51 | \item Collision response balances external forces and velocities; it applies to multiple kinds of constraints: 52 | \begin{itemize} 53 | \item Contact constraints (the obvious ones) 54 | \item Distance constraints 55 | \item Friction constraints 56 | \item ... 57 | \end{itemize} 58 | }\end{slide} 59 | 60 | \begin{frame}[fragile]{General layout of a physics engine} 61 | \begin{lstlisting} 62 | physics.Initialize: 63 | setup AABB, BV (BS and others), BSP/Gauss maps, other support data structures 64 | 65 | physics.Tick: 66 | update AABBs 67 | find AABBs intersections 68 | refine AABBs intersections with BV tests (optional) 69 | separating axes collision detection 70 | resolve physics constraints 71 | contacts 72 | friction 73 | distance 74 | ... 75 | apply kinematics 76 | \end{lstlisting} 77 | \end{frame} 78 | 79 | \section{Assignment} 80 | \begin{slide}{Assignment}{Assignment}{ 81 | \item Before the end of next week 82 | \item Group-work archive/video on Natschool or uploaded somewhere else and linked in your report 83 | \item Individual report by each of you on Natschool 84 | \item Build a kinematics simulator with movement and rotation, with RK2 or RK4 85 | }\end{slide} 86 | 87 | \begin{frame}{That's it} 88 | \center 89 | \fontsize{18pt}{7.2}\selectfont 90 | Thank you! 91 | \end{frame} 92 | 93 | \end{document} 94 | 95 | 96 | \begin{slide}{SECTION}{SLIDE}{ 97 | \item i 98 | }\end{slide} 99 | 100 | \begin{frame}[fragile]{SLIDE} 101 | \begin{lstlisting} 102 | CODE 103 | \end{lstlisting} 104 | \end{frame} 105 | 106 | \begin{frame}{SLIDE} 107 | \center 108 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 109 | \end{frame} 110 | -------------------------------------------------------------------------------- /Slides/Lecture 4/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 5/Lecture 5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Lecture 5.pdf -------------------------------------------------------------------------------- /Slides/Lecture 5/Lecture 5.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | \DeclareMathOperator{\lerp}{lerp} 12 | 13 | \title{Building a physics engine - part 2: narrow phase of collision detection} 14 | 15 | \author{Dr. Giuseppe Maggiore} 16 | 17 | \institute{NHTV University of Applied Sciences \\ 18 | Breda, Netherlands} 19 | 20 | \date{} 21 | 22 | \begin{document} 23 | \maketitle 24 | 25 | \begin{frame}{Table of contents} 26 | \tableofcontents 27 | \end{frame} 28 | 29 | \section{Narrow phase collision detection and response} 30 | \begin{slide}{Narrow phase}{Narrow phase}{ 31 | \item Find intersections for each pair of rigid bodies 32 | \begin{itemize} 33 | \item Whether they intersect 34 | \item When they intersect 35 | \item Where they intersect 36 | \end{itemize} 37 | \item Acceptable precision 38 | \item Very high performance 39 | }\end{slide} 40 | 41 | \begin{slide}{Narrow phase}{Response}{ 42 | \item At all points of contact the \textit{relative velocity} projected along the normal must be non-negative 43 | \item No pair of bodies in contact is getting closer 44 | \begin{itemize} 45 | \item This would mean that they are penetrating each other 46 | \end{itemize} 47 | }\end{slide} 48 | 49 | \begin{frame}{Relative Velocity} 50 | \center 51 | \includegraphics[width=8cm]{Pics/Rel_Vel.png} 52 | \end{frame} 53 | 54 | \begin{slide}{Narrow phase}{Response}{ 55 | \item \textit{Relatively} easy to handle between pairs of bodies 56 | \item Multiple bodies in contact make it much harder 57 | }\end{slide} 58 | 59 | \begin{frame}{Relative Velocity} 60 | \center 61 | \includegraphics[width=6cm]{Pics/Stacking.png} 62 | \end{frame} 63 | 64 | \section{Convex polyhedra} 65 | \begin{slide}{Convex polyhedra}{Convex polyhedra}{ 66 | \item Also known as \textit{polytopes} 67 | \item $\forall P,Q \in C. \forall \alpha \in [0..1]. \lerp(\alpha, P, Q) \in C$ 68 | \item Complex bodies can be treated as multiple polytopes with distance constraints 69 | }\end{slide} 70 | 71 | \begin{frame}{Convex polygon} 72 | \center 73 | \includegraphics[width=6cm]{Pics/ConvexPolyhedron.png} 74 | \end{frame} 75 | 76 | \begin{frame}{Convex polyhedra} 77 | \center 78 | \includegraphics[height=5cm]{Pics/ConvexPolyhedra.png} 79 | \end{frame} 80 | 81 | \section{Separating axis} 82 | \begin{slide}{Separating axis}{Method of separating axis}{ 83 | \item We use a method that works in 2D and 3D 84 | \begin{itemize} 85 | \item We look for an axis/plane that separates the bodies 86 | \end{itemize} 87 | }\end{slide} 88 | 89 | \begin{frame}{Separating axis} 90 | \center 91 | \includegraphics[height=5cm]{Pics/Fig6_19.png} 92 | \end{frame} 93 | 94 | \begin{slide}{Separating axis}{Method of separating axis}{ 95 | \item Given a (not necessarily unit-length) direction $D$ and two polytopes $C_0$ and $C_1$ 96 | \item We project them over the direction $D$: $I_i = [\lambda_{min}^i,\lambda_{max}^i] = [\min_{x\in C_i}\{ D \cdot (X-O) \}, \max_{x\in C_i}\{ D \cdot (X-O) \}]$ 97 | \item There is no collision if $\exists D . \lambda_{min}^0 > \lambda_{max}^1 \vee \lambda_{min}^1 > \lambda_{max}^0$ 98 | }\end{slide} 99 | 100 | \begin{frame}{Separating axis} 101 | \center 102 | \includegraphics[width=8cm]{Pics/Fig6_20.png} 103 | \end{frame} 104 | 105 | \begin{slide}{Separating axis}{Method of separating axis}{ 106 | \item $D$ may be multiplied by a (non-zero) constant 107 | \item The projection is scaled uniformly, but no contact still translates into a separated projection 108 | \item The translation of a separating axis remains a separating axis, so we only deal with lines that go through the origin 109 | }\end{slide} 110 | 111 | \begin{frame}{Scale of separating axis} 112 | \center 113 | \includegraphics[width=8cm]{Pics/ScaleOfSeparatingAxis.png} 114 | \end{frame} 115 | 116 | \begin{frame}{Translation of separating axis} 117 | \center 118 | \includegraphics[width=8cm]{Pics/TranslationOfSeparatingAxis.png} 119 | \end{frame} 120 | 121 | % FIG OF SCALED/TRANSLATED PROJECTION 122 | 123 | \begin{slide}{Separating axis}{Method of separating axis}{ 124 | \item We now consider $C_j$ polytopes, each with 125 | \begin{itemize} 126 | \item $P_i^j$ vertices, \textit{ordered counter-clockwise} and with wrapping indices 127 | \item $E_i^j = P_{i+1}^j - P_i^j$ edges, \textit{ordered counter-clockwise} 128 | \item $N_i^j$ normals, perpendicular to the edges 129 | \end{itemize} 130 | \item Similarly we store the triangles in 3D 131 | }\end{slide} 132 | 133 | \begin{slide}{Separating axis}{Method of separating axis}{ 134 | \item There are infinite candidate directions $D$ 135 | \item Fortunately we need only consider a finite set 136 | \item In 2D, the normals of each polygon 137 | }\end{slide} 138 | 139 | \begin{frame}{Separating axis} 140 | \center 141 | \includegraphics[width=8cm]{Pics/SeparatingAxesIn2D.png} 142 | \end{frame} 143 | 144 | \begin{slide}{Separating axis algorithms}{Algorithms}{ 145 | \item Naïve algorithm 146 | \item For each normal: 147 | \begin{itemize} 148 | \item Project all vertices of both polytopes 149 | \item Compute the intervals 150 | \item Check for intersection 151 | \end{itemize} 152 | }\end{slide} 153 | 154 | \begin{slide}{Separating axis algorithms}{Algorithms}{ 155 | \item Smarter algorithm 156 | \begin{itemize} 157 | \item For each body $C_j$ 158 | \item For each normal $P_i^j, N_i^j$ 159 | \item Check if the closest vertex $P_k^l$ of the other body $C_l$ is too close to the edge 160 | \item $(P_k^l - P_i^j) \cdot N_i^j > \epsilon$ 161 | \end{itemize} 162 | }\end{slide} 163 | 164 | \begin{frame}{Separation against face} 165 | \center 166 | \includegraphics[height=5cm]{Pics/SeparationOfVertex.png} 167 | \end{frame} 168 | 169 | \begin{frame}[fragile]{Pseudo-code} 170 | \begin{lstlisting} 171 | bool TestIntersection (ConvexPolygon C0, ConvexPolygon C1) { 172 | for (i0 = C0.GetN()-1, i1 = 0; i1 < C0.GetN(); i0 = i1++) { 173 | P = C0.GetVertex(i1); 174 | D = C0.GetNormal(i0); 175 | if (WhichSide(C1,P,D) > 0) { 176 | return false; 177 | } 178 | } 179 | \end{lstlisting} 180 | \end{frame} 181 | \begin{frame}[fragile]{Pseudo-code} 182 | \begin{lstlisting} 183 | for (i0 = C1.GetN()-1, i1 = 0; i1 < C1.GetN(); i0 = i1++) { 184 | P = C1.GetVertex(i1); 185 | D = C1.GetNormal(i0); 186 | if (WhichSide(C0,P,D) > 0) { 187 | return false; 188 | } 189 | } 190 | return true; 191 | } 192 | \end{lstlisting} 193 | \end{frame} 194 | \begin{frame}[fragile]{Pseudo-code} 195 | \begin{lstlisting} 196 | int WhichSide (ConvexPolygon C, Point P, Vector D) { 197 | posCount = 0; 198 | negCount = 0; 199 | zeroCount = 0; 200 | for (i = 0; i < C.GetN(); ++i) { 201 | t = Dot(D,C.GetVertex(i) - P); 202 | if (t > 0) { posCount++; } 203 | else if (t < 0) { negCount++; } 204 | else { zeroCount++; } 205 | if ((posCount > 0 and negCount > 0) or zeroCount > 0) { return 0; } 206 | } 207 | return posCount ? 1 : -1; 208 | } 209 | \end{lstlisting} 210 | \end{frame} 211 | 212 | \begin{slide}{Separating axis algorithms}{Optimizations}{ 213 | \item Bisection on the sorted vertices 214 | \item Find the vertex closest to an edge faster 215 | }\end{slide} 216 | 217 | \begin{slide}{Separating axis algorithms}{Optimizations}{ 218 | \item 2D and 3D: BSP, Gauss map, hash table of the vertices sorted w.r.t. their direction 219 | \item Find the vertex closest to an edge much faster 220 | \item We will \textit{maybe} see this algorithm, depending on how fast the course goes 221 | }\end{slide} 222 | 223 | \begin{slide}{Separating axis in 3D}{Candidate axes}{ 224 | \item In 2D the candidate axes are just the edge normals 225 | \item In 3D the face normals are not enough 226 | \item Edge-to-edge collisions are not covered 227 | }\end{slide} 228 | 229 | \begin{frame}{Separating axis} 230 | \center 231 | \includegraphics[height=5cm]{Pics/EdgeToEdgeCross.png} 232 | \end{frame} 233 | 234 | \begin{slide}{Separating axis in 3D}{Candidate axes}{ 235 | \item Also consider edge-to-edge cross products 236 | \item Exactly the same algorithm, but with more potential axes 237 | }\end{slide} 238 | 239 | \begin{frame}{Separating axis} 240 | \center 241 | \includegraphics[height=5cm]{Pics/EdgeToEdgeCross2.png} 242 | \end{frame} 243 | 244 | \begin{frame}[fragile]{Pseudo-code} 245 | \begin{lstlisting} 246 | bool TestIntersection (ConvexPolyhedron C0, ConvexPolyhedron C1) { 247 | for (i = 0; i < C0.GetFCount(); ++i) { 248 | D = C0.GetNormal(i); 249 | ComputeInterval(C0,D,min0,max0); 250 | ComputeInterval(C1,D,min1,max1); 251 | if (max1 < min0 || max0 < min1) { return false; } 252 | } 253 | \end{lstlisting} 254 | \end{frame} 255 | \begin{frame}[fragile]{Pseudo-code} 256 | \begin{lstlisting} 257 | for (j = 0; j < C1.GetFCount(); ++j) { 258 | D = C1.GetNormal(j); 259 | ComputeInterval(C0,D,min0,max0); 260 | ComputeInterval(C1,D,min1,max1); 261 | if (max1 < min0 || max0 < min1) { return false; } 262 | } 263 | \end{lstlisting} 264 | \end{frame} 265 | \begin{frame}[fragile]{Pseudo-code} 266 | \begin{lstlisting} 267 | for (i = 0; i < C0.GetECount(); ++i) { 268 | for (j = 0; j < C1.GetECount(); ++j) { 269 | D = Cross(C0.GetEdge(i),C1.Edge(j)); 270 | ComputeInterval(C0,D,min0,max0); 271 | ComputeInterval(C1,D,min1,max1); 272 | if (max1 < min0 || max0 < min1){ return false; } 273 | } 274 | } 275 | return true; 276 | } 277 | \end{lstlisting} 278 | \end{frame} 279 | \begin{frame}[fragile]{Pseudo-code} 280 | \begin{lstlisting} 281 | void ComputeInterval (ConvexPolyhedron C, Vector D, double& min, double& max) { 282 | min = Dot(D,C.GetVertex(0)); 283 | max = min; 284 | for (i = 1; i < C.GetVCount(); ++i) { 285 | value = Dot(D,C.GetVertex(i)); 286 | if (value < min) { 287 | min = value; 288 | } else { 289 | max = value; 290 | } 291 | } 292 | } 293 | \end{lstlisting} 294 | \end{frame} 295 | 296 | \section{Moving objects} 297 | \begin{slide}{Moving objects}{Moving objects}{ 298 | \item Objects are usually moving in a game :) 299 | \item We must check for future intersections 300 | \item With some simplifying assumptions 301 | \begin{itemize} 302 | \item Rotations can be ignored (phew!) 303 | \item Interpenetration may happen a bit 304 | \end{itemize} 305 | }\end{slide} 306 | 307 | \begin{slide}{Moving objects}{Moving objects}{ 308 | \item Use the \textit{moving projection} on an axis 309 | \item Consider the \textit{relative velocity} $V = V_2 - V_1$ 310 | \item Speed of projection along $D$ is $\sigma = V \cdot D$ when $|D| = 1$ 311 | \item The distance of the minimum point must be bigger than $\sigma$ 312 | \item $\Delta x = \sigma \Delta t$ $\Delta t \frac{\Delta x}{d} = $ time of collision 313 | \item When the time of collision is outside the time of the current frame, then there is no collision 314 | }\end{slide} 315 | 316 | \begin{frame}[fragile]{Moving objects} 317 | \begin{lstlisting} 318 | bool TestIntersection (ConvexPolygon C0, Vector V0, ConvexPolygon C1, Vector V1, double tmax, double& tfirst, double& tlast) { 319 | V = V1 - V0; 320 | tfirst = 0; 321 | tlast = INFINITY; 322 | \end{lstlisting} 323 | \end{frame} 324 | \begin{frame}[fragile]{Pseudo-code} 325 | \begin{lstlisting} 326 | for (i0 = C0.GetN() - 1, i1 = 0; i1 < C0.GetN(); i0 = i1++) { 327 | D = C0.GetNormal(i0); 328 | ComputeInterval(C0,D,min0,max0); 329 | ComputeInterval(C1,D,min1,max1); 330 | speed = Dot(D,V); 331 | if (NoIntersect(tmax,speed,min0,max0,min1,max1,tfirst, tlast)) { return false; } 332 | } 333 | \end{lstlisting} 334 | \end{frame} 335 | \begin{frame}[fragile]{Pseudo-code} 336 | \begin{lstlisting} 337 | for (i0 = C1.N - 1, i1 = 0; i1 < C1.N; i0 = i1++) { 338 | D = C1.GetNormal(i0); 339 | ComputeInterval(C0,D,min0,max0); 340 | ComputeInterval(C1,D,min1,max1); 341 | speed = Dot(D,V); 342 | if (NoIntersect(tmax,speed,min0,max0,min1,max1,tfirst, tlast)) { return false; } 343 | } 344 | return true; 345 | } 346 | \end{lstlisting} 347 | \end{frame} 348 | 349 | \begin{slide}{Moving objects}{Moving objects}{ 350 | \item if the polygons intersect at a first time $t_{\text{first}}$, then there is a separating axis $\forall t. t < t_{\text{first}}$ 351 | \item if the polygons intersect at a last time $t_{\text{last}}$, then there is a separating axis $\forall t. t > t_{\text{last}}$ 352 | \item if for all direction $t_{\text{first}} < t_{\text{last}}$, then the polygons intersect at time $t_{\text{first}}$ (check against $\Delta t$) 353 | \item if for all direction $t_{\text{first}} > t_{\text{last}}$, then the polygons do not intersect (all axis must intersect at the same time!) 354 | }\end{slide} 355 | 356 | \begin{frame}[fragile]{Pseudo-code} 357 | \begin{lstlisting} 358 | bool NoIntersect (double tmax, double speed, double min0, double max0, double min1, double max1, double& tfirst, double& tlast) { 359 | if (max1 < min0) { 360 | if (speed <= 0) { return true; } 361 | t = (min0 - max1)/speed; 362 | if (t > tfirst) { tfirst = t; } 363 | if (tfirst > tmax) { return true; } 364 | t = (max0 - min1)/speed; 365 | if (t < tlast) { tlast = t; } 366 | if (tfirst > tlast) { return true; } 367 | \end{lstlisting} 368 | \end{frame} 369 | \begin{frame}[fragile]{Pseudo-code} 370 | \begin{lstlisting} 371 | } else if ( max0 < min1 ) { 372 | if (speed >= 0) { return true; } 373 | t = (max0 - min1)/speed; 374 | if (t > tfirst) { tfirst = t; } 375 | if (tfirst > tmax) { return true; } 376 | t = (min0 - max1)/speed; 377 | if (t < tlast) { tlast = t; } 378 | if (tfirst > tlast) { return true; } 379 | \end{lstlisting} 380 | \end{frame} 381 | \begin{frame}[fragile]{Pseudo-code} 382 | \begin{lstlisting} 383 | } else { 384 | if (speed > 0) { 385 | t = (max0 - min1)/speed; 386 | if (t < tlast) { tlast = t; } 387 | if (tfirst > tlast) { return true; } 388 | } else if (speed < 0) { 389 | t = (min0 - max1)/speed; 390 | if (t < tlast) { tlast = t; } 391 | if (tfirst > tlast) { return true; } 392 | } 393 | } 394 | return false; 395 | } 396 | \end{lstlisting} 397 | \end{frame} 398 | 399 | \section{Finding the contact manifold} 400 | \begin{slide}{Finding intersections}{Contact manifold}{ 401 | \item The collision response system needs the intersections 402 | \item So far we have built \texttt{TestIntersection} 403 | \item Huge numbers of possible algorithms for this (\textbf{GJK} is the most diffuse) 404 | \item We now \textit{sketch} a description of one intuitive algorithm 405 | }\end{slide} 406 | 407 | \begin{slide}{Finding intersections}{Finding intersections}{ 408 | \item When the intersection is found at time $T$, before returning 409 | \item We move the bodies forward with the respective velocities 410 | \item We compute and return (an approximation) of the contact set 411 | \item May be face-to-vertex or edge-to-edge 412 | }\end{slide} 413 | 414 | \begin{slide}{Finding intersections}{Finding intersections for SAT failures}{ 415 | \item Identify \textit{reference face} ($D=N$) and \textit{incident face} (most anti-parallel to $D$) 416 | \item Clip incident face against edges of reference face 417 | \item Keep all resulting vertices \textit{below or on} the reference face 418 | }\end{slide} 419 | 420 | \begin{frame}{Reference face} 421 | \center 422 | \includegraphics[height=5cm]{Pics/ReferenceFace.png} 423 | \end{frame} 424 | 425 | \begin{frame}{Reference face sideways} 426 | \center 427 | \includegraphics[height=5cm]{Pics/ReferenceFaceSideways.png} 428 | \end{frame} 429 | 430 | \begin{slide}{Finding intersections}{Edge-to-edge SAT failures}{ 431 | \item Just intersect the edges 432 | }\end{slide} 433 | 434 | \begin{slide}{Finding intersections}{Contact manifold}{ 435 | \item Two vertices are enough in 2D 436 | \item Three vertices are enough in 3D 437 | \item Too many more vertices do not improve stability (a few might) 438 | \item We always choose the ones penetrating the most 439 | \item Deterministic as much as possible (contact caching) 440 | }\end{slide} 441 | 442 | \begin{frame}{Contact manifold} 443 | \center 444 | \includegraphics[height=5cm]{Pics/ContactManifold.png} 445 | \end{frame} 446 | 447 | \begin{slide}{Finding intersections}{Clipping and intersections}{ 448 | \item Sutherland-Hogman algorithm for clipping 449 | \item Edge-to-edge intersection 450 | }\end{slide} 451 | 452 | \begin{slide}{Finding intersections}{Clipping faces}{ 453 | \item Project planes from the edges of the reference face 454 | \item Vertices of the incident face \textit{inside} all planes are contact points 455 | \item Reference plane with incident edge intersections are more contact points 456 | \item Keep a subset of the points: (most inside the reference face) 457 | }\end{slide} 458 | 459 | \begin{slide}{Finding intersections}{Clipping a vertex}{ 460 | \item Given a plane $\langle N,d \rangle$ where $N$ is the normal of the plane and $d$ is the minimum distance of the plane from the origin 461 | \item We determine the side of the plane on which a vertex $V$ lies with the sign of $P \cdot N - d$ 462 | }\end{slide} 463 | 464 | \begin{frame}{Clipping} 465 | \center 466 | \includegraphics[width=10cm]{Pics/PlaneVertexClipping.png} 467 | \end{frame} 468 | 469 | \begin{slide}{Finding intersections}{Clipping a vertex}{ 470 | \item All signs of plane-vertex distance must be the same 471 | \item The planes must all be facing inward (or outward) 472 | }\end{slide} 473 | 474 | \begin{slide}{Finding intersections}{Clipping an edge}{ 475 | \item Given a plane $\langle V \cdot N = d \rangle$ and an edge $V = A + \alpha B$ ($0 \leq \alpha \leq 1$) 476 | \item We put these equations together: $(A + \alpha B) \cdot N = d$ and solve for $\alpha = \frac{d - A \cdot N}{B \cdot N}$ 477 | }\end{slide} 478 | 479 | \begin{slide}{Finding intersections}{Clipping an edge}{ 480 | \item $\alpha = \frac{d - A \cdot N}{B \cdot N}$ 481 | \item Watch for lack of solutions 482 | \begin{itemize} 483 | \item If $|B \cdot N| \leq \epsilon$ then edge and plane are parallel 484 | \item No intersection possible 485 | \end{itemize} 486 | }\end{slide} 487 | 488 | \begin{frame}{Clipping} 489 | \center 490 | \includegraphics[height=3cm]{Pics/PlaneEdgeClipping.png} 491 | \end{frame} 492 | 493 | \begin{slide}{Finding intersections}{Edge-to-edge intersections}{ 494 | \item We consider two edges: $P_1 + \alpha D_1$ and $P_2 + \beta D_2$ 495 | \item Intersection in 3D is rather rare 496 | \item We look for the shortest connecting axis: $P_a = P_1 + \mu_a D_1$ and $P_b = P_2 + \mu_b D_2$ 497 | }\end{slide} 498 | 499 | \begin{frame}{Clipping} 500 | \center 501 | \includegraphics[height=5cm]{Pics/EdgeEdgeIntersection.png} 502 | \end{frame} 503 | 504 | \begin{slide}{Finding intersections}{Edge-to-edge intersections}{ 505 | \item The connecting axis is perpendicular to the both edges, so 506 | $\left\{ \begin{matrix} 507 | (P_a - P_b) \cdot D_1 &=& 0 \\ 508 | (P_a - P_b) \cdot D_2 &=& 0 509 | \end{matrix} \right.$ 510 | \pause 511 | \item Expanding $P_a$ and $P_b$ results in 512 | $\left\{ \begin{matrix} 513 | (P_1 + \mu_a D_1 - P_2 - \mu_b D_2) \cdot D_1 &=& 0 \\ 514 | (P_1 + \mu_a D_1 - P_2 - \mu_b D_2) \cdot D_2 &=& 0 515 | \end{matrix} \right.$ 516 | }\end{slide} 517 | 518 | \begin{slide}{Finding intersections}{Edge-to-edge intersections}{ 519 | \item This is just a system with two unknowns and two equations; the dot products turn everything into numbers: 520 | $\left\{ \begin{matrix} 521 | (P_1 + \mu_a D_1 - P_2 - \mu_b D_2) \cdot D_1 &=& 0 \\ 522 | (P_1 + \mu_a D_1 - P_2 - \mu_b D_2) \cdot D_2 &=& 0 523 | \end{matrix} \right.$ 524 | \item The full (tedious) derivation of the solutions is shown in \url{http://paulbourke.net/geometry/pointlineplane/} 525 | }\end{slide} 526 | 527 | \section{Assignment} 528 | \begin{slide}{Assignment}{Assignment}{ 529 | \item Before the end of next week 530 | \item Group-work archive/video on Natschool or uploaded somewhere else and linked in your report 531 | \item Individual report by each of you on Natschool 532 | \item Build a narrow phase collision detector that can compute the contact manifold 533 | }\end{slide} 534 | 535 | \begin{frame}{That's it} 536 | \center 537 | \fontsize{18pt}{7.2}\selectfont 538 | Thank you! 539 | \end{frame} 540 | 541 | \end{document} 542 | 543 | 544 | \begin{slide}{SECTION}{SLIDE}{ 545 | \item i 546 | }\end{slide} 547 | 548 | \begin{frame}[fragile]{SLIDE} 549 | \begin{lstlisting} 550 | CODE 551 | \end{lstlisting} 552 | \end{frame} 553 | 554 | \begin{frame}{SLIDE} 555 | \center 556 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 557 | \end{frame} 558 | -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/ContactManifold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/ContactManifold.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/ConvexPolyhedra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/ConvexPolyhedra.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/ConvexPolyhedron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/ConvexPolyhedron.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/EdgeEdgeIntersection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/EdgeEdgeIntersection.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/EdgeToEdgeCross.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/EdgeToEdgeCross.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/EdgeToEdgeCross2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/EdgeToEdgeCross2.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/Fig6_19.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/Fig6_19.PNG -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/Fig6_20.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/Fig6_20.PNG -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/PlaneEdgeClipping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/PlaneEdgeClipping.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/PlaneVertexClipping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/PlaneVertexClipping.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/ReferenceFace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/ReferenceFace.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/ReferenceFaceSideways.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/ReferenceFaceSideways.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/Rel_Vel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/Rel_Vel.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/ScaleOfSeparatingAxis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/ScaleOfSeparatingAxis.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/SeparatingAxesIn2D.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/SeparatingAxesIn2D.PNG -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/SeparationOfVertex.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/SeparationOfVertex.PNG -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/Stacking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/Stacking.png -------------------------------------------------------------------------------- /Slides/Lecture 5/Pics/TranslationOfSeparatingAxis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 5/Pics/TranslationOfSeparatingAxis.png -------------------------------------------------------------------------------- /Slides/Lecture 5/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 6/Lecture 6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 6/Lecture 6.pdf -------------------------------------------------------------------------------- /Slides/Lecture 6/Lecture 6.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Building a physics engine - part 3: collision response} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{frame}{Table of contents} 25 | \tableofcontents 26 | \end{frame} 27 | 28 | \section{Collision response} 29 | \begin{slide}{Collision response}{Collision response system}{ 30 | \item Solving physical constraints in addition to the equations of motion 31 | \item Constraints are mostly contact constraints, but also 32 | \begin{itemize} 33 | \item Friction constraints 34 | \item Distance constraints 35 | \item Joint angle constraints 36 | \item ... 37 | \end{itemize} 38 | \item The ideal collision response system deals with all of these 39 | }\end{slide} 40 | 41 | \begin{slide}{Collision response}{Naïve take}{ 42 | \item Apply the constraints to the objects in pairs 43 | \item Use the laws of \textit{conservation of motion} for each collision; $P_0$ is the point of collision, $x_A$ and $x_B$ are the centres of mass of the objects, $v^{-1}$ is the pre-impact velocity of the objects, $v^+$ is the post-impact velocity of the objects 44 | \begin{itemize} 45 | \item $f = \frac{-(1 + \epsilon)(N_0 \cdot (v_A^{-1} - v_B^{-1})) + (\omega_A^- \cdot (r_A \times N_0) - \omega_B^- \cdot (r_B \times N_0)))}{1/m_A + 1/m_B + (r_A \times N_0)^T J_A^{-1} (r_A \times N_0) + (r_B \times N_0)^T J_B^{-1} (r_B \times N_0)}$ 46 | \item $r_A = P_0 - x_A$, $r_B = P_0 - x_B$ 47 | \item $v_A^+ = v_A^- + \frac{f N_0}{m_A}$ 48 | \item $\omega_A^+ = \omega_A^- + J_A^- (r_A \times (f N_0))$ 49 | \end{itemize} 50 | \item Push away from interpenetration as long as interpenetration exists 51 | }\end{slide} 52 | 53 | \begin{slide}{Collision response}{Naïve take}{ 54 | \item Jitters a lot, and does not support stacking 55 | \item May be acceptable in very sparse scenarios (space/flight simulator) 56 | }\end{slide} 57 | 58 | \begin{slide}{Collision response}{Naïve take number 2}{ 59 | \item Apply the constraints to the objects in pairs 60 | \item Apply again during the same tick 61 | \item Average/combine the various impulses 62 | \item Push apart objects so they do not penetrate 63 | \pause 64 | \item Constraints are still broken 65 | \item \textit{Hack-y method}, gives no guarantees 66 | \item Still does not support stacking 67 | }\end{slide} 68 | 69 | \section{Constrained dynamics} 70 | \begin{slide}{Constrained dynamics}{Unconstrained kinematics}{ 71 | \item A rigid body is characterised by 72 | \item $\dot x = v$ 73 | \item $\dot q = \frac{1}{2}wq$ 74 | }\end{slide} 75 | 76 | \begin{slide}{Constrained dynamics}{Unconstrained kinematics}{ 77 | \item For a system of $N$ bodies, we can define the system derivative as 78 | $$V = \left[ \begin{matrix} 79 | v_1 \\ \omega_1 \\ \vdots \\ v_N \\ \omega_N 80 | \end{matrix} \right]$$ 81 | }\end{slide} 82 | 83 | \begin{slide}{Constrained dynamics}{Constraints}{ 84 | \item Our system allows \textit{pairwise} constraints between bodies 85 | \item The $k$-th constraint, between bodies $i$ and $j$, has the form $C_k(x_i,q_i,x_j,q_j) = 0$ 86 | \item The vector $C$ holds all the constraints. $C = 0$, or $C(x) = 0$, is a function of the state vector, so by the chain rule $\dot C = J V = 0$ 87 | }\end{slide} 88 | 89 | \begin{slide}{Constrained dynamics}{Constraint forces}{ 90 | \item Each constraint causes a reaction force $f_c$ and a reaction torque $\tau_c$ 91 | \item The vector of all reaction forces is $$F_c = \left[ \begin{matrix} 92 | f_{c1} \\ \tau_{c1} \\ \vdots \\ f_{cN} \\ \tau_{cN} 93 | \end{matrix} \right]$$ 94 | }\end{slide} 95 | 96 | \begin{slide}{Constrained dynamics}{Constraint forces}{ 97 | \item We know that $\dot C = J V = 0$ 98 | \item $J V = \left[ \begin{matrix} 99 | J_1 \cdot V \\ \vdots \\ J_M \cdot V \\ 100 | \end{matrix} \right] = 0$ 101 | \item This means that $V$ is orthogonal to each row of $J$ 102 | }\end{slide} 103 | 104 | \begin{slide}{Constrained dynamics}{Constraint forces}{ 105 | \item Constraint forces perform no work, so $F_c \cdot V = 0$ 106 | }\end{slide} 107 | 108 | \begin{frame}{Principle of virtual work} 109 | \center 110 | \includegraphics[width=7cm]{Pics/VirtualWork.png} 111 | \end{frame} 112 | 113 | \begin{slide}{Constrained dynamics}{Constraint forces}{ 114 | \item We can use $F_c = J^T \lambda$ for some vector $\lambda$ of undetermined force multipliers 115 | \item $F_c \cdot V = J^T \lambda \cdot V = (\sum_i J_i \lambda_i) \cdot V = \sum_i J_i \cdot V \lambda_i = \sum_i 0 \lambda_i = 0$ 116 | }\end{slide} 117 | 118 | \begin{slide}{Constrained dynamics}{Constraint forces}{ 119 | \item We will thus compute the matrix $J$ of constraints from the collision system 120 | \item We then solve for $\lambda$, compute $F_c$, and finally obtain $V$ 121 | }\end{slide} 122 | 123 | \section{Setting up the constraints} 124 | \begin{slide}{Constrained dynamics}{Distance constraints}{ 125 | \item The simplest constraint is a distance constraint 126 | \item Two points of two bodies must remain at a given distance 127 | \item $C(x_i,q_i,x_j,q_j) = \frac{1}{2}(|p_j-p_i|^2 - L^2) = 0$ 128 | \item If we derive this, we get $\dot C(x_i,q_i,x_j,q_j) = \underbrace{(p_j-p_i)}_{d}(v_j + \omega_j \times r_j - v_i - \omega_i \times r_i)$ 129 | \item We split this into a row for $J$ and a part of $V$: 130 | \item $\dot C(x_i,q_i,x_j,q_j) = \underbrace{\left[ -d^T\ -(r_i \times d)^T\ d^T\ (r_j \times d)^T \right]}_{\text{a row of }J} \underbrace{\left[ v_i\ \omega_i\ v_j\ \omega_j \right]^T}_{\text{some columns of } V}$ 131 | }\end{slide} 132 | 133 | \begin{frame}{Distance constraint} 134 | \center 135 | \includegraphics[width=7cm]{Pics/DistanceConstraint.png} 136 | \end{frame} 137 | 138 | \begin{slide}{Constrained dynamics}{Distance constraints}{ 139 | \item We are abusing the notation; the ``row of $J$'' also contains many zeroes $(6 \times (N_{\text{bodies}} - 2))$ 140 | \item The only columns that are not zeroed are those corresponding to the bodies $i$ and $j$ 141 | \item $\dot C(x_i,q_i,x_j,q_j) = \underbrace{\left[ \dots\ 0\ -d^T\ -(r_i \times d)^T\ 0\ \dots\ 0\ d^T\ (r_j \times d)^T\ \dots\ 0\right]}_{\text{a row of }J} V$ 142 | }\end{slide} 143 | 144 | \begin{slide}{Constrained dynamics}{Contact constraints}{ 145 | \item We may also model contact constraints 146 | \item The contact constraint measures the object separation; it is negative in case of overlap 147 | \item $C(x_i,q_i,x_j,q_j) = (x_j + r_j - x_i - r_i) \cdot n_i = 0$ 148 | \item $\dot C(x_i,q_i,x_j,q_j) = (v_j + \omega_j \times r_j - v_i - \omega_i \times r_i) \cdot n_i + (x_j + r_j - x_i - r_i) \cdot \omega_i \times n_i$ 149 | \item We assume that both penetration and angular velocity are small, so we ignore the second term 150 | \item $\dot C(x_i,q_i,x_j,q_j) \approx (v_j + \omega_j \times r_j - v_i - \omega_i \times r_i) \cdot n_i$ 151 | }\end{slide} 152 | 153 | \begin{frame}{Contact constraint} 154 | \center 155 | \includegraphics[height=5cm]{Pics/ContactConstraint.png} 156 | \end{frame} 157 | 158 | \begin{slide}{Constrained dynamics}{Contact constraints}{ 159 | \item We can now separate $\dot C$ into $J$ and $V$: 160 | \item $\dot C(x_i,q_i,x_j,q_j) = (v_j + \omega_j \times r_j - v_i - \omega_i \times r_i) \cdot n_i = \left[ -n_i^T\ -(r_i \times n_i)^T\ n_i^T\ (r_j \times n_i)^T\ \right] \left[ v_i\ \omega_i\ v_j\ \omega_j \right]^T$ 161 | }\end{slide} 162 | 163 | \begin{slide}{Constrained dynamics}{Contact constraints}{ 164 | \item Notice that the force between bodies in contact can push them apart, but not pull them together 165 | \item This means that $0 \leq \lambda_k \leq +\infty$, where $k$ is the constraint index for a contact constraint 166 | }\end{slide} 167 | 168 | \begin{slide}{Constrained dynamics}{Contact constraints}{ 169 | \item In some cases penetration might happen anyway 170 | \item Numerical errors or issues with discrete steps 171 | \item We allow the velocity to be augmented with a \textit{pushing factor} which is proportional to the penetration 172 | \item This means that for contact constraints $J_i V = -\ \beta C_i$, for $\beta \leq \frac{1}{\Delta t}$ 173 | }\end{slide} 174 | 175 | \begin{slide}{Constrained dynamics}{Friction constraints}{ 176 | \item Friction constraints are very similar to contact constraints 177 | \item Friction happens along the tangent plane, so we have two constraints (one for $u_i = T$ and one for $u_j = B$) 178 | \begin{itemize} 179 | \item $\dot C_{u_i}(x_i,q_i,x_j,q_j) = (v_j + \omega_j \times r_j - v_i - \omega_i \times r_i) \cdot u_i = \left[ -u_i^T\ -(r_i \times u_i)^T\ u_i^T\ (r_j \times u_i)^T\ \right] \left[ v_i\ \omega_i\ v_j\ \omega_j \right]^T$ 180 | \item $\dot C_{u_j}(x_i,q_i,x_j,q_j) = (v_j + \omega_j \times r_j - v_i - \omega_i \times r_i) \cdot u_j = \left[ -u_j^T\ -(r_i \times u_j)^T\ u_j^T\ (r_j \times u_j)^T\ \right] \left[ v_i\ \omega_i\ v_j\ \omega_j \right]^T$ 181 | \end{itemize} 182 | }\end{slide} 183 | 184 | \begin{slide}{Constrained dynamics}{Friction constraints}{ 185 | \item We must also bound the friction value (this is an approximation) to take the friction coefficient into account 186 | \item $-\mu m_c g \leq \lambda_{u_1} \leq \mu m_c g$ and $-\mu m_c g \leq \lambda_{u_2} \leq \mu m_c g$, where $m_c$ is the mass assigned to the contact point 187 | }\end{slide} 188 | 189 | \section{Equations of motion} 190 | \begin{slide}{Equations of motion}{Equations of motion}{ 191 | \item We now integrate our constraint system with the equations of motion 192 | \item We know the $Newton-Euler$ equations of motion are 193 | $\begin{matrix} 194 | m \dot v & = & F & = & f_c + f_{\text{ext}} \\ 195 | I \dot w & = & \tau & = & \tau_c + \tau_{\text{ext}} \\ 196 | \end{matrix}$ 197 | }\end{slide} 198 | 199 | \begin{slide}{Equations of motion}{Equations of motion}{ 200 | \item We can define a single, big matrix for all the bodies 201 | $M = \left( \begin{matrix} 202 | m_1 E _{3 \times 3} & 0 & \dots & 0 & 0 \\ 203 | 0 & I_1 & \dots & 0 & 0 \\ 204 | \vdots & \vdots & \ddots & \vdots & \vdots \\ 205 | 0 & \dots & 0 & m_n E _{3 \times 3} & 0 \\ 206 | 0 & \dots & 0 & 0 & I_n \\ 207 | \end{matrix} \right)$ 208 | \item $E_{3 \times 3}$ is just the identity matrix 209 | }\end{slide} 210 | 211 | \begin{slide}{Equations of motion}{Equations of motion}{ 212 | \item We can easily invert this matrix 213 | $M^{-1} = \left( \begin{matrix} 214 | (m_1 E _{3 \times 3})^{-1} & 0 & \dots & 0 & 0 \\ 215 | 0 & I_1^{-1} & \dots & 0 & 0 \\ 216 | \vdots & \vdots & \ddots & \vdots & \vdots \\ 217 | 0 & \dots & 0 & (m_n E _{3 \times 3})^{-1} & 0 \\ 218 | 0 & \dots & 0 & 0 & I_n^{-1} \\ 219 | \end{matrix} \right)$ 220 | }\end{slide} 221 | 222 | \begin{slide}{Equations of motion}{Equations of motion}{ 223 | \item We can define a single, big vector for all the external forces 224 | $F_{\text{ext}} = \left[ \begin{matrix} 225 | f_{\text{ext}1} \\ 226 | \tau_{\text{ext}1} \\ 227 | \vdots \\ 228 | f_{\text{ext}N} \\ 229 | \tau_{\text{ext}N} \\ 230 | \end{matrix} \right]$ 231 | }\end{slide} 232 | 233 | \begin{slide}{Equations of motion}{Equations of motion}{ 234 | \item Since we know that $F_C = J^T \lambda$, we can rewrite the equations of motion for $n$ bodies as 235 | $\left\{ \begin{matrix} 236 | M \dot V & = & J^T \lambda + F_{\text{ext}} \\ 237 | JV & = & \epsilon \\ 238 | \end{matrix} \right.$ 239 | \item $\epsilon$ is the vector of force offsets which allows contact forces to perform work 240 | \item We have too many unknowns: $V$, $\dot V$, and $\lambda$ 241 | }\end{slide} 242 | 243 | \begin{slide}{Equations of motion}{Equations of motion}{ 244 | \item We approximate $\dot V \approx \frac{V_2 - V_1}{\Delta t}$ 245 | \item We replace $\dot V$ 246 | $\left\{\begin{matrix} 247 | M \frac{V_2 - V_1}{\Delta t} & = & J^T \lambda + F_{\text{ext}} \\ 248 | JV_2 & = & \epsilon \\ 249 | \end{matrix} \right.$ 250 | \item We solve for $V_2$ 251 | $\left\{ \begin{matrix} 252 | V_2 & = & \Delta t M^{-1}(J^T \lambda + F_{\text{ext}}) + V_1\\ 253 | V_2 & = & J^T \epsilon 254 | \end{matrix} \right.$ 255 | }\end{slide} 256 | 257 | \begin{slide}{Equations of motion}{Equations of motion}{ 258 | \item We can now finish solving for $\lambda$ 259 | \item $J^T \epsilon = \Delta t M^{-1}(J^T \lambda + F_{\text{ext}}) + V_1$ 260 | \item $J^T \epsilon - V_1 - \Delta t M^{-1}F_{\text{ext}} = \Delta t M^{-1}(J^T \lambda)$ 261 | \item $\frac{\epsilon}{\Delta t} - J V_1 - \Delta t J M^{-1}F_{\text{ext}} = J M^{-1} J^T \lambda$ 262 | }\end{slide} 263 | 264 | \begin{slide}{Equations of motion}{Equations of motion}{ 265 | \item The equation $\frac{\epsilon}{\Delta t} - J V_1 - \Delta t J M^{-1}F_{\text{ext}} = J M^{-1} J^T \lambda$ admits infinite solutions; this is due to redundant constraints, such as a table with more than three legs 266 | \item The force combinations that solve the system are usually infinite 267 | }\end{slide} 268 | 269 | \begin{slide}{Equations of motion}{Equations of motion}{ 270 | \item Once $\lambda$ is computed, we can determine $F_c$, $F$, and then $V_2$ 271 | \item A regular integration step is then performed with the new velocities $V_2$ 272 | }\end{slide} 273 | 274 | \section{Iterative solution of a system of equations} 275 | \begin{slide}{Iterative solution}{System of equations}{ 276 | \item The equation $\frac{\epsilon}{\Delta t} - J V_1 - \Delta t J M^{-1}F_{\text{ext}} = J M^{-1} J^T \lambda$ can be restated in simpler form 277 | \item $\underbrace{\frac{\epsilon}{\Delta t} - J V_1 - \Delta t J M^{-1}F_{\text{ext}}}_{b} = \underbrace{J M^{-1} J^T}_{A} \underbrace{\lambda}_{x}$ 278 | \item $A x = b$ for some $A,b$ 279 | \item These systems can be solved iteratively with a method such as Projected Gauss-Seidel (PGS) 280 | }\end{slide} 281 | 282 | \begin{frame}[fragile]{(Projected) Gauss-Seidel} 283 | \begin{lstlisting}[mathescape=true] 284 | while not converged 285 | $\Delta x_i$ = $(b_i - \sum_j a_{ij} x_j) / A_{ii}$ 286 | $x_i$ = clamp$(x_i + \Delta x_i, min_i, max_i)$ 287 | \end{lstlisting} 288 | \end{frame} 289 | 290 | \begin{slide}{Iterative solution}{Sparse matrices}{ 291 | \item Remember that $A$ is going to be very sparse 292 | \item You may optimize the summation $\Delta x_i$ \texttt{=} $(b_i - \sum_j a_{ij} x_j) / A_{ii}$ a lot by ignoring the zero entries of $A$ 293 | }\end{slide} 294 | 295 | \section{Contact caching} 296 | \begin{slide}{Contact caching}{Contact caching}{ 297 | \item PGS is faster the closer the initial $x$ vector is to the solution 298 | \item If we store previous contact points and their $\lambda_i$ values, PGS converges sooner 299 | \item Just be aware of this 300 | \begin{itemize} 301 | \item Also be aware that it is rather hard to build in practice 302 | \item If you attempt it, chances of success may be low 303 | \end{itemize} 304 | }\end{slide} 305 | 306 | \section{Assignment} 307 | \begin{slide}{Assignment}{Assignment}{ 308 | \item Before the end of next week 309 | \item Group-work archive/video on Natschool or uploaded somewhere else and linked in your report 310 | \item Individual report by each of you on Natschool 311 | \item Build a collision response system that supports collisions between multiple objects 312 | }\end{slide} 313 | 314 | \begin{frame}{That's it} 315 | \center 316 | \fontsize{18pt}{7.2}\selectfont 317 | Thank you! 318 | \end{frame} 319 | 320 | \end{document} 321 | 322 | 323 | \begin{slide}{SECTION}{SLIDE}{ 324 | \item i 325 | }\end{slide} 326 | 327 | \begin{frame}[fragile]{SLIDE} 328 | \begin{lstlisting} 329 | CODE 330 | \end{lstlisting} 331 | \end{frame} 332 | 333 | \begin{frame}{SLIDE} 334 | \center 335 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 336 | \end{frame} 337 | -------------------------------------------------------------------------------- /Slides/Lecture 6/Pics/ContactConstraint.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 6/Pics/ContactConstraint.PNG -------------------------------------------------------------------------------- /Slides/Lecture 6/Pics/DistanceConstraint.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 6/Pics/DistanceConstraint.PNG -------------------------------------------------------------------------------- /Slides/Lecture 6/Pics/VirtualWork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 6/Pics/VirtualWork.png -------------------------------------------------------------------------------- /Slides/Lecture 6/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 7/Lecture 7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 7/Lecture 7.pdf -------------------------------------------------------------------------------- /Slides/Lecture 7/Lecture 7.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Building a physics engine - part 4: broad phase of collision detection} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{frame}{Table of contents} 25 | \tableofcontents 26 | \end{frame} 27 | 28 | \section{Broad phase of collision detection} 29 | \begin{slide}{Broad phase of collision detection}{Increasing performance, in general}{ 30 | \item What is the fastest instruction? 31 | \pause 32 | \item The one that is not run! 33 | }\end{slide} 34 | 35 | \begin{slide}{Broad phase of collision detection}{Increasing performance, in collision detection}{ 36 | \item How do we increase performance in a collision detection system? 37 | \item Quickly and cheaply exclude pairs of colliders 38 | \item Process known as \textit{collision culling} 39 | \begin{itemize} 40 | \item We \textit{ensure lack} of collisions 41 | \item \textit{Presence is ensured} only during narrow phase 42 | \end{itemize} 43 | \item Akin to frustum/occlusion culling 44 | }\end{slide} 45 | 46 | \section{Bounding spheres} 47 | \begin{slide}{Collision culling}{Bounding spheres}{ 48 | \item An obvious choice is bounding spheres 49 | \item Identical w.r.t. rotation 50 | \item Fast to check against other spheres 51 | }\end{slide} 52 | 53 | \begin{slide}{Collision culling}{Intersection of bounding spheres}{ 54 | \item Two spheres, $\langle C_0, r_0 \rangle$ and $\langle C_1, r_1 \rangle$ 55 | \item Intersection when $|C_1 - C_0| \leq r_1 + r_0$ 56 | \item Intersection also when $|C_1 - C_0|^2 \leq (r_1 + r_0)^2$ 57 | }\end{slide} 58 | 59 | \begin{slide}{Collision culling}{Intersection of bounding spheres}{ 60 | \item If the spheres are moving, then we can increase their radii by their speed 61 | \item Or we can project their relative speed 62 | \pause 63 | \item $\sigma = |(V_1 - V_2) \cdot \frac{C_1 - C_0}{|C_1 - C_0|}|$ 64 | \item $|C_1 - C_0| \leq r_1 + r_0 + \sigma$ 65 | }\end{slide} 66 | 67 | \begin{frame}{Moving spheres} 68 | \center 69 | \includegraphics[height=5cm]{Pics/MovingSpheres.png} 70 | \end{frame} 71 | 72 | \section{Space partitioning} 73 | \begin{slide}{Space partitioning}{Space partitioning}{ 74 | \item We can also decompose space in axis-aligned-bounding-boxes (``bins'') 75 | \item Even earlier no-collision determination 76 | \item This would reduce the number of sphere-to-sphere checks 77 | }\end{slide} 78 | 79 | \begin{frame}{SLIDE} 80 | \center 81 | \includegraphics[height=5cm]{Pics/SpacePartitioning.png} 82 | \end{frame} 83 | 84 | \begin{slide}{Space partitioning}{Space partitioning}{ 85 | \item We can divide space in \textit{bins}; each bin is an AABB 86 | \item Sphere intersection with an AABB bounded by points $L$ and $U$ 87 | \item No intersection if $|C_j - L_j| \leq r_j + \sigma_j$ or $C_j - U_j| \leq r_j + \sigma_j$ for all axes $j = x,y,z$ 88 | }\end{slide} 89 | 90 | \begin{slide}{Space partitioning}{Space partitioning}{ 91 | \item When a sphere moves, it only moves to a neighbouring bin; less checks 92 | \item We can find the right bin directly with modulus operations (hashing) 93 | }\end{slide} 94 | 95 | \section{Bounding boxes} 96 | \begin{slide}{Axis aligned bounding boxes}{AABB intersection}{ 97 | \item A simple and powerful algorithm exists for determining intersection groups of AABBs 98 | \item It is particularly fast, especially if the AABBs do not move too much between frames 99 | }\end{slide} 100 | 101 | \begin{slide}{Axis aligned bounding boxes}{AABB intersection}{ 102 | \item Update AABBs (if needed) 103 | \item Insertion sort the extremes of each box; one list for every axis (2 for 2D, 3 for 3D, etc.) 104 | \begin{itemize} 105 | \item After the first frame the list is \textit{nearly sorted} 106 | \item $O(n)$ complexity 107 | \end{itemize} 108 | }\end{slide} 109 | 110 | \begin{slide}{Axis aligned bounding boxes}{AABB intersection}{ 111 | \item Run sweep algorithm 112 | \begin{itemize} 113 | \item Active intervals $= \emptyset$ 114 | \item When a beginning value is encountered, add it as intersecting all active intervals; add it to active intervals 115 | \item When end value is encountered, remove it from the active intervals 116 | \end{itemize} 117 | \item Intersections must be confirmed across all axes 118 | }\end{slide} 119 | 120 | \begin{slide}{Oriented bounding boxes}{OBB}{ 121 | \item An OBB is characterized by a center and three directions (columns of the rotation matrix) 122 | \item The vertices are $P = C + \sigma_0 e_0 U_0 + \sigma_1 e_1 U_1 + \sigma_2 e_2 U_2$ 123 | \begin{itemize} 124 | \item $\sigma_i = 1$ or $\sigma_i = -1$ 125 | \item $e_i$ are the half extents 126 | \end{itemize} 127 | }\end{slide} 128 | 129 | \begin{slide}{Oriented bounding boxes}{OBB SAT}{ 130 | \item With the separating axis test, it may seem that we need to test $6$ face normals for one, $6$ for the other, and $12^2 = 144$ edge pair cross products 131 | \item That's quite a lot! 132 | }\end{slide} 133 | 134 | \begin{slide}{Oriented bounding boxes}{OBB SAT}{ 135 | \item The OBB is symmetric, so many tests are redundant 136 | \begin{itemize} 137 | \item Three unique face directions 138 | \item Three unique edge directions 139 | \end{itemize} 140 | \item The minimum number of required tests is $3$ face normals for one, $3$ for the other, and $3^2 = 9$ edge pair cross products 141 | }\end{slide} 142 | 143 | \begin{slide}{Oriented bounding boxes}{OBB SAT}{ 144 | \item We project both OBBs onto one of the unique potential separating directions $Q + tD$ 145 | \item We look for an extremal vertex such that $\max_P D \cdot (P - Q)$ 146 | \item $D \cdot (P - Q) = D \cdot (C + \sigma_0 e_0 U_0 + \sigma_1 e_1 U_1 + \sigma_2 e_2 U_2 - Q)$ 147 | }\end{slide} 148 | 149 | \begin{slide}{Oriented bounding boxes}{OBB SAT}{ 150 | \item We are maximizing, so we do not try all the $\sigma_i$ combinations 151 | \begin{eqnarray} 152 | D \cdot (P - Q) &=& D \cdot (C + \sigma_0 e_0 U_0 + \dots - Q) \\ 153 | &=& D \cdot (C - Q) + \sigma_0 e_0 D \cdot U_0 + \dots \\ 154 | &=& D \cdot (C - Q) + \sum_{i=0}^2 |e_i D \cdot U_i| 155 | \end{eqnarray} 156 | }\end{slide} 157 | 158 | \begin{slide}{Oriented bounding boxes}{OBB SAT}{ 159 | \item Maximization results in $\max_P D \cdot (P - Q) = \underbrace{D \cdot (C - Q)}_{\gamma} + \underbrace{\sum_{i=0}^2 |e_i D \cdot U_i|}_{r}$ 160 | \item Minimization results in $\min_P D \cdot (P - Q) = D \cdot (C - Q) - \sum_{i=0}^2 |e_i D \cdot U_i|$ 161 | \item The interval is thus $[\gamma - r, \gamma + r]$ 162 | \item \textbf{Important:} the separating directions \textit{must be unit length}, and the edges as well 163 | }\end{slide} 164 | 165 | \begin{slide}{Oriented bounding boxes}{OBB SAT}{ 166 | \item We project both OBBs onto their intervals $[\gamma_1 - r_1, \gamma_1 + r_1]$ and $[\gamma_2 - r_2, \gamma_2 + r_2]$ 167 | \item They intersect when $|\gamma_2 - \gamma_1| < r_1 + r_2$ 168 | }\end{slide} 169 | 170 | \begin{slide}{Oriented bounding boxes}{OBB SAT - final optimization}{ 171 | \item Some separating directions are taken from the cross product of two edge directions: $D = U_i^1 \times U_k^2$ 172 | \item When we plug those directions $D$ in the above formulas, we get $U_i^1 \times U_k^2 \cdot U_j^1$ 173 | \item We can rewrite $U_i^1 \times U_k^2 \cdot U_j^1 = U_i^1 \times U_j^1 \cdot U_k^2$ 174 | \item We can cache the products $U_i^1 \times U_j^1$, so we do not have to recompute them 175 | }\end{slide} 176 | 177 | \begin{slide}{Moving objects}{Moving objects}{ 178 | \item We ignore the angular velocity; does not improve much, and is very complex to handle 179 | \item We can enlarge the interval radii by projecting the current relative velocity onto the separating direction 180 | \item $s = D \cdot (V_2 - V_1)$ 181 | }\end{slide} 182 | 183 | \section{Further optimizations} 184 | \begin{slide}{Further optimizations}{Islands}{ 185 | \item Apply collision response system only to groups of objects in contact 186 | \item Flood-fill algorithm 187 | }\end{slide} 188 | 189 | \begin{slide}{Further optimizations}{Sparse matrices for collision response}{ 190 | \item Avoid multiplying lots of zeroes 191 | \item Store matrix row as list of \texttt{int * float} entries 192 | }\end{slide} 193 | 194 | \section{Assignment} 195 | \begin{slide}{Assignment}{Assignment}{ 196 | \item Before the end of next week 197 | \item Group-work archive/video on Natschool or uploaded somewhere else and linked in your report 198 | \item Individual report by each of you on Natschool 199 | \item Build a broad phase collision detector that supports a combination of bounding spheres, AABBs, bins, and OBBs 200 | }\end{slide} 201 | 202 | \begin{frame}{That's it} 203 | \center 204 | \fontsize{18pt}{7.2}\selectfont 205 | Thank you! 206 | \end{frame} 207 | 208 | \end{document} 209 | 210 | 211 | \begin{slide}{SECTION}{SLIDE}{ 212 | \item i 213 | }\end{slide} 214 | 215 | \begin{frame}[fragile]{SLIDE} 216 | \begin{lstlisting} 217 | CODE 218 | \end{lstlisting} 219 | \end{frame} 220 | 221 | \begin{frame}{SLIDE} 222 | \center 223 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 224 | \end{frame} 225 | -------------------------------------------------------------------------------- /Slides/Lecture 7/Pics/MovingSpheres.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 7/Pics/MovingSpheres.png -------------------------------------------------------------------------------- /Slides/Lecture 7/Pics/SpacePartitioning.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 7/Pics/SpacePartitioning.PNG -------------------------------------------------------------------------------- /Slides/Lecture 7/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 8/Lecture 8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 8/Lecture 8.pdf -------------------------------------------------------------------------------- /Slides/Lecture 8/Lecture 8.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | 12 | \title{Building a physics engine - part 5: various forces} 13 | 14 | \author{Dr. Giuseppe Maggiore} 15 | 16 | \institute{NHTV University of Applied Sciences \\ 17 | Breda, Netherlands} 18 | 19 | \date{} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \begin{frame}{Table of contents} 25 | \tableofcontents 26 | \end{frame} 27 | 28 | \section{Gravity} 29 | \begin{slide}{Gravity}{Gravity}{ 30 | \item The easiest :) 31 | \item $F_G = \frac{G m_1 M_2}{r^2}$ $G=6.67384 10^{-11} m^3 kg^{-1} s^{-2}$ 32 | \item On the surface of a planet, $F=ma$, where $a = \frac{G m_2}{r^2}$; for example, $a = g = 9.81$ 33 | }\end{slide} 34 | 35 | \section{Friction} 36 | \begin{slide}{Friction}{Friction}{ 37 | \item Friction is related to the \textit{normal force} 38 | \item $F_N = m g \cos \theta$ 39 | \item $F_F = \mu F_N$, where $\mu$ depends on the materials 40 | \item When not moving, static friction applies $\mu_S$ 41 | \item When moving, dynamic friction applies $\mu_K$ 42 | \item $\mu_K < \mu_S$ 43 | }\end{slide} 44 | 45 | % TABLE OF FRICTIONS AND MATERIALS 46 | 47 | \section{Springs} 48 | \begin{slide}{Springs}{Springs}{ 49 | \item Hooke's Law 50 | \item $F_S = -k \Delta l$ 51 | }\end{slide} 52 | 53 | % FIG 3.7 54 | 55 | \section{Centripetal force} 56 | \begin{slide}{Centripetal force}{Centripetal force}{ 57 | \item During a circular movement 58 | \item Force towards the center of the circle 59 | \item $F_C = \frac{m v^2}{r}$ 60 | }\end{slide} 61 | 62 | \section{Projectiles} 63 | \begin{slide}{Projectiles}{Projectiles}{ 64 | \item A projectile is influenced by 65 | \begin{itemize} 66 | \item Gravity 67 | \item Aerodynamic drag 68 | \item Laminar and turbulent flow 69 | \item Wind effects 70 | \item Spin effects 71 | \item Projectile geometry and mass 72 | \end{itemize} 73 | }\end{slide} 74 | 75 | \begin{slide}{Projectiles}{Aerodynamic drag}{ 76 | \item $F_D = \frac{1}{2} \rho v^2 A C_D$ 77 | \begin{itemize} 78 | \item $\rho$ is the fluid density 79 | \item $A$ is the body area 80 | \item $C_D$ is the drag coefficient 81 | \end{itemize} 82 | }\end{slide} 83 | 84 | \begin{slide}{Projectiles}{$C_D$}{ 85 | \item Drag is a force applied against motion $-\frac{v}{|v|}$ 86 | \item The drag coefficient depends on the \textit{Reynolds number} 87 | \item $C_D = f(Re)$ for some complex function $f$ 88 | \item $Re = \frac{\rho v L}{\mu}$ 89 | \begin{itemize} 90 | \item $L$ is the projectile length 91 | \item $\mu$ is the drag coefficient 92 | \end{itemize} 93 | }\end{slide} 94 | 95 | % FIG 5-6 96 | % FIG 5-3 97 | 98 | \begin{slide}{Projectiles}{Air density}{ 99 | \item Depends on altitude 100 | }\end{slide} 101 | 102 | % TAB 5-4 103 | 104 | \begin{slide}{Projectiles}{Laminar vs turbulent flow}{ 105 | \item Depending on the speed, the air travels over the surfaces of the projectile 106 | \item At low Reynolds numbers, flow is laminar 107 | \item At around $Re = 250000$ the switch occurs (for a golf ball and similar projectiles) 108 | \item At high Reynolds numbers, flow is turbulent 109 | \item We store at least two $C_D$ coefficients per object 110 | }\end{slide} 111 | 112 | \begin{slide}{Projectiles}{Wind}{ 113 | \item Wind simply changes the \textit{apparent velocity} 114 | \item All other computations simply use the apparent velocity 115 | \item $v_{\text{apparent}} = v - v_{\text{wind}}$ 116 | }\end{slide} 117 | 118 | \begin{slide}{Projectiles}{Spin effects}{ 119 | \item When an object is spinning, the velocity difference between the top and bottom surfaces given by spinning causes acceleration 120 | \item This is known as the \textit{Magnus Effect} or \textit{Robin's Effect} 121 | }\end{slide} 122 | 123 | % FIG 5-14 124 | 125 | \begin{slide}{Projectiles}{Spin effects}{ 126 | \item $F_M = \frac{1}{2} \rho v^2 A C_L$ 127 | \item $C_L = \frac{r w}{v}$ for a sphere 128 | \item $C_L = \frac{2 \pi r w}{v}$ for a cylinder 129 | \item Direction of force is $\frac{v \times w}{|v \times w|}$ 130 | }\end{slide} 131 | 132 | \begin{slide}{Projectiles}{Bullets}{ 133 | \item Rotation axis is horizontal 134 | \item Almost zeroes $\frac{v \times w}{|v \times w|}$ 135 | \item Magnus Effect can be ignored 136 | \item $C_D = 0.3$ is a reasonable constant 137 | }\end{slide} 138 | 139 | % TAB 5-6 140 | 141 | \begin{slide}{Projectiles}{Cannonballs}{ 142 | \item Start with a velocity between $260m/s$ and $344m/s$ 143 | \item Weight is between $2kg$ and $10kg$ 144 | \item $C_D = 0.3$ is a reasonable constant 145 | }\end{slide} 146 | 147 | 148 | \section{Assignment} 149 | \begin{slide}{Assignment}{Assignment}{ 150 | \item Before the end of next week 151 | \item Group-work archive/video on Natschool or uploaded somewhere else and linked in your report 152 | \item Individual report by each of you on Natschool 153 | \item Add a personalized selection of forces to your simulator 154 | }\end{slide} 155 | 156 | \begin{frame}{That's it} 157 | \center 158 | \fontsize{18pt}{7.2}\selectfont 159 | Thank you! 160 | \end{frame} 161 | 162 | \end{document} 163 | 164 | 165 | \begin{slide}{SECTION}{SLIDE}{ 166 | \item i 167 | }\end{slide} 168 | 169 | \begin{frame}[fragile]{SLIDE} 170 | \begin{lstlisting} 171 | CODE 172 | \end{lstlisting} 173 | \end{frame} 174 | 175 | \begin{frame}{SLIDE} 176 | \center 177 | %\includegraphics[height=5cm]{Pics/recursive_multiplier.png} 178 | \end{frame} 179 | -------------------------------------------------------------------------------- /Slides/Lecture 8/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Slides/Lecture 9/Lecture 9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Lecture 9.pdf -------------------------------------------------------------------------------- /Slides/Lecture 9/Lecture 9.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{Warsaw} 3 | \usepackage{nhtvslides} 4 | \usepackage{graphicx} 5 | \usepackage{listings} 6 | \lstset{language=CAML, 7 | basicstyle=\ttfamily\footnotesize, 8 | frame=shadowbox, 9 | breaklines=true} 10 | \usepackage[utf8]{inputenc} 11 | \DeclareMathOperator{\sign}{sign} 12 | \DeclareMathOperator{\LookupCurve}{LookupCurve} 13 | 14 | \title{Building a physics engine - part 5b: cars} 15 | 16 | \author{Dr. Giuseppe Maggiore} 17 | 18 | \institute{NHTV University of Applied Sciences \\ 19 | Breda, Netherlands} 20 | 21 | \date{} 22 | 23 | \begin{document} 24 | \maketitle 25 | 26 | \begin{frame}{Table of contents} 27 | \tableofcontents 28 | \end{frame} 29 | 30 | \section{Basic linear dynamics} 31 | \begin{slide}{Basic linear dynamics}{Basic linear dynamics}{ 32 | \item Some easy assumptions for starters 33 | \item No gears, lateral forces, etc. 34 | \item Sports car with rear traction 35 | }\end{slide} 36 | 37 | \begin{slide}{Basic linear dynamics}{Basic linear dynamics}{ 38 | \item Longitudinal force 39 | \begin{eqnarray} 40 | F_{\text{traction}} &=& u F_{\text{engine}} \\ 41 | F_{\text{drag}} &=& - C_{\text{drag}} v |v| \\ 42 | F_{\text{rr}} &=& - C_{\text{rr}} v \\ 43 | F_{\text{long}} &=& F_{\text{traction}} + F_{\text{drag}} + F_{\text{rr}} 44 | \end{eqnarray} 45 | \begin{itemize} 46 | \item $u$ is forward direction 47 | \item $C_{\text{drag}} = 0.4257$ 48 | \item $C_{\text{rr}} = 12.8$ 49 | \end{itemize} 50 | }\end{slide} 51 | 52 | \begin{slide}{Basic linear dynamics}{Basic linear dynamics}{ 53 | \item Braking force 54 | \begin{eqnarray} 55 | F_{\text{brake}} &=& -u C_{\text{brake}} \\ 56 | F_{\text{long}} &=& F_{\text{brake}} + F_{\text{drag}} + F_{\text{rr}} 57 | \end{eqnarray} 58 | \begin{itemize} 59 | \item $C_{\text{brake}}$ is a constant that \textit{just feels good} 60 | \end{itemize} 61 | }\end{slide} 62 | 63 | \section{Weight transfer} 64 | \begin{slide}{Weight transfer}{Weight transfer}{ 65 | \item Acceleration causes a pitch of the car 66 | \item It shuffles weight between front and rear 67 | \item Tires with more or less friction, and thus capacity to support acceleration 68 | \item $F_{\text{max}} = \mu W_w$ for a wheel carrying weight $W_w$ 69 | \item $\mu \in [1 \dots 1.5]$ 70 | }\end{slide} 71 | 72 | \begin{frame}{Weight transfer} 73 | \center 74 | \includegraphics[height=5cm]{Pics/WeightTransfer.png} 75 | \end{frame} 76 | 77 | \begin{slide}{Weight transfer}{Weight transfer}{ 78 | \item When the car is at rest 79 | \begin{eqnarray} 80 | W_f &=& \frac{c}{l}W \\ 81 | W_r &=& \frac{b}{l}W 82 | \end{eqnarray} 83 | \item When the car is accelerating 84 | \begin{eqnarray} 85 | W_f &=& \frac{c}{l}W - \frac{h}{l}ma \\ 86 | W_r &=& \frac{b}{l}W + \frac{h}{l}ma 87 | \end{eqnarray} 88 | }\end{slide} 89 | 90 | \begin{slide}{Weight transfer}{Weight transfer}{ 91 | \item When accelerating, pitch the car 92 | \item If the force applied by the engine to the wheels is bigger than $F_{\text{max}}$, reduce $\mu$ and apply $F_{\text{max}}$, and draw smoke/spinning wheels 93 | \item If the force applied by the engine to the wheels is less than $F_{\text{max}}$, apply the engine force directly 94 | }\end{slide} 95 | 96 | \section{Engine force} 97 | \begin{slide}{Engine force}{Engine force}{ 98 | \item The engine is not directly connected to the wheels 99 | \item Gears apply the engine torque to different values of max wheel $\tau$ and max wheel $\omega$ 100 | \item Lower gears have higher $\tau$ 101 | \item Higher gears have higher $\omega$ 102 | }\end{slide} 103 | 104 | \begin{slide}{Engine force}{Engine force}{ 105 | \item $F_{\text{drive}} = u \frac{\tau_{\text{drive}}}{R_w}$ is the force applied to the rear axle 106 | \item $\tau_{\text{drive}} = \tau_{\text{engine}} x_g x_d n$ is the torque applied to the rear axle 107 | \item $\tau_{\text{engine}}$ is the torque coming from the engine given the current RPM 108 | \item $x_g$ is the gear ratio, $x_d$ is the differential ratio 109 | \item $m=1500kg$ is the car mass 110 | \item $n=0.7$ is the transmission efficiency 111 | \item $r_w = 0.34m$ is the wheels radius 112 | }\end{slide} 113 | 114 | \begin{slide}{Engine force}{Gear ratios}{ 115 | \item $x_g = 2.66\ 1.78\ 1.3\ 1.0\ 0.74\ 0.5$ 116 | \item reverse gear $ = 2.9$ 117 | \item $x_d = 3.42$ 118 | }\end{slide} 119 | 120 | \begin{slide}{Engine force}{Torque and RPM}{ 121 | \item $rpm$ determines the current maximum torque 122 | \item torque accelerates the wheels 123 | \item wheels determine the next $rpm$ 124 | \item $rpm$ is capped; after a while (\textit{red-line}) the engine breaks 125 | \item $\tau_{\text{max}}$ is capped as well; one cap per gear 126 | }\end{slide} 127 | 128 | \begin{slide}{Engine force}{Torque and RPM}{ 129 | \item Torque and RPM recurrences 130 | \begin{eqnarray} 131 | \tau_{\text{max}} &=& \LookupCurve(rpm) \\ 132 | \tau_{\text{engine}} &=& \tau_{\text{max}} \alpha_{\text{throttle}} \\ 133 | rpm &=& \max(1000, \frac{\omega_w x_g x_d}{2 \pi}) 134 | \end{eqnarray} 135 | }\end{slide} 136 | 137 | \begin{slide}{Engine force}{Wheel angular velocity}{ 138 | \item For $\LookupCurve$, any reasonable bell-shaped curve (different for each gear) will do 139 | \item Or, copy from the sources of \textit{Marco Monster's - Car Physics for Games} tutorial; they contain some data 140 | }\end{slide} 141 | 142 | \begin{frame}{Gear plot} 143 | \center 144 | \includegraphics[height=5cm]{Pics/GearPlot.png} 145 | \end{frame} 146 | 147 | \begin{slide}{Engine force}{Shifting gears}{ 148 | \item RPM changes suddenly when changing gear $rpm' = rpm \frac{x_g'}{x_g}$ 149 | }\end{slide} 150 | 151 | \begin{slide}{Engine force}{Wheel angular velocity}{ 152 | \item Simple solution vs hard solution 153 | \item Simple solution: wheels rotating as car is moving 154 | $$\omega_w \approx \frac{|v|}{r_w}$$ 155 | \item Hard solution: track wheel angular velocities separately 156 | }\end{slide} 157 | 158 | \section{Slip ratio} 159 | \begin{slide}{Slip ratio}{Slip ratio}{ 160 | \item The amount of acceleration of the car depends on the friction between tires and road 161 | \item Rolling tires do not have friction; friction is given by tires rotating faster than they are moving 162 | \item Rear tires roll faster than front tires 163 | }\end{slide} 164 | 165 | \begin{frame}{Longitudinal force} 166 | \center 167 | \includegraphics[height=3cm]{Pics/SlipRatioCurve.png} 168 | \end{frame} 169 | 170 | \begin{slide}{Slip ratio}{Slip ratio}{ 171 | \item Slip ratio determines the force given by the wheel to the car 172 | $\sigma = \frac{\omega_w r_w - v_{\text{long}}}{|v_{\text{long}}|}$ 173 | \item The traction force given by the wheel at a certain slip ratio is 174 | $F_{\text{traction}} = \max(6000, C_t \sigma)$ 175 | $\tau_{\text{traction}} = F_{\text{traction}} \times R_w$ 176 | }\end{slide} 177 | 178 | \begin{frame}{Longitudinal force simplified} 179 | \center 180 | \includegraphics[height=3cm]{Pics/SlipRatioCurveApprox.png} 181 | \end{frame} 182 | 183 | \begin{slide}{Slip ratio}{Slip ratio}{ 184 | \item We track $\omega_w$ for each wheel 185 | \item We compute the slip ratio and the corresponding torque on the axle 186 | $\tau_{\text{total}} = \tau_{\text{drive}} + \underbrace{\tau_{\text{traction}}}_{\text{two wheels}} + \tau_{\text{brake}}$ 187 | \item We compute the angular acceleration of this force on the wheel 188 | $\alpha = \frac{\tau_{\text{total}}}{I_w}$ 189 | \item The wheel rotating around its central axis has moment of inertia 190 | $I_w = \frac{m r_w^2}{2}$ 191 | }\end{slide} 192 | 193 | \section{Curves at a low speed} 194 | \begin{slide}{Curves at a low speed}{Curves at a low speed}{ 195 | \item When travelling at low speed 196 | \item We just find the radius of the circle the car describes, depending on the wheel angle 197 | \item $\delta$ is the wheel turn angle 198 | \item $\sin \delta = \frac{L}{R}$ 199 | \item From the radius we can determine the angular velocity and just rotate the car by that 200 | $\omega = \frac{v}{R} = \frac{v \sin \delta}{L}$ 201 | }\end{slide} 202 | 203 | \begin{frame}{Rotation radius} 204 | \center 205 | \includegraphics[height=3cm]{Pics/RotationRadius.png} 206 | \end{frame} 207 | 208 | \begin{frame}{Delta angle} 209 | \center 210 | \includegraphics[height=3cm]{Pics/DeltaAngle.png} 211 | \end{frame} 212 | 213 | \section{Curves at a high speed} 214 | \begin{slide}{Curves at a high speed}{Curves at a high speed}{ 215 | \item Turning the front wheels causes a change in their lateral forces 216 | \item We add new state information to our system 217 | \begin{itemize} 218 | \item $\alpha$ is the side-slip angle of the wheel, which changes as we turn 219 | \item $C_a$ is the cornering stiffness, a pleasant, and utterly fake, constant 220 | \end{itemize} 221 | }\end{slide} 222 | 223 | \begin{slide}{Curves at a high speed}{Curves at a high speed}{ 224 | \item We compute the lateral and longitudinal speed at a given side-slip angle, for each wheel 225 | \begin{eqnarray} 226 | v_{\text{lat}} &=& |v| \sin \alpha \\ 227 | v_{\text{long}} &=& |v| \cos \alpha 228 | \end{eqnarray} 229 | }\end{slide} 230 | 231 | \begin{slide}{Curves at a high speed}{Curves at a high speed}{ 232 | \item We also compute the side-slip angles given the current angular velocity (started up from low-speed turning) and lateral and longitudinal velocities 233 | \begin{eqnarray} 234 | \alpha_{\text{front}} &=& \frac{v_{\text{lat}} + \omega b}{v_{\text{long}}} - \delta \sign(v_{\text{long}}) \\ 235 | \alpha_{\text{rear}} &=& \frac{v_{\text{lat}} - \omega b}{v_{\text{long}}} 236 | \end{eqnarray} 237 | }\end{slide} 238 | 239 | \begin{slide}{Curves at a high speed}{Lateral forces}{ 240 | \item Lateral force also depends on the current weight distribution 241 | \item $F_{\text{lateral}} = \max(6000, C_a \alpha) W_w$ 242 | \item $\tau_{\text{lateral}} = F_{\text{lateral}} \times b$ 243 | \item Each wheel has a different lateral force; we compute torque from lateral forces and use it as usual to further integrate $\omega$ 244 | }\end{slide} 245 | 246 | 247 | \section{Assignment} 248 | \begin{slide}{Assignment}{Assignment}{ 249 | \item Before the end of next week 250 | \item Group-work archive/video on Natschool or uploaded somewhere else and linked in your report 251 | \item Individual report by each of you on Natschool 252 | \item Add a personalized selection of forces to your simulator 253 | }\end{slide} 254 | 255 | \begin{frame}{That's it} 256 | \center 257 | \fontsize{18pt}{7.2}\selectfont 258 | Thank you! 259 | \end{frame} 260 | 261 | \end{document} 262 | -------------------------------------------------------------------------------- /Slides/Lecture 9/Pics/DeltaAngle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Pics/DeltaAngle.png -------------------------------------------------------------------------------- /Slides/Lecture 9/Pics/GearPlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Pics/GearPlot.png -------------------------------------------------------------------------------- /Slides/Lecture 9/Pics/RotationRadius.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Pics/RotationRadius.png -------------------------------------------------------------------------------- /Slides/Lecture 9/Pics/SlipAngleCurve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Pics/SlipAngleCurve.png -------------------------------------------------------------------------------- /Slides/Lecture 9/Pics/SlipRatioCurve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Pics/SlipRatioCurve.png -------------------------------------------------------------------------------- /Slides/Lecture 9/Pics/SlipRatioCurveApprox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Pics/SlipRatioCurveApprox.png -------------------------------------------------------------------------------- /Slides/Lecture 9/Pics/WeightTransfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giuseppemag/Game-physics/0dd4856b6361b34d472020f98b63d0803d9a92e3/Slides/Lecture 9/Pics/WeightTransfer.png -------------------------------------------------------------------------------- /Slides/Lecture 9/nhtvslides.sty: -------------------------------------------------------------------------------- 1 | \newenvironment{slide}[3] 2 | { 3 | \begin{frame}{#1} 4 | \begin{block}{#2} 5 | \begin{itemize} 6 | #3 7 | \end{itemize} 8 | \end{block} 9 | }{ 10 | \end{frame} 11 | } 12 | 13 | \newenvironment{textslide}[3] 14 | { 15 | \begin{frame}{#1} 16 | \begin{block}{#2} 17 | #3 18 | \end{block} 19 | }{ 20 | \end{frame} 21 | } 22 | 23 | \newenvironment{codeslide}[3] 24 | { 25 | \begin{frame}[fragile]{#1} 26 | \begin{block}{#2} 27 | \begin{lstlisting}[language=CAML] 28 | #3 29 | \end{lstlisting} 30 | \end{block} 31 | }{ 32 | \end{frame} 33 | } 34 | 35 | --------------------------------------------------------------------------------