Difference between revisions of "Advanced C++ Programming Tutorial 5"
From Chilipedia
(→Tutorial 5.2) |
(→Tutorial 5.2) |
||
Line 53: | Line 53: | ||
:* The order in which you concatenate matrices matters: ABC != CBA | :* The order in which you concatenate matrices matters: ABC != CBA | ||
:* The sequence of applying transformations reads from right to left in Matrix multiplication | :* The sequence of applying transformations reads from right to left in Matrix multiplication | ||
− | :: | + | :: T = CBA means transformation A is applied first, then B, then C |
:* Demo of this principle in debug mode [https://youtu.be/CS4HQdQnbaA?t=14m19s 14:19] | :* Demo of this principle in debug mode [https://youtu.be/CS4HQdQnbaA?t=14m19s 14:19] | ||
− | + | * Matrix augmentation is not just a hack, it falls in the domain of Projective Geometry [https://youtu.be/CS4HQdQnbaA?t=15m29s 15:29] | |
− | * [https://youtu.be/CS4HQdQnbaA?t= | + | * Fix up the Starfield rendering pipeline [https://youtu.be/CS4HQdQnbaA?t=16m31s 16:31] |
− | * [https://youtu.be/CS4HQdQnbaA?t= | + | :* Design decision: keep working with <code>Vec2</code>, this requires conversion operators to and from <code>Vec3</code> |
− | * [https://youtu.be/CS4HQdQnbaA?t= | + | :* Refactoring the <code>DrawClosedPolygon</code> function in the <code>Graphics</code> class [https://youtu.be/CS4HQdQnbaA?t=18m03s 18:03] |
− | * [https://youtu.be/CS4HQdQnbaA?t= | + | :* Refactoring the <code>Drawable</code> class [https://youtu.be/CS4HQdQnbaA?t=19m15s 19:15] |
− | * [https://youtu.be/CS4HQdQnbaA?t= | + | :* Refactoring the <code>Entity</code> class [https://youtu.be/CS4HQdQnbaA?t=23m22s 23:22] |
+ | :* Refactoring the <code>CoordinateTransformer</code> class [https://youtu.be/CS4HQdQnbaA?t=23m22s 24:00] | ||
+ | * Debugging session: the wrong order of transformations can mess you up [https://youtu.be/CS4HQdQnbaA?t=24m51s 24:51] | ||
+ | :* Be careful with Matrix multiplication operators: using the overloaded <code>operator*=()</code> is problematic: | ||
+ | :: </code>M *= A</code> yields M=MA, but we need M=AM | ||
* [https://youtu.be/CS4HQdQnbaA?t=ms :] | * [https://youtu.be/CS4HQdQnbaA?t=ms :] | ||
* [https://youtu.be/CS4HQdQnbaA?t=ms :] | * [https://youtu.be/CS4HQdQnbaA?t=ms :] |
Revision as of 16:01, 18 April 2020
Hot take: the Matrix is a mediocre film at best. It's a pretty great way to encode transformations though, so let's matrix it up!
Contents
Topics
Part 1
- Matrix form
- Matrix by vector multiplication
- Matrix encoding of scaling, rotation, and flipping
- Matrix multiplication
- Concatenating matrix transforms
Part 2
- Augmented 3x3 matrix for encoding translations
- Matrix multiplication order matters!
- Porting pipeline to use matrix transforms
- Bug hunting!
Video Timestamp Index
Tutorial 5.1
- Matrices: what are they, what are they good for? 0:44
- Basic Matrix operations: Matrix by Vector multiplication 3:05
- Creating a templated
_Mat2<T>
Matrix class 7:16
- Matrix data stored as 2D array
T arr[2][2]
- Matrix data stored as 2D array
- Implementing the Matrix by Vector multiplication method 9:21
- Testing in
game.cpp
13:00 - Implementing basic transformations in Matrix form as static functions 15:16
- Testing in
game.cpp
21:25 - Basic matrix operations: Matrix multiplication 23:06
- Implementing & testing the Matrix multiplication method 25:52
- Recap: concatenating transformations by multiplying transformation matrices 30:10
- This is the beauty of matrix operations: one single concatenated matrix holds all the transformation information
- Concatenating matrices cuts down the number of vector operations needed at runtime
- What about translation? 31:20
Tutorial 5.2
- Translation: why is it a complicated transformation? 0:14
- Trick: augment the matrix (add an extra dimension) 3:11
- Coding this into the framweork 6:54
- The order of applying transformations and its relation to Matrix multiplication (concatenation) 12:09
- The order in which you concatenate matrices matters: ABC != CBA
- The sequence of applying transformations reads from right to left in Matrix multiplication
- T = CBA means transformation A is applied first, then B, then C
- Demo of this principle in debug mode 14:19
- Matrix augmentation is not just a hack, it falls in the domain of Projective Geometry 15:29
- Fix up the Starfield rendering pipeline 16:31
- Debugging session: the wrong order of transformations can mess you up 24:51
- Be careful with Matrix multiplication operators: using the overloaded
operator*=()
is problematic:
- </code>M *= A</code> yields M=MA, but we need M=AM
- Be careful with Matrix multiplication operators: using the overloaded
Links
- GitHub Repo (advmath)
- Note that the code for this tutorial can be found on the <starfield> branch of the repo not in <master>
Homework
None! (or check out 3D Fundamentals you lazy fucks!)