C++, Graphics, Math, Physics, Programming, Review

Review: Essential Mathematics for Games and Interactive Applications by James M. Van Verth and Lars M. Bishop

Essential Mathematics for Games and Interactive Applications by James M. Van Verth and Lars M. Bishop is a quality math book if I ever saw one.  Strangely, the first edition came out in 2004 but the book was kind of off my radar until recently.  This third edition was published in 2015 and seems very current. The authors here do a great job of explaining the material properly. I felt like they created a great foundation for learning these complex ideas and I appreciated the  quality and readability of the code  samples.

The book starts with an overview of computer number representations, and goes into detail with the IEEE 754 floating-point standard. At first I assumed this was unnecessary detail, but actually it’s pretty useful to understand and a good base to build on. They continue with vectors and points, linear transformations and matrices, affine transformations,  orientation (including matrices, Euler angles, axis-angle, and quaternions),  and interpolation (linear and curved). In the next section they transition to more graphic oriented topics such as: viewing and projection, geometry and programmable shading, lighting, rasterization, then a random chapter on… random numbers, and finish off with intersection testing  and rigid-body dynamics.

Just looking at the table of contents is sometimes not enough to get a feel for the quality of the text, so I will reveal  more. The beginning parts are really exactly what you’d expect for a game math book. The basics of vectors, matrices, quaternions, etc. are the bread and butter for a 3D programmer. The coverage here is solid and great for a beginner. Advanced readers  may not find any surprises, but it’s still a good refresher.  The interpolation chapter I found interesting, especially the detail into different types of curves and splines .  This could be immediately useful for coding  a skinned character or animating a camera in a game.  Viewing and projection were given adequate coverage and are essential to anyone wishing to code a graphics engine themselves.  The next chapter was particularly long and explained the programmable shader pipeline to great effect.  The authors explained everything from color representation, vertex attributes, drawing geometry, fixed-function versus programmable, vertex and fragment shaders (aka pixel shaders), and texture mapping. Really a great introduction for anyone wanting to learn to code shaders themselves.  Then they  move onto lighting and go into the basic types (point, spot, directional, and ambient), surface materials, per-vertex and per-fragment lighting, combining with textures, and a few small sections of more advanced topics like normal mapping, physically based lighting, HDR, and deferred shading.

Next up is rasterization, which was an awesome chapter that explained (in epic detail) how rasterizers work which I feel does help when you know what’s going on behind the scenes. I don’t know of many other books that explain this part of the pipeline so well, so this was much appreciated. The random number chapter was also quite informative. It’s easy to just call a function that spits out a number and not actually understand what’s happening.  I found this  portion of the book to be a nice surprise. Intersection testing was covered near the end, and  it was one of the longer chapters. Almost anything you could think of was here: finding distances from lines and points, sphere/ray/plane intersections, axis-aligned bounding boxes (AABBs), swept spheres, object-oriented boxes, triangle intersection, and a simple collision system. Finally the book closes with a chapter on rigid-body dynamics. I actually purchased my copy mostly for the rigid-body material and I felt I learned a few useful things. Of course, it was only one chapter but some of the explanation was better than whole books I’ve read on physics. Certainly it gave me a few things to research further, and I appreciate that.

Overall I would say that  Essential Mathematics for Games and Interactive Applications is an almost flawless textbook. I may be a great place to start for a beginner, and even intermediate to advanced readers may learn a thing or two. Some of the other game math books I recommend I read so long ago it’s hard to make a direct comparison. But this title is certainly up there with the best. I would wholeheartedly recommend.

Math, Physics, Programming, Unity

Custom 2D Physics in Unity Using Verlet Integration


So 2017 will be my year of “doing the work,” a line I learned from Steven Pressfield in his excellent book named, unsurprisingly, “Do the Work.”  I’ve spent literally years reading about 3D math and physics and, outside of a few small demos I’ve experimented with and never released, I haven’t actually produced anything. I’ve also been inspired and motivated by a variety of books, most recently “Little Bets” which talks about innovators from Steve Jobs to Pixar and how they developed their craft. So, hopefully this year I can work on various smaller projects to hone my skills and really apply the knowledge I’ve gained.

To begin with, I’ve implemented a Verlet Integration based 2D physics engine in Unity, shown in the video above. I created this in basically 1 day over a weekend, and am pretty impressed with the initial results. To be fair, all the logic was taken from a C++ tutorial I found online,  A Verlet based approach for 2D game physics by Benedikt Bitterli, and basically what I did was re-implement it in C# and Unity. I’m no stranger to Verlet Integration, and did similar work many years ago in Flash after reading  Thomas Jakobsen’s breakthrough 2003 article, Advanced Character Physics.  So I very much understood the concepts already and could hit the ground running.

