2.5 The common classes

Well, there's a lot of stuff that's common... This section is dedicated to common.h... This file is the header for some functions we couldn't figure out where else to put them...

Let's start with two structures that are used throughout the whole library:


struct lg_colorstc {
	Uint8 r, g, b;
typedef struct lg_colorstc lg_color;

struct stc_rect {
	Uint32 x0, y0, xf, yf; 
typedef struct stc_rect lg_rect;
lg_color is used to represent an RGB triplet.
lg_rect is used to represent a rectangular area.


void map_pixels (char *map, SDL_Surface *s, int x0, int y0, int xf, int yf, int sensitivity, lg_color *transp, float qfactor);
char *map this is the pixel map will be stored.

SDL_Surface *s this is the surface you want to map the pixels from.

int x0, y0 this is the upper-left pixel of the rectangular area you want to map.

int xf, yf this is the lower-right pixel of the rectangular area you want to map.

int sensitivity this is how detailed you want your pixel map to be. 1 uses up 1 byte per pixel, while 2 uses up 1 byte for 4 pixels, so for n it represents n^2 pixels. In our tests, 5 proved to be very accurate. WARNING!!! You should always use the same sensitity for every object in the same scene!!! This may break too many things!!! JUST DON'T MESS IT UP!!!

lg_color *transp this is the color the function will detect as transparent.

float qfactor this value ranges from 0 to 1. It represents the percentage of pixels in the sensitivity^2 area that shouldn't be transparent in order to map the region as opaque. Special case is 0, which means that even if only 1 pixel is opaque, the whole region will be marked opaque. In case you're confused, use 0.5 for this and you should be fine.

This function is used to create a pixel map in order to improve the performance of pixel-by-pixel collision detection. If you have any doubts look at the samples or at the source code.

void rotate_map (char *map, char *rmap, int w_bitmap, int h_bitmap, float ang, int sens)
char *map: this is the pixel map you wish to rotate.

char *rmap: stores the rotated map.

int w_bitmap, h_bitmap: tells the height and width of the bitmap that corresponds to the bitmap you wish to rotate.

float ang this determines the angle that the map object should be rotated. Please note this is in radians and that 180 degrees = PI (3.14159) radians.

int sens this should be the same sensitivity you've used to create the map in the first place.

This function rotates a pixel map that has already been generated with map_pixels.

Important Notes:

There's a bunch of other functions in common.h, but they're used more frequently in the source code. If you wish to check collisions, just use the functions explained in the section 2.2 The lg_object class

We should document that stuff someday...

Back to Home