Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 07 July 2012 - 12:00 PM
Posted 07 July 2012 - 12:11 PM
Posted 07 July 2012 - 02:14 PM
Posted 07 July 2012 - 02:32 PM
void Surface::line(int x1,int y1,int x2,int y2,uint color=0xFFFFFFFF) { float dx=x2-x1; float dy=y2-y1; if(dx==0) { vline(x1,y1,dy,color); return; } if(dy==0) { hline(x1,y1,dx,color); return; } if(fabs(dx)>fabs(dy)) { if(dy<0) { float temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; dy=-dy; } float cx=dx/dy; float x=x1; for(int j=y1;j<y2;j++) { hline(x,j,cx,color); x+=cx; } } else { if(dx<0) { float temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; dx=-dx; } float cy=dy/dx; float y=y1; for(int i=x1;i<x2;i++) { vline(i,y,cy,color); y+=cy; } } }This code is using my own SDL/other drawing library wrapper, so youd need to, for instance, make sure all the vline and hline calls are rewritten for whatever graphics library you use (whether its _gfx, _draw, or just plain SDL).
void hline(int x,int y,int width,Uint32 color) { if(w<0) { x+=w; w=-w; } r.x=x; r.y=y; r.w=w; r.h=1; SDL_FillRect(screen,&r,color); } void vline(int x,int y,int height,Uint32 color) { if(h<0) { y+=h; h=-h; } r.x=x; r.y=y; r.w=1; r.h=h; SDL_FillRect(screen,&r,color); }
Posted 07 July 2012 - 02:32 PM
Posted 07 July 2012 - 02:36 PM
Posted 07 July 2012 - 03:39 PM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.