# Plz debug my code

I am using a routine to map a triangle from one surface to another.
The problem is that the function below chooses the correct pixel to draw on the destination surface, but the pixel selected from the source surface has a constant displacement from the correct source pixel.

Here is the function:

// Copy the colour from the source surface to a point on the destiation surface
int BB_renderPixel(SDL_Point destpoint, SDL_Surface* source, SDL_Surface* dest, SDL_Point alpha, SDL_Point bravo, SDL_Point charlie, SDL_Point tango, SDL_Point uniform, SDL_Point victor){

``````//    Locate the pixel relative to the destination triangle.
float Aleph = ((bravo.x - alpha.x) * (charlie.y - alpha.y) - (bravo.y - alpha.y) * (charlie.x - alpha.x)); // = BB_Orient2d
float Bravo = (destpoint.x * (charlie.y - alpha.y) - destpoint.y * (charlie.x - alpha.x)) / Aleph;
float Charlie = (-destpoint.x * (bravo.y - alpha.y) + destpoint.y * (bravo.x - alpha.x)) / Aleph;

//    Locate the corresponding pixel sourcepoint(x, y) in the source triangle tango(x, y), uniform(x, y), victor(x, y)
//    Round (x, y) to an integer and sample (or else do some magic with floating point coordinates.)
//    Add 0.5 then round down to get the nearest int.
SDL_Point sourcepoint;
sourcepoint.x = floor(tango.x + Bravo * (uniform.x - tango.x) + Charlie * (victor.x - tango.x) + 0.5);
sourcepoint.y = floor(tango.y + Bravo * (uniform.y - tango.y) + Charlie * (victor.y - tango.y) + 0.5);
int bpp = source->format->BytesPerPixel;
int bpp2 = dest->format->BytesPerPixel;
SDL_Color p = *(SDL_Color *)(source->pixels + sourcepoint.y * source->pitch + sourcepoint.x * bpp);
*(SDL_Color *)(dest->pixels + destpoint.y * dest->pitch + destpoint.x * bpp2) = p;
return 1;
``````

}

For the minimum code to compile and test, and pictures, download this: