I'm using the SDL for graphics. and i am trying to write a function for drawing a line,
this is what i came up with
When angles are extreem it doesnt draw quite right. i helped with problem by drawing calculattes x.00 -> x1 x.00 to garner more y coordinates too use, still didnt help to much
any ideas on a better way to code this?
Code:
void Artist::drawLine(int f, int p, int u , int t, Uint8 r, Uint8 g, Uint8 b)
{
float rise = (p * 1.0) - (t * 1.0);
float run = (f * 1.0) - (u * 1.0);
float slope = rise / run;
float y,x, d;
d = (slope * f ) - p ;
for ( f = f * 100, u = u * 100; f <= u; f ++)
{
drawPixel(surface, f / 100 , ( (f*slope) + d ) / 100, r,g,b);
}
}