nezvers

draw_line optimized Brasenham

Jun 21st, 2021
937
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void draw_line(s32 x1, s32 y1, s32 x2, s32 y2){
  2.     //faster Bresenham by Endesga
  3.     s32 xd = x2 - x1;
  4.     s32 yd = y2 - y1;
  5.     s32 hs = 0x8000;
  6.     s32 vs = 0x8000;
  7.     s32 amount = max(abs(xd), abs(yd));
  8.     s32 xs = ((xd << 16) / amount);
  9.     s32 ys = ((yd << 16) / amount);
  10.    
  11.     for (u16 i = 0; i < amount; i++){
  12.         hs += xs;
  13.         vs += ys;
  14.         draw_pixel(x1 + (hs >> 16), y1 + (vs >> 16));
  15.     }
  16. }
RAW Paste Data