I present a formulation for Rigid Body Dynamics that is independent of the dimension of the space. I describe the state and equations of motion of rigid bodies using geometric algebra. Using collision detection algorithms extended to nD I resolve collisions and contact between bodies. My implementation is 4D, but the techniques described here apply to any number of dimensions. I display these four-dimensional rigid bodies by taking a three-dimensional slice through them. I allow the user to manipulate these bodies in real-time.
Btw I believe it is basically unheard of to have work from an indie game presented in the SIGGRAPH technical papers track?
The paper is full of really fun and beautiful math (obviously Geometric Algebra based, see my recent article) that makes me happy. One reviewer called the work “whimsical,” and they’re not wrong, ahah.
Most of this work (including writing the paper) is from ~2012, but I added a section on the (4D) Dzhanibekov effect at the suggestion of the reviewers. Many thanks to them for helping me greatly improve the paper.
To represent 3D rotations graphics programmers use Quaternions. However, Quaternions are taught at face value. We just accept their odd multiplication tables and other arcane definitions and use them as black boxes that rotate vectors in the ways we want. Why does $\mathbf{i}^2=\mathbf{j}^2=\mathbf{k}^2=-1$ and $\mathbf{i} \mathbf{j} = \mathbf{k}$? Why do we take a vector and upgrade it to an “imaginary” vector in order to transform it, like $\mathbf{q} (x\mathbf{i} + y\mathbf{j} + z \mathbf{k}) \mathbf{q}^{*}$? Who cares as long as it rotates vectors the right way, right?
Personally, I have always found it important to actually understand the things I am using. I remember learning about Cross Products and Quaternions and being confused about why they worked this way, but nobody talked about it. Later on I learned about Geometric Algebra and suddenly I could see that the questions I had were legitimate, and everything became so much clearer.
In Geometric Algebra there is a way to represent rotations called a Rotor that generalizes Quaternions (in 3D) and Complex Numbers (in 2D) and even works in any number of dimensions.
3D Rotors are in a sense the true form of quaternions, or in other words Quaternions are an obfuscated version of Rotors. They are equivalent in that they have the same number of components, their API is the same, they are as efficient, they are good for interpolation and avoiding gimbal lock, etc… in fact, they are isomorphic, so it is possible to do some math to turn a rotor into a quaternion, but doing so makes them less general and less intuitive (and loses extra capabilites).
But instead of defining Quaternions out of nowhere and trying to explain how they work retroactively, it is possible to explain Rotors almost entirely from scratch. This obviously takes more time, but I find it is very much worth it because it makes them much easier to understand!
For example, Quaternions are introduced as this mysterious four-dimensional object, but why introduce a fourth dimension of space to visualize a 3D concept? By contrast 3D Rotors do not require the use of a fourth dimension of space in order to be visualized.
Trying to visualize quaternions as operating in 4D just to explain 3D rotations is a bit like trying to understand planetary motion from an earth-centric perspective i.e. overly complex because you are looking at it from the wrong viewpoint.
It would be great if we could start phasing out the use and teaching of Quaternions and replace them with Rotors. The change is simple and the code remains almost the same, but the understanding grows a lot.
As a side note, Geometric Algebra contains more than just Rotors, and is a very useful tool to have in one’s toolbox. This article also serves as an introduction to it.
And here are some quotes about it:
The clearest explanation of 3D geometric algebra within 15 minutes that I’ve seen so far—BrokenSymmetry
I am sold. While I can understand quaternions to an extent, this way of thinking is a much more intuitive and elegant approach.—Jack Rasksilver
This sets a high standard for educational material, and is a shining example of how we can improve education with today’s technologies.—Sebastien Pierre
When I was in college, I asked one of my math professors why the cross product of two vectors results in a perpendicular vector whose magnitude is equal to the area of the parallelogram formed by the two vectors. Like..what? Why? And what about 2D?
They blew me off, and that was a big part of why I stopped taking math in college. […]
Anyway, I had pretty much given up on ever truly understanding the whole jumble of seemingly unrelated types that are cross products. But then I saw this: And…wow. Just 15 minutes and a lot more than just cross products suddenly make a lot more sense.—Mason Remaley
I’m a pure math dude at heart, even if I don’t get to do it much any more.
Two years ago, my wife asked me, “If you had to get a math equation tattooed on your body, what would it be?” I answered, “i^2 = j^2 = k^2 = ijk = -1”.
I felt a brief flush of anger when I saw this headline.
This is an extraordinarily good article that should be read by pretty much anyone doing graphics programming.—pflats
I wrote most of in 2011/2012, but didn’t release it because I was not satisfied with part of it. But I thought it was time to let go and release it anyway. I actually think it is hurting the advancement of science that people are still mainly using quaternions instead of Geometric Algebra, so holding on to it was not good.
So last fall/summer I cleaned up some of the diagrams and made a 15 minute long video that follows the article exactly. I never made a video this long, and it was quite exhausting. But I thought it would be really cool to make an article that is perfectly synced to a video, so you can either read it or watch it, and the article serves as an exact table of contents for the video.
Geometric Algebra soon came in handy for Miegakure, specifically to define the 4D equivalent to Quaternions, which I posted about on this blog. Later on it became the backbone of 4D Toys.
Learning about Geometric Algebra was also great because it answered so many questions I had when learning linear algebra, the cross product, quaternions, etc… I basically wrote this article for my past self as a college student.
I recently rewrote the introduction to add more detail about the properties of Rotors and how they relate to quaternions. Even though the content went into detail, it should now be clear what Rotors are from only reading the introduction. I can already see from reading recent comments that it was worth it.
I deliberately picked a cheeky click-bait title…
Something else that might be of interest is the history of Geometric Algebra, so I recently added a heavily summarized version to the end of the article. I think looking at the history makes it clearer how the quaternion viewpoint stayed in people’s minds for longer than necessary…
It occurred to me that it should be possible to give more detailed progress updates without spoiling the game too much. Thanks to those of you who emailed me to check on the progress of the game and thank you for your patience. As I said last time, all the mechanics, levels, story & dialogs are done. We still are polishing up the game. Here are some things that we worked on since the last blog update (a lot of these could, and maybe will be their own blog posts):
We implemented the sound of the moving blocks. The code still needs to be cleaned up a bit. It seems we tend to not really know how it should work until we try it in game. There is still of bunch of sound work left.
I spent a while looking for and building additional methods of procedurally generating 4D geometry, especially for the large tesseract-shaped rocks which are very common in the game. This allowed me to really improve the visuals throughout the game. I initially implemented a few complex generic algorithm, but some of them were not stable enough (I need very clean geometry for collision detection) so I spent some time figuring out how to achieve the effects I wanted using simpler methods, and I am very happy with the original solutions I came up with! Some of this work will also be useful for 4D Toys.
I added a few finishing touches and released this Article with Interactive Diagrams on Rotors and Geometric Algebra I had made back in 2012. It look longer than I thought it would… making a 15 minutes long video took a long time and was very exhausting. I recently updated it, and will do a separate blog post about it very soon.
I figured out the rough look and layout of the few remaining large buildings in the game, and built them as prototypes. There is a strong interconnection between the visuals, gameplay, and story in the game, and that made for intricate “puzzles” with lots of moving parts that I had to figure out… The concept artist is working on the final look for these in the next few months.
I went on vacation, because honestly I was pretty burnt out last year. I went to Japan, which is always amazing and heals my soul. I needed a break after crunching on this game for the last one hundred and eighty three years (give or take).
I worked on nailing down the final look of the game… I worked on some Physically Based Rendering (PBR) stuff to include. A bunch more work remains to be done there.
We found and fixed issues with the animation rig we were using. Working on finishing all the animations now with an animator who has recently joined the project.
I made how the water is shown in the game consistent across every level, and worked to finalize the look of the “empty space” around the “diorama” that is each level.
I finalized the look of the gates used to go from level to level. We have to make sure anything in the game is easy to learn and manipulate for a 3D being inside a 4D world, and that brings all these complications to something that should be quite simple normally… but also: – there is a ton of information that needs to be displayed on this one element (ex: level is done/available/etc…) – there are around five slightly different versions of it with different constraints – it needs to be visible enough but not grab too much attention – it needs to belong with natural elements such as trees and rocks but also stand out as an “interface” element – it needs to match the feel of the game – it needs to use the 4D in a cool way, etc…
As a side-note, many of the things I worked on lately had the property that they were pretty good, but not good enough to ship. For example they worked fine for part of the game, but not for the whole thing. Or my friends would point them out to me saying something feels off there. But I didn’t know how to finish them at the time, so I left them as is, to be picked up later. Coming back to them, I could tell they were often “local maxima” solutions: it felt like any changes made them worse, and I didn’t know how to proceed anymore, but there had to be a better solution. After thinking hard for a while, breakthroughs came and the best solutions ended up very different than the solutions that were in the game for a long time! Or sometimes I found out that they really were the best solutions and I had to move on, ahah.
I made the way the buildings are sliced consistent across the entire game. The old way I was using for some buildings was made very early on, back when I didn’t understand 4D space very much. But it also had extra features that were not trivial to port to proper 4D geometry, like fading out certain sections to let the player see inside. Interestingly, the hacky method I was using to display these buildings was simpler, and so in some way potentially easier to understand. But it was inconsistent with the rest of the game. So while it seemed a bit of a loss, I opted for more consistency and correctness. I am keeping in the back of my mind the counter-intuitive way in which adding the tetrahedral meshes and making doodads be “correct” in 4D made the game more visually complicated but also easier to play, probably because of some unconscious pattern recognition.
The very talented artists on the team have modeled/textured most of the large buildings in the game at this point and they look amazing. We are moving on to the smaller ones!
We also finally built the main element of a very exciting and beautiful level that I had planned almost from the very beginning. This level is so cool that it will be showcased in a video as one of the “Main Miracles” of being to able to move in 4D, along with Going around Walls, Binding Two Rings (which I still need to redo), Stealing From Inside a Closed Building, etc…
And many other things!
As always, thank you for your patience and enthusiasm.
Added 11 new star-like shapes that would look great hanging from or on top of your 4D Christmas Tree.
The Regular Star Polychora (or “Schläfli-Hess 4-polytopes”):
Icosahedral 120-cell
Small stellated 120-cell
Great 120-cell
Grand 120-cell
Great stellated 120-cell
Grand stellated 120-cell
Great grand 120-cell
Great icosahedral 120-cell
Grand 600-cell
And my personal favorite, the Great grand stellated 120-cell
Plus a Compound 5-Cell for good measure.
The Star Polychora are the 4D equivalent of the 2D Star Polygons.
Star polygons can be made by extending the edges of polygons, until they meet outside of the polygon.
For
example this Hexagram (or “Star of David”) can be made by extending the
edges of a Hexagon. This process of extending edges (or faces and cells
in 3D or 4D) is called Stellation.
Warmest wishes for a Happy
Holiday Season and a wonderful New Year! I felt the need to take a break
from updating 4D Toys for a bit, but more updates will be coming next
year!
(I also never posted here about the other updates, such as the gryochora: It turns out there exist 4D dice shapes with any number of sides, even primes! Added an assortment of over 30 new dice with sides such as 9, 13 and of course 42.)