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.

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.

3D Engine, C++, DirectX, Game Engine, Graphics, Physics

Creating a 3D Game Engine (Part 24)


 

It’s been some time since the last 3D engine update, but I’m still sticking with it. Currently I am working on getting a physics engine implemented. The video you see above is the first glimpse of this custom physics engine. Obviously it’s ultra basic right now, but it’s a start. The algorithm is based on a verlet integrator, and the code is running using DirectCompute on the GPU.

To be honest, it’s pretty hacked together right now, and the bounds/bouncing behavior is hard-coded. But, hey, it’s something! I also tweaked the style of the demo to more closely align with other demos from researchers (and the clean flat-shaded style looks a bit more classy).

I’m planning on expanding this significantly, but still have a lot of work ahead of me. Though I’m still questioning whether GPGPU is the way to go with this, especially since there are 8-core CPUs available for consumers (and which I am running now). There is also added difficulty and limitations of DirectCompute rather than straight C++. But if there are big gains on the GPU obviously I would like to go that route. Definitely more testing to do here, but progress is being made. Stay tuned.

Gaming, Physics, Review

Review: Game Physics Pearls by Gino van den Bergen & Dirk Gregorius

GamePhysicsPearls

Game Physics Pearls has been a book on my wishlist for a while, and I’ve finally got the chance to finish reading it and putting up this review. The text is edited by Gino van den Bergen and Dirk Gregorius, and each chapter is written by a unique author. I found that a lot of ground was covered while still keeping the book somewhat cohesive. It doesn’t feel like a complete random mash-up, and the progression is nice.

Some of the chapter content includes: basic mathematics, game physics pitfalls, broad phase, narrow phase, GJK, SPH, parallel particle simulation, ropes, soft bodies, and verlet integration. Even after reading several game physics books, there was still a decent amount of information I had not seen before. I especially appreciated the chapter on verlet integration (and the subsequent chapter on cloth physics that builds upon it). So many of the books I’ve seen seem to focus on Euler integration techniques and it’s rare to see much talk of verlet integration (or position based dynamics for that matter). This is the direction I am going with my physics engine, so it was nice to see some coverage.

Overall I was impressed with the quality of the book. Sometimes with these “gem” style books, it can be a hit or miss if the chapter is relevant to your needs. I did not think that was the case here. Nearly all the chapters had some pertinent information, and (while maybe not directly relevant to my current project) were at least interesting to read. I did not feel bogged down with math, most of the explanations made sense and there wasn’t too much needless minutia.

I would definitely recommend this title to anyone interested in video game physics. While there are other books that may be better places to start (as the book sort of assumes you know the basics already) this would not be a bad book to add to the collection. There are actually only a couple game physics books that I *haven’t* read, so it’s getting to the point I will need to stop researching and start writing code. Wish me luck!

Physics, Review

Review: Physics for Game Programmers by Grant Palmer

PhysicsForGameProgrammers

Today I will be reviewing Physics for Game Programmers by Grant Palmer, another stepping stone on my quest to build a custom physics engine. Overall I enjoyed reading the book, and I feel like I learned a lot of general things but not enough to base a physics implementation on. Please read on for more details.

What I found most interesting about this text was the explanations of certain aspects of physics that I had not seen covered before. I have already read about 3 or 4 different books all on game physics, and I was expecting this title to be more of a refresher than anything. However, I was surprised to find a lot of things I didn’t know about. In particular, the coverage of drag forces was extremely detailed including things like turbulent and laminar flow and the Reynolds number. Some of the topics covered include: Newtonian mechanics, kinematics, projectiles, collisions, sports simulation (golf, soccer, basketball), cars and motorcycles, boats, airplanes, rockets and missiles, explosions, and lasers. Quite a lot in a little under 500 pages.

There is certainly a breadth of knowledge living inside this book. It was undeniably an interesting read, and I felt like I learned a decent amount. However, I am not sure it really got me any closer to building the physics engine I have set out to create. Let me explain. While there are equations listed in the text, and some example code is given, it is mostly used to support the 2D sample applications. I am not sure there is much I could just pull from the book an paste into a 3D engine. The concepts are sound, and it wouldn’t be a huge stretch to make it work, it’s just not spelled out for you. To be fair, some topics are explained well, like his discussion on differential equations and drag forces among other things.

My main gripe with the book is that it did not really try to explain rigid-body dynamics at all. There are some interesting things talked about, like sports and boats and planes and all that. And certainly there are probably a ton of sports games and simulators that would benefit from that focus. For my purposes, I was looking more for a rigid or soft body solver, and how bodies can interact with each other. Unfortunately, that was not discussed at all.

