her's a simpler version of first function i posted
Code: Select all
void D3DGraphics::DrawLine2(int x1,int y1,int x2,int y2,int r,int g,int b)
{
int dx;
int dy;
double x=0;
double y=0;
double xratio;
double yratio;
if(x1>x2) //this makes sure it always draws from left to right;
{
int temp=x2;
x2=x1;
x1=temp;
temp=y2;
y2=y1;
y1=temp;
}
dx = abs( x2 - x1 );
dy = abs( y2 - y1 );
if(dx!=0&&dy!=0)
{
if(dx>dy) //close to horizontal line
{
yratio=(double)dy/(double)dx;
xratio=1;
}
else if(dx<dy) //close to vertical line
{
xratio=(double)dx/(double)dy;
yratio=1;
}
else if(dx==dy) //line must be drawn at 45 degree's in this case.
{
xratio=1;
yratio=1;
}
}
if(dx!=0&&dy!=0&&y2<y1)
{
yratio=-yratio;
}
if(dx==0&&dy!=0) //special condition ,the line is paralel with either x or y axis so the above forumla doesn't apply because of division by 0 case;
{
xratio=0;
if(y1>y2)
{
yratio=-1;
}
else
{
yratio=1;
}
}
if (dy==0&&dx!=0)
{
yratio=0;
xratio=1;
}
x=x1;
y=y1;
if(x1!=x2||y1!=y2)
{
if(y2>y1||y1==y2) //draws the lines that make an angle of less than 45 degree's with the x axis
{
for(;(int)x<=x2&&(int)y<=y2;) //the line drawing loop,it loops trough both x and y based on they'r ratio and it stops when it meets the end pixel coords.
{
PutPixel(((int)(x+0.5f)),((int)(y+0.5)),r,g,b);
x=x+xratio;
y=y+yratio;
}
}
if(y1>y2||y1==y2) //draws the lines that make an angle of less than 45 degree's with the x axis
{
for(;((int)x)<=x2&&((int)y)>=y2;)
{
PutPixel(x+0.5f,y+0.5,r,g,b);
x+=xratio;
y+=yratio;
}
}
}
}
i'd like to know if there's any way to count computing cycles for a function,that would help me truly test this functions:)