// ### BOILERPLATE ### // Orthographic Cube Firmware // Copyright (C) 2006 Peter Todd // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // ### BOILERPLATE ### // Line list stuff. #define abs(a) ((a) >= 0 ? (a) : -(a)) // Draws line i to the display buffer void draw_line(uint8_t ax, uint8_t ay, uint8_t bx, uint8_t by){ static int8_t deltax,deltay,error,x,y,ystep,xstep; static uint8_t steep; // We're using Bresenham's line algorithm for all this. steep = 0; if (abs(by - ay) > abs(bx - ax)) steep = 1; #if 1 if (steep){ // swap ax and ay x = ax; ax = ay; ay = x; // swap bx and by y = bx; bx = by; by = y; } #endif if (ax > bx){ // swap bx and ax x = bx; bx = ax; ax = x; // swap by and ay y = by; by = ay; ay = y; } deltax = bx - ax; deltay = abs(by - ay); error = 0; y = ay; if (ay < by){ ystep = 1; } else{ ystep = -1; } xstep = ax < bx ? 1 : -1; x = ax; while (x != (bx + xstep)){ if (steep){ display_pset((uint8_t)y,(uint8_t)x); } else{ display_pset((uint8_t)x,(uint8_t)y); } error += deltay; // !@#$% if that error << 1 is replaced by a multiply, it doesn't work!! if ((error << 1) >= deltax){ y += ystep; error -= deltax; } x += xstep; } }