-
3
pages
-
English
-
Documents
Description
A 2d collision detection tutorial,including a C implementation.first draft, please email comments!Ulf Ekstr¨omulfek@ifm.liu.seJuly 12, 20021 Introduction improve it later on, but for now it will suffice.This tutorial tries to explain a commonly used ap-proach to 2d collision detection for use in games. A 2.1 The bitmaskspecial ’mask’ is created for each sprite, and is usedIn the following discussion we assume a 32-bit ma-for the overlap detection. This method is suitablechine, but the same points are valid for 16 or 64 bitsfor pre-rendered or hand-drawn graphics as it givesaswell. Abitmaskisessentiala1bitperpixelimage,pixel-perfect collision detection. The method is alsoand to store the bitmask we use a struct likepretty fast and does not slow down the game notica-struct bitmask{bly when compared to other existing methods.int width, height;The method has been commonly used in gamesunsigned long *bits;ever since the days of the Commodore 64, and is well}; .understood even though the actual implementationcan be a bit tricky to get right. A GPL’d implemen- The bits pointer is used to access the actual mask.tation of the ideas in this tutorial can be found at on Each line of bits in the mask requires a whole num-1the internet . ber of int’s, to speed up the intersection tests we aredoing later. The remaining bits are set to 0. Assum-ing we have allocated some memory for the bits it is2 How to know when things now easy to set and clear bits in the mask ...
-
Publié par
-
Langue
English