Tricks of the Windows Game Programming Gurus

André LaMothe

Mentioned 4

Annotation World-renowned game wizard Andre Lamothe up20020701s his best-selling book for the current versions of Windows and DirectX! Andre Lamothe is the most recognizable name in game programming, with several best-sellers over the past ten years. DirectX 7a (for 2D) and 8 (for 3D) provide important new features for game programmers. The game programming fundamentals presented in this book--from physics to artificial intelligence--are required knowledge. The first edition of Tricks of the Windows Game Programming Gurus promised to be, simply, the most advanced game programming book ever written. Lamothe lived up to that promise and provides even more impressive coverage of game modeling and physics, programming logic, and artificial intelligence in this revised edition. Along with the fundamentals of game programming, Lamothe presents the Windows and DirectX coverage necessary to build the amazing 2D and 3D games that have made him the worlds best-selling game programming author. Andre Lamothes book, Tricks of the Game Programming Gurus was a seminal work for game programmers worldwide. In The Black Art of 3D Game Programming, Andre created to the first significant work on 3D games. His writing and teaching style are recognized by game programmers world-wide. Andre is the CEO of Xtreme Games and holds advanced degrees in Mathematics, computer science, and electrical engineering.

More on

Mentioned in questions and answers.

How do I determine whether or not two lines intersect, and if they do, at what x,y point?

FWIW, the following function (in C) both detects line intersections and determines the intersection point. It is based on an algorithm in Andre LeMothe's "Tricks of the Windows Game Programming Gurus". It's not dissimilar to some of the algorithm's in other answers (e.g. Gareth's). LeMothe then uses Cramer's Rule (don't ask me) to solve the equations themselves.

I can attest that it works in my feeble asteroids clone, and seems to deal correctly with the edge cases described in other answers by Elemental, Dan and Wodzu. It's also probably faster than the code posted by KingNestor because it's all multiplication and division, no square roots!

I guess there's some potential for divide by zero in there, though it hasn't been an issue in my case. Easy enough to modify to avoid the crash anyway.

// Returns 1 if the lines intersect, otherwise 0. In addition, if the lines 
// intersect the intersection point may be stored in the floats i_x and i_y.
char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, 
    float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
    float s1_x, s1_y, s2_x, s2_y;
    s1_x = p1_x - p0_x;     s1_y = p1_y - p0_y;
    s2_x = p3_x - p2_x;     s2_y = p3_y - p2_y;

    float s, t;
    s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
    t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);

    if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
        // Collision detected
        if (i_x != NULL)
            *i_x = p0_x + (t * s1_x);
        if (i_y != NULL)
            *i_y = p0_y + (t * s1_y);
        return 1;

    return 0; // No collision

BTW, I must say that in LeMothe's book, though he apparently gets the algorithm right, the concrete example he shows plugs in the wrong numbers and does calculations wrong. For example:

(4 * (4 - 1) + 12 * (7 - 1)) / (17 * 4 + 12 * 10)

= 844/0.88

= 0.44

That confused me for hours. :(

I'm a C# developer for the most part. Back in college I had classes on C/C++ so I "know C" and that's a good chunk of the reason I'm a C# developer.

However I've never had the chance to code in C/C++ professionally and I'd like to study how a modern game engine works, along with how an industrial grade C/C++ app operates.

The problem is, I have no idea where to start. As in, I downloaded the Quake 3 engine source code (which has been retronymed id Tech 3) and I'm not even sure where to start with it.

How should a sheltered C#/WinForms attack a massive C codebase like id Tech 3 or some other massive AAA engine?

Andre LaMothe pretty much taught me everything I know about game programming. Once you get through these two books, you'll pretty much know everything you need to know about 3d engines.

  1. Tricks of the Windows Game Programming Gurus
  2. Tricks of the 3D Game Programming Gurus - Advanced 3D Graphics and Rasterization

Otherwise, just try writing your own little engine for fun, see how far you get, what you're missing, and you'll soon start to understand the purpose of the other code you're looking at,

Also might want to try looking at the NeHe Gamedev Tutorials.

Say I am making a 2D Tile Based game in C# using System.Drawing for graphics.

OOP Layer for GDI?

The System.Drawing namespace provides access to GDI+ basic graphics functionality. ~ MSDN

Back when I was starting out Graphics & Game programming in C, a lot of books such as this one taught me that a software-rendered API like GDI was not efficient enough for Double-Buffered 2D games running at a decent FPS. So does Microsoft .NET's System.Drawing implementation fall into the same category? Does it use GDI & GDI+ under the hood, or can it use a different, faster backend?

How Much FPS Can I Hope For?

Even if System.Drawing can only use GDI, is it impossible to make a game run at a decent Frame rate, say 50-60 frames per second, with GDI?

It's not really a question of it being fast enough as it is it being suitable for the task you want to perform. In all honesty, it's quite easy to implement basic functionality to do the drawing you require using for instance XNA, and you get so much for free. There is simply no reason to go into System.Drawing for making games.

The book you linked in quite ancient, while it contains a few algorithms that never goes out of style most of it is really outdated.

As to how much FPS you can get from System.Drawing, you can probably get enough FPS from it from a simple tile based game. It's going to work if you do it that way, but it will hinder you from making real progress later on - especially as the threshold for making games using XNA is so low these days.

everybody, I've just finished my course Introduction to Systems Programming, the last part of it was C++, I learned a lot of stuff, but all I used to write was some console programs, I want to begin to write something new on c++ (something with graphic windows or maybe small game) to improve my knowledge, from which point can I start and which books can You recommend, I found a lot materials but I don't want to waste my time for bad books, so need Your advice, thanks in advance

I once read the book "Tricks of the windows game programming gurus"

All though it was the only book i ever read about game programming, I think it's a great book. All the samples are in C++.

It has a lot of mathematical and physics equations that have to do with simple game programming and graphics techniques. It also teaches you to work with DirectX.

I read it a while back (at least a couple of years) so it could be that it's outdated by now...