Jump to content
  • Advertisement
Sign in to follow this  
fir

error cases for fixedpoint drawline

This topic is 2037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Times a go i was to lazy to get and test bressenham drawline routine

so i just took it strightforward, counted dx, dy slope on each pixels

and used fixedpoints (16-16 bit over 32 bit int)

void DrawLineUnsafe(int xs, int ys, int xk, int yk, unsigned color)
{
 
   int abs_width  = abs(xk-xs);
   int abs_height = abs(yk-ys);
 
   int how_many_segmants =  max(abs_width, abs_height);
 
   SetPixel(xs, ys, color);
 
   if(how_many_segments==0) return;
 
   int x = xs<<16;
   int y = ys<<16;
 
   int dx =  ((xk-xs)<<16)/how_many_segments;
   int dy =  ((yk-ys)<<16)/how_many_segments;
 
 
   for(int i=0; i<how_many_segments; i++)
   {
      x += dx ;
      y += dy ;
 
      SetPixel(x>>16, y>>16, color); 
 
                 //setpixel is inline routine bitmap[y*width+x]=color
 
   }
 
}

 
1) is this code in general usable? can it be optymized? (Imo it should 
be probably ok not sure if it is slower compered to bressenham and how much?
 
2) I cannot count the error that come from the fact that there are used 16 bit fixedpoints here - Is someone able to count/show some corner cases where error in drawing will show - or there is some range or x/y where it is errorless
and works like bressenham? I culd not find thie error - is maybe someone able to say something about it?
 
(the natural range for line begin and end  it should work seem to me could be 0 to 65535  or -32768 to 32 767 but will it work okay for this range?)
 
tnx
Edited by fir

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!