Quote:

> I can't use others libraries , i need to use pset to draw the line.

> I need the way to do this using pset becuase i can't make the way.

Why do you have to use PSet()? Or do you mean you have to use _VB_? If the

latter then you'll get better performance using the SetPixelV() API call,

and if you're drawing lots of lines then operating on the bitmap data of a

DIB is incredibly quick and allows you to perform overall clipping using a

Radix sort of the coordinates rather than per pixel. Here's a dead simple

conversion of a Bresenham routine originally off GameDev.net including the C

source in case you'd prefer to convert it yourself:

'*** Begin C version

deltax = abs(x2 - x1); // The difference between the x's

deltay = abs(y2 - y1); // The difference between the y's

x = x1; // Start x off at the first pixel

y = y1; // Start y off at the first pixel

if (x2 >= x1) // The x-values are increasing

{

xinc1 = 1;

xinc2 = 1;

Quote:

}

else // The x-values are decreasing

{

xinc1 = -1;

xinc2 = -1

Quote:

}

if (y2 >= y1) // The y-values are increasing

{

yinc1 = 1;

yinc2 = 1;

Quote:

}

else // The y-values are decreasing

{

yinc1 = -1;

yinc2 = -1;

Quote:

}

if (deltax >= deltay) // There is at least one x-value for every

y-value

{

xinc1 = 0; // Don't change the x when numerator >=

denominator

yinc2 = 0; // Don't change the y for every iteration

den = deltax;

num = deltax / 2;

numadd = deltay;

numpixels = deltax; // There are more x-values than y-values

Quote:

}

else // There is at least one y-value for every

x-value

{

xinc2 = 0; // Don't change the x for every iteration

yinc1 = 0; // Don't change the y when numerator >=

denominator

den = deltay;

num = deltay / 2;

numadd = deltax;

numpixels = deltay; // There are more y-values than x-values

Quote:

}

for (curpixel = 0; curpixel <= numpixels; curpixel++)

{

PutPixel(x, y); // Draw the current pixel

num += numadd; // Increase the numerator by the top of the

fraction

if (num >= den) // Check if numerator >= denominator

{

num -= den; // Calculate the new numerator value

x += xinc1; // Change the x as appropriate

y += yinc1; // Change the y as appropriate

}

x += xinc2; // Change the x as appropriate

y += yinc2; // Change the y as appropriate

Quote:

}

'***

'*** Begin VB version

Public Sub BresGameDev(ByVal inDC As Long, ByVal x1 As Long, _

ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal inCol As

Long)

Dim DeltaX, DeltaY As Long

Dim x As Long, y As Long

Dim XInc1 As Long, YInc1 As Long

Dim XInc2 As Long, YInc2 As Long

Dim Den As Long, Num As Long, NumAdd As Long, NumPixels As Long

Dim CurPixel As Long

DeltaX = Abs(x2 - x1) 'The difference between the x's

DeltaY = Abs(y2 - y1) 'The difference between the y's

x = x1 'Start x off at the first pixel

y = y1 'Start y off at the first pixel

If (x2 >= x1) Then 'The x-values are increasing

XInc1 = 1

XInc2 = 1

Else 'The x-values are decreasing

XInc1 = -1

XInc2 = -1

End If

If (y2 >= y1) Then 'The y-values are increasing

YInc1 = 1

YInc2 = 1

Else 'The y-values are decreasing

YInc1 = -1

YInc2 = -1

End If

If (DeltaX >= DeltaY) Then 'There is at least one x-value for every

y-value

XInc1 = 0 'Don't change the x when numerator >=

denominator

YInc2 = 0 'Don't change the y for every iteration

Den = DeltaX

Num = DeltaX / 2

NumAdd = DeltaY

NumPixels = DeltaX 'There are more x-values than y-values

Else 'There is at least one y-value for every

x-value

XInc2 = 0 'Don't change the x for every iteration

YInc1 = 0 'Don't change the y when numerator >=

denominator

Den = DeltaY

Num = DeltaY / 2

NumAdd = DeltaX

NumPixels = DeltaY 'There are more y-values than x-values

End If

For CurPixel = 0 To NumPixels - 1

SetPixelV inDC, x, y, inCol 'Draw the current pixel

Num = Num + NumAdd 'Increase the numerator by the top of the

fraction

If (Num >= Den) Then 'Check if numerator >= denominator

Num = Num - Den 'Calculate the new numerator value

x = x + XInc1 'Change the x as appropriate

y = y + YInc1 'Change the y as appropriate

End If

x = x + XInc2 'Change the x as appropriate

y = y + YInc2 'Change the y as appropriate

Next CurPixel

End Sub

'***

Hope this helps,

Mike

-- EDais --

- Microsoft Visual Basic MVP -

WWW: Http://EDais.earlsoft.co.uk/