 by MirekCz » Dec 2, 2001 @ 6:50pm
by MirekCz » Dec 2, 2001 @ 6:50pm 
			
			Ello,<br>I have modified for my own use the EasyCE line drawing routine so it works now with 24:8 fixed math and it has got several modifications to increase performace. As-is it works in 320x240 mode so you will have to make slight changes to make it work with 240x320/whatever you use mode.<br>Hope it will help someone:)<br><br>PS.If you find some bugs/a way to increase this routine speed feel free to post it. If you find use in this routine feel free to post here, too. I might throw here more routines...<br><br>#define Abs(A) (((A)>(0))?(A):(-(A)))<br><br>void DrawLine(int x1,int y1,int x2,int y2,unsigned short color,unsigned short *pWhere)<br>{<br>      if (y1>y2)<br>      {<br>            //switch y1 and y2<br>            int h=y1;<br>            y1=y2;<br>            y2=h;<br>            h=x1;<br>            x1=x2;<br>            x2=h;<br>      }<br>      int len=Abs(x2-x1);<br>      if (Abs(y2-y1)>len) len=Abs(y2-y1);<br>      len=len>>8;<br>      if (len!=0)<br>      {<br>            int dx=(x2-x1)/len;<br>            int dy=(y2-y1)/len;<br>            if (y1<0)<br>            {<br>                  if (dy>0)<br>                  {<br>                        i=-(y1/dy)+1;<br>                        x1+=dx*i;<br>                        y1+=dy*i;<br>                        len-=i;<br>                  }<br>                  else len=0;<br>            }<br>            if (len>0) if (x1<0)<br>            {<br>                  if (dx>0)<br>                  {<br>                        i=-(x1/dx)+1;<br>                        x1+=dx*i;<br>                        y1+=dy*i;<br>                        len-=i;<br>                  }<br>                  else len=0;<br>            }<br>            if (len>0) if (y2>(240<<8))<br>            {<br>                  if (dy>0)<br>                  {<br>                        i=((y2-(240<<8))/dy)+1;<br>                        x2-=dx*i;<br>                        y2-=dy*i;<br>                        len-=i;<br>                  }<br>                  else len=0;<br>            }<br>            if (len>0) if (x2>(320<<8))<br>            {<br>                  if (dx>0)<br>                  {<br>                        i=((x2-(320<<8))/dx)+1;<br>                        x2-=dx*i;<br>                        y2-=dy*i;<br>                        len-=i;<br>                  }<br>                  else len=0;<br>            }<br>            for (i=0;i<len;i++)<br>            {<br>                  pWhere[((y1>>8)<<8)+((y1>>8)<<6)+(x1>>8)]=color;<br>                  x1+=dx;<br>                  y1+=dy;<br>            }<br>      }<br>}<br><br>input - x,y values 24:8 fixed math, 16bit color and a pointer to backbuffer/whatever (currently 320x240, with few simple modifications it will work with 240x320 etc.
			With best regards,
         Mirek Czerwinski