247: GameDev: 1.1 Plus 2.2 Is Not 3.3. What?
Listen now
Description
Be careful with floating point numbers when building games. You could be in for some big surprises if you don’t understand how computers work with fractional values. You might be able to write an app to keep track of your friend’s addresses without using any floating point numbers. But most games will need math that uses fractional values. That is if you want any kind of game with smooth motion. If your game consist of typing letters in words, then maybe you won’t have to worry about this. But if you want those letters to move slowly across the screen as the user drags them into place, then you’ll need to use fractional values. You might think that you can get away from this by just having really small whole numbers. Maybe you track individual pixels. The problem is that computers are really fast these days and can do a lot of work even between pixels. You might find that the computer tries to move the image by 1 thousandth of a pixel. If you only work with whole numbers, then this becomes zero. And your image will be stuck without moving at all because the computer is so fast that it’s always trying to move it by a tiny amount. Instead of limiting yourself to whole numbers, you’ll need to understand how to use fractional values. And that means you need to understand how to use floating point numbers. You should also listen to episode #112 about the float data type. I try not to repeat information between episodes so you’ll find both this episode and the earlier one have something for you.
More Episodes
This is the first in a series of comments about the book “How To Code C++ From a Simple Idea To a Game You’ll Understand!” Each episode will be short and focused. You can watch the video versions on YouTube at https://www.youtube.com/channel/UC4K_WBflLr2Cz0Sje_xTXkA You can also get your own copy...
Published 01/28/22
This is an interview with Conor Hoekstra about C++ algorithms and ranges. Conor presented my favorite talk at CppCon 2019 called Algorithm Intuition. I asked him to talk about algorithms on this podcast and he agreed. This just proves again why CppCon is the best place to be when you want to...
Published 09/25/19
Published 09/25/19