It’s not that I want to get down on Physics for Game Programmers, and I think Grant Palmer did a great job within the scope of what he was trying to do. The book was entertaining and relevant, it just wasn’t a one-stop-shop for all your physics needs. However, it does cover some basic things well, and includes topics not even touched by some of the other books I’ve read. That alone would make it worth reading, just set your expectations correctly. Once you are ready to make an actual implementation, you will likely need to seek other books or papers. But I guess it is almost always the case as one book can rarely impart all the knowledge you need in any given topic. To sum up: I liked it but wanted more.

Physics, Review

Review: Physics for Game Developers: Science, math, and code for realistic effects by David M Bourg & Bryan Bywalec

PhysicsGameDevs

I can say I had a pretty good time with Physics for Game Developers: Science, math, and code for realistic effects by David M Bourg & Bryan Bywalec. It is a very approachable text, and makes a somewhat complex topic more manageable with concrete examples. It’s definitely a book about 3D physics, but many of the samples are done in 2D for clarity. I did not find this to be an issue, and most of the equations and code were digestible. I did see some heat on the reviews, saying that there were errors in some of the code. I could not verify this, but just from reading the book the authors seemed knowledgeable.

At the beginning, each chapter covers a fundamental aspects of physics. Later they go into examples that could be used in a game. Some of the topics covered include: Newton’s laws of motion, kinematics, force, kinetics, collisions, projectiles, particles, rigid-bodies, springs, aircraft, boats, cars, guns, sports. In the last section it goes over some emerging technology and how they work, like touch screens, motion-sensors, 3D displays, and the physics of sound. I very much enjoyed the whole book, and liked that there were practical examples to go along with every topic.

Many technical books can get lost in the math equations, but I found this text to have a good amount of explanation and not too many long proofs. This could be a pro or a con. On one hand it makes reading it a little more straight-forward, but on the other-hand, it may leave out some important details when it comes time to create your own implementation. I’m not sure I would want to base a physics engine solely on this book. It’s not that it was bad, but it was more of a general concept thing than giving you all the code. That said, there is a good amount of code in the book, it just may not be as complete as some other sources.

Overall I was satisfied with Physics for Game Developers. It may not be my favorite physics book (I found Game Physics Engine Development to be a lot better for my purposes), it still seemed worth reading. Now I am beginning to realize the creating a physics engine will not be easy, but the more I read the more I feel capable of this task. I think the book has helped.

C++, Physics, Review

Review: Game Physics Engine Development: How to Build a Robust Commercial-Grade Physics Engine for your Game by Ian Millington

Game Physics Engine Development

In this review, I will discuss my experience with Game Physics Engine Development: How to Build a Robust Commercial-Grade Physics Engine for your Game by Ian Millington. This is actually the first book I’ve ever read solely on game physics and I think I made the right choice here. Although I have developed several physics engines previously, they were only in 2D and the extra dimension complicates matters significantly. Game Physics Engine Development is a book specifically about 3D game physics, though the author does make a short reference to 2D physics at the end. I felt like the book had just enough math to explain the concepts, without getting bogged down in technical minutia. I also enjoyed the friendly writing style, the approachable implementations, and a rational coding standard.

Ian Millington’s book covers a lot of ground, and each chapter builds up a single aspect of the engine. Many chapters could stand alone in one aspect or another, though they do come together at the end. Some of the topics covered include: basic 3D math (vectors, matrices, quaternions), laws of motion, particles, rigid bodies, mass aggregate physics, springs, collision, contact resolution, velocity and acceleration, torque, friction, broad-phase collision detection, bounding volumes, and more. While the book is “only” 552 pages, there are a ton of things packed into those pages. I found the coverage to be fairly in-depth, without getting lost of mathematical proofs or anything like that. The book is very practical in that way, and a lot of the code samples could easily be the basis of a real implementation.

Overall I enjoyed the book at lot, and breezed through it within a week, eagerly anticipating each new chapter. Being the only physics book I’ve read so far, I don’t feel 100% confidant creating a physics engine myself just yet. However, I do feel it has explained a lot of key concepts necessary in physics development. The book was everything I was hoping for, and gets my recommendation.

Graphics, Physics

Insane Physics Simulation From Nvidia


 

This has got to be one of the more insane physics demos I’ve seen so far. Most physics engine handles the basic rigid bodies and such, but start to fall apart with more complex interactions (i.e. fluid and cloth simulations). With the demo shown above, from Nvidia, it seems these difficult problems have been solved. Cloth, fluid, smoke, and rigid or soft bodies, all interacting with each other? It looks great. The author, Mike Macklin, has even posted a pre-release of the SIGGRAPH paper explaining the technique here. I took a quick look, and I will be giving it some serious investigation soon. These types of complex physics interactions are exactly what I am trying to do myself. Hopefully the implementation will not be that difficult, but I have a feeling I have a long road ahead of me. Wish me luck!