The idea was to begin with something small and achievable, and then build upon it. I started with 2D first, but it shouldn’t be that hard to expand the demo to support 3D as well. Eventually I’d like to explore GPU accelerated physics using Compute Shaders, but I do understand that’s a very complex proposition. Some of my earlier experiments with GPGPU programming were initially positive, but I quickly hit walls with the fundamentals of data structure and the huge can of worms of massively parallel computation. Still, I believe the potential is there, but I have a lot more to learn to harness that kind of power.

After my failed excursion in 3D engine programming, I’m a bit hesitant to make another series out of this. I do hope to continue exploring physics more, and will try to share what I can of the process as I move forward. Honestly, looking back at a lot of the games I’ve programmed in the past, I realized it was mostly the physics that made the games fun. Back then it was when Flash and 2D web games were big, so it was feasible to write the physics code by hand for each game. Today, with 3D being the norm, that kind of customized physics per-game is not tenable but, at the same time, I feel that many developers just use their engine of choice’s built-in physics and things haven’t really evolved.  I have some ideas I’d like to explore that just aren’t possible with what is on the market. Maybe the state of the art is just not there yet, or current hardware is not capable, but I feel compelled to at least try. If everything goes well maybe you will see more of these physics posts from me, and maybe something will come of it. Or, maybe not. I guess we will see.

C++, Math, Physics, Programming, Review

Review: Beginning Math and Physics for Game Programmers by Wendy Stahler

beginning_math_and_physics

Beginning Math and Physics for Game Programmers by Wendy Stahler is the kind of book I like. The title is straight-forward, and the content actually delivers what it claims. I’ve read a number of game development math books but I find that many of them expect a college level mathematics background, or at least some intermediate knowledge already. Not here. This is a book that is accessible to stark beginners, and I’d even recommend it to high school students.

Stahler’s text covers all the basics for both 3D math and physics. Topics include: points and lines, geometry, trigonometry, vector and matrix math, transformations, unit conversions, motion, Newton’s laws, energy and momentum, collisions, and, finally, rotational motion. Clocking in at around 500 pages, there is enough space to delve into each area with adequate coverage. I found the explanations to be very clear and geared to novices.  The author uses lines like: “The fancy name for moving objects in these directions is translation.” While advanced readers may feel somewhat patronized by the language, I actually think this is a great approach for beginners. 3D programming is not easy, but sometimes the arcane conventions used in more advanced books can be off-putting to people just getting started.

One thing I should note, I don’t typically test code samples or verify the accuracy of formulas while I’m progressing through the text. What I expect from the book is to gain a high-level conceptual understanding of the material in order to better grasp the subject matter. When it comes to the actual programming implementation, I will just use the book as a reference but usually find the formula online on Wikipedia or similar sites. I realize some people expect every code sample to work, but I’m not one of those people. It’s the concepts themselves that are important to learn and once you understand you should be able to know what to search for or even implement the code yourself.

One aspect I appreciated was that most of the concepts started with an explanation first in one dimension, then two, then three.  This was especially helpful as it’s conceptually simple to understand something like motion in only 1 dimension and it gradually builds upon that. Some other books jump straight into higher dimensions right off the bat, and that may be difficult to some without prior knowledge. The author also provides ample diagrams, graphs, charts and sample code. She also makes effort to show unit conversions when needed, and emphasizes differences between easily confused units.

Wendy Stahler’s book is, however, somewhat dated being originally published in 2004. While the core material is still relevant, and hasn’t really changed much in those years, some of the samples are written for antique computer systems. For example, for one demo included on the CD-ROM she recommends that the “minimum system requirements for the program are a 700MHz processor, a graphics card with 8MB of memory, and 64MB of RAM.” Those specs would have been laughable even in 2004, when the book originally came out. However, it is humbling to consider my smart-watch has specs that would put the machine those demos were build for to shame.

Overall I enjoyed the book, even with the caveat the nearly all the material was a refresher for me. If you are already a professional game developer, then there probably won’t be much to learn here. I’ve been kind of on a binge of game math and physics books, so I figured I’d give this a shot. I also like to have material to recommend to people new to game development and I find it interesting to read books of different levels to get a broader perspective. If you are just starting out, this may be a nice resource to get your feet wet before graduating to the more complex, but much better math books out there.

3D Engine, Game Engine, Math, Programming, Review

Review: Foundations of Game Engine Development, Volume 1: Mathematics by Eric Lengyel

Volume 1 Mathematics

