Tricks of the Windows Game Programming Gurus:Vector Rasterization and 2D Transformations

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

#### Data Types and Structures

The next set of code elements includes the types and data structures that the engine uses. I’m going to list them all, but be warned that there are a couple you haven’t seen yet that have to do with the Blitter Object Engine (BOB). To be consistent, let’s take a look at everything at once:

    // basic unsigned types

    typedef unsigned short USHORT;

    typedef unsigned short WORD;

    typedef unsigned char  UCHAR;

    typedef unsigned char  BYTE;

    // container structure for bitmaps .BMP file

    typedef struct BITMAP_FILE_TAG

            {

            BITMAPFILEHEADER bitmapfileheader;  // this contains the

                                                // bitmapfile header

            BITMAPINFOHEADER bitmapinfoheader;  // this is all the info

                                                // including the palette

            PALETTEENTRY     palette[256];      // we will store

                                                // the palette here

            UCHAR            *buffer;           // this is a pointer

                                                // to the data

            } BITMAP_FILE, *BITMAP_FILE_PTR;

    // the blitter object structure BOB

    typedef struct BOB_TYP

            {

            int state;          // the state of the object (general)

            int anim_state;     // an animation state variable, up to you

            int attr;           // attributes pertaining

                                // to the object (general)

            int x,y;            // position bitmap will be displayed at

            int xv,yv;          // velocity of object

            int width, height;  // the width and height of the bob

            int width_fill;     // internal, used to force 8*x wide surfaces

            int counter_1;      // general counters

            int counter_2;

            int max_count_1;    // general threshold values;

            int max_count_2;

            int varsI[16];      // stack of 16 integers

            float varsF[16];    // stack of 16 floats

            int curr_frame;     // current animation frame

            int num_frames;     // total number of animation frames

            int curr_animation; // index of current animation

            int anim_counter;   // used to time animation transitions

            int anim_index;     // animation element index

            int anim_count_max; // number of cycles before animation

            int *animations[MAX_BOB_ANIMATIONS]; // animation sequences

            LPDIRECTDRAWSURFACE4 images[MAX_BOB_FRAMES]; // the bitmap images

                                                         // DD surfaces

            } BOB, *BOB_PTR;

    // the simple bitmap image

    typedef struct BITMAP_IMAGE_TYP

            {

            int state;          // state of bitmap

            int attr;           // attributes of bitmap

            int x,y;            // position of bitmap

            int width, height;  // size of bitmap

            int num_bytes;      // total bytes of bitmap

            UCHAR *buffer;      // pixels of bitmap

            } BITMAP_IMAGE, *BITMAP_IMAGE_PTR;

    // blinking light structure

    typedef struct BLINKER_TYP

                   {

                   // user sets these

                   int color_index;       // index of color to blink

                   PALETTEENTRY on_color; // RGB value of "on" color

                   PALETTEENTRY off_color;// RGB value of "off" color

                   int on_time;           // number of frames to keep "on"

                   int off_time;          // number of frames to keep "off"

                   // internal member

                   int counter;     // counter for state transitions

                   int state;       // state of light, -1 off, 1 on, 0 dead

                   } BLINKER, *BLINKER_PTR;

    // a 2D vertex

    typedef struct VERTEX2DI_TYP

            {

            int x,y; // the vertex

            } VERTEX2DI, *VERTEX2DI_PTR;

    // a 2D vertex

    typedef struct VERTEX2DF_TYP

            {

            float x,y; // the vertex

            } VERTEX2DF, *VERTEX2DF_PTR;

    // a 2D polygon

    typedef struct POLYGON2D_TYP

            {

            int state;        // state of polygon

            int num_verts;    // number of vertices

            int x0,y0;        // position of center of polygon

            int xv,yv;        // initial velocity

            DWORD color;      // could be index or PALETTENTRY

            VERTEX2DF *vlist; // pointer to vertex list

            } POLYGON2D, *POLYGON2D_PTR;

    // matrix defines

    typedef struct MATRIX3X3_TYP

            {

            float M[3][3]; // data storage

            } MATRIX3X3, *MATRIX3X3_PTR;

    typedef struct MATRIX1X3_TYP

            {

            float M[3]; // data storage

            } MATRIX1X3, *MATRIX1X3_PTR;

    typedef struct MATRIX3X2_TYP

            {

            float M[3][2]; // data storage

            } MATRIX3X2, *MATRIX3X2_PTR;

    typedef struct MATRIX1X2_TYP

            {

            float M[2]; // data storage

            } MATRIX1X2, *MATRIX1X2_PTR;

Not bad; nothing new, really. Basic types, all the bitmap stuff, polygon support, and a little matrix math.

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.