I’ve always been a big fan of Eric Lengyel, from both his work on the C4 Engine (and now the new Tombstone Engine) and his previous math book, Mathematics for 3D Game Programming and Computer Graphics, which is on it’s 3rd edition and is one of the definitive texts in the genre. This latest book, Foundations of Game Engine Development, Volume 1: Mathematics, I feel does it again and is well worth reading.

The text, which clocks in at around 200 pages (short for a technical book) actually has a decent amount of information crammed into those pages. Lengyel breaks it up into 4 chapters, each focusing on a different aspect. Chapter 1 starts with vectors and matrices, then continuing to transformations, next to geometry and the finishing chapter on advanced algebra. The first 3 chapters are about what you’d expect from a game math book, but explained clearly and succinctly. Early in the book, when discussing vectors, the author states: “Loosely speaking, the dot product provides a measure of how much one vector is like another.” Though it seems obvious now, I’m not sure I’ve ever heard it explained quite as clear before. Much of the rest of the coverage in the first 3 chapters feels like this. While it may be a refresher to many, it’s like seeing some of these concepts in a new light just from the stellar delivery.

As I mentioned, chapters 1 through 3 cover the basics, that most game programmers are likely familiar with. Vector and matrix operations, transformation spaces, finding relations between points, lines, and planes, etc.  I’d consider this to be a good refresher for people at least somewhat familiar with game mathematics. Though I could also see it as an decent introduction for some, there may not be enough hand holding for a complete novice.

However, in chapter 4, Lengyel dives into new territory with Grassmann algebra. Though the math is very old, I’m not sure I’ve ever seen it covered or mentioned in any of the popular game math books I’ve read. The concepts are actually quite interesting, and seem to tie together some different areas that originally seem disparate. To be honest, I think I’d have to read this chapter a second time for the concepts to really sink in. It did make some sense but, being somewhat new material to me, I wasn’t sure how I’d immediately apply the knowledge. That said, I applaud the author for bringing something new to the table and I can’t imagine it being described better.

One part I really did appreciate were the code listings, shown in real C++ code that, while I did not type them in a computer and compile, seem like they would be ready to basically lift off the pages and use in a project. I also very much liked the coding style, which felt clean and modern, unlike some other books I’ve seen where it looked like the code came from a 1980’s mainframe.

Overall, I very much enjoyed this book. It was able to cover basic game mathematics in an extremely clear and concise manner, and introduce new concepts along the way. I think this would make an excellent edition to any game development library. While the book was refreshing at only 200 pages, that brevity meant that some concepts could have been in more depth, and other topics weren’t covered at all. For more thorough coverage, I’d look to  3D Math Primer for Graphics and Game Development by Fletcher Dunn or to Lengyel’s prior book, Mathematics for 3D Game Programming and Computer Graphics. That said, whatever your skill level, I think Foundations of Game Engine Development is a worthy read.

Math, Physics, Programming, Review

Review: Mathematics & Physics for Programmers by Danny Kodicek and John P. Flynt

MathAndPhysics

This book was quite an interesting read. Though a book of math and physics sounds like it would be boring, I found the text to be pretty engaging. At  688 pages, it’s not the longest technical resource, but the authors manage to pack a good deal in those pages. Of course, there is a lot of math in here, but that’s not all. Even some random topics like mazes and game theory pop up near the end. I really did enjoy the book and it seems worthwhile.

Some of the areas of focus include even basic number representations, arithmetic, algebra and trigonometry, vectors and calculus, to mass and acceleration, collision detection, force and motion, friction and more. Finally, in the last section, the authors cover some tangential topics like tile-based games, mazes, game theory and AI, even search techniques. Really, a good roster.

One of the main reasons I purchased this book, aside from general interest, was to gain some knowledge to apply to a custom physics engine. While that’s still (in my mind) a debatable goal, I do feel like Mathematics & Physics for Programmers has helped, at least with the general concepts.

Unfortunately, I did not try to implement any of the equations or pseudo code from the book, so I won’t comment on the accuracy of the code. It’s possible there were errors that I did not notice. I typically don’t base my implementations directly from books. I use the books to understand the big picture, to get a sense of what’s possible, and to understand the vocabulary and terms that I need to search for. Then I’ll find resources online when it comes to writing the code.

What I will say, though, is that the text is not as good as the other big 3d math books, specifically 3D Math Primer for Graphics and Game Development by Fletcher Dunn or Mathematics for 3D Game Programming and Computer Graphics by Eric Lengyel. For sure, if you are only buying one or two math books for game development, get either of those first. However, if you are like me and you’ve already read the popular books on the topic, this isn’t such a bad choice as a refresher or to round out your knowledge.