draw a line using pset 
Author Message
 draw a line using pset

How can i made to draw a line, knowing the coordinates of the two extremes ,
using pset instead of using line??

--
Juan Carlos (El fortinero)
LV-VLZ
EL CHURRINCE NRO 100
VATSIM: Id:826992 / IVAO: Id :118581
Fedex: Senior Captain FDX602 FAA-006 "Teniente Nolibos"



Sat, 02 Apr 2005 02:27:51 GMT  
 draw a line using pset

Quote:
> How can i made to draw a line, knowing the coordinates of the two extremes
,
> using pset instead of using line??

Look up the Bresenham line drawing routine, or just use a simple Linear
function to step from one coordinate to the other and draw pixels along the
way.  The latter is easier but a lot slowed and far more wasteful on it's
plotting.  There's _lots_ of examples of Bresenham's routines about though,
have a look at the circle drawing one too, it's pretty neat :)
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Sat, 02 Apr 2005 03:57:18 GMT  
 draw a line using pset
I have 32-bit assembler code I wrote in my asm library for doing this...  is
that any help?   :-)

David
lilchips.com



Quote:
> > How can i made to draw a line, knowing the coordinates of the two extremes
> ,
> > using pset instead of using line??

> Look up the Bresenham line drawing routine, or just use a simple Linear
> function to step from one coordinate to the other and draw pixels along the
> way.  The latter is easier but a lot slowed and far more wasteful on it's
> plotting.  There's _lots_ of examples of Bresenham's routines about though,
> have a look at the circle drawing one too, it's pretty neat :)
> Hope this helps,

>     Mike

>  -- EDais --

>  - Microsoft Visual Basic MVP -
> WWW: Http://EDais.earlsoft.co.uk/





Sat, 02 Apr 2005 04:27:11 GMT  
 draw a line using pset
On Mon, 14 Oct 2002 20:57:18 +0100, "Mike D Sutton"

Quote:

>... Bresenham line drawing routine...

Not being a trig wiz <g>, I've always used LineDDA for that.

-Tom
(please post replies to the newsgroup)



Sat, 02 Apr 2005 04:42:51 GMT  
 draw a line using pset
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.


Quote:
> > How can i made to draw a line, knowing the coordinates of the two
extremes
> ,
> > using pset instead of using line??

> Look up the Bresenham line drawing routine, or just use a simple Linear
> function to step from one coordinate to the other and draw pixels along
the
> way.  The latter is easier but a lot slowed and far more wasteful on it's
> plotting.  There's _lots_ of examples of Bresenham's routines about
though,
> have a look at the circle drawing one too, it's pretty neat :)
> Hope this helps,

>     Mike

>  -- EDais --

>  - Microsoft Visual Basic MVP -
> WWW: Http://EDais.earlsoft.co.uk/





Sat, 02 Apr 2005 05:08:07 GMT  
 draw a line using pset

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/




Sat, 02 Apr 2005 05:29:26 GMT  
 draw a line using pset
I have to use pset because i can't use any of the primitives of the
lenguajes , i have to build my own primitive.
The same for circle and spline.



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_?



Sat, 02 Apr 2005 05:54:26 GMT  
 draw a line using pset

Quote:
> I have to use pset because i can't use any of the primitives of the
> lenguajes , i have to build my own primitive.
> The same for circle and spline.

PSet() is more than likely just calling SetPixelV() behind the scenes
anyway, it's hardly 'cheating' or detrimental to your goal.  Incidentally,
why do you have to write them yourself at this high level?  Just out of
personal interest or for conversion to another language perhaps?

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Sat, 02 Apr 2005 06:06:12 GMT  
 draw a line using pset
Work at the university , the profesor want us make a mini autocad and don't
use line.



Quote:
> > I have to use pset because i can't use any of the primitives of the
> > lenguajes , i have to build my own primitive.
> > The same for circle and spline.

> PSet() is more than likely just calling SetPixelV() behind the scenes
> anyway, it's hardly 'cheating' or detrimental to your goal.  Incidentally,
> why do you have to write them yourself at this high level?  Just out of
> personal interest or for conversion to another language perhaps?

>     Mike

>  -- EDais --

>  - Microsoft Visual Basic MVP -
> WWW: Http://EDais.earlsoft.co.uk/





Sat, 02 Apr 2005 06:17:13 GMT  
 draw a line using pset

Quote:
> Work at the university , the profesor want us make a mini autocad and
don't
> use line.

Then you'll really want to use the DIB data method then, PSet() or
SetPixelV() won't give you the refresh rates you need for that kind of
complex vector driven work.  It's not as much work as you may think, once
you've got the data array, plotting pixels is simply a case of getting the
relevant offset into that array, with a 2D array it's even easier but
slower.  You'll have to have a crack at clipping too, but again that's not
difficult to write a simple routine and radix sorting all the points in one
shot is dead fast.  This will also open you things like scan-line conversion
and different draw modes, it depends how advanced you want to go.  If you
need any specific help then let me know, I've written drawing systems like
this from the ground up on a couple of occasions and could probably answer
your queries in the area.
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Sat, 02 Apr 2005 06:52:11 GMT  
 draw a line using pset
On Mon, 14 Oct 2002 19:17:13 -0300, "Juan Carlos \(El fortinero\)"

Quote:

>Work at the university , the profesor want us make a mini autocad and don't
>use line.

Just my two cents, but I agree with Mike completely.  Don't work on
the screen itself with PSet.  Instead, work on an array of Longs,
where each Long corresponds to a screen pixel.  When you're done
processing (gone through (parts of) the array and changed some values)
you can blast the whole thing to the screen in one go.

It'll make PSet look like a tricycle next to your Porsche.

Jim Deutch



Sun, 03 Apr 2005 00:04:10 GMT  
 draw a line using pset

Quote:
> Just my two cents, but I agree with Mike completely.  Don't work on
> the screen itself with PSet.  Instead, work on an array of Longs,
> where each Long corresponds to a screen pixel.  When you're done
> processing (gone through (parts of) the array and changed some values)
> you can blast the whole thing to the screen in one go.

Definitely, or if you're going to perform graphics manipulation to the array
that involves editing existing pixel data rather than just replacing it then
you may way to create it as a UDT type, something like:

'***
Private Type Pixel
    Blue As Byte
    Green As Byte
    Red As Byte
    Alpha As Byte
End Type
'***

Note: this is fully compatible with 32-bit GDI DIB's, automatically DWord
aligns and can be manipulated as a flat data array if you're sending it out
to a C++ DLL for the drawing.  The Pixel library on my page (Which uses this
very type) includes a whole bunch of code to perform colour manipulation on
a pixel types.

Quote:
> It'll make PSet look like a tricycle next to your Porsche.

Vroom, vroom! :)
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Sun, 03 Apr 2005 00:17:13 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Help with drawing (Pset+Picturebox)

2. PSet replacement for drawing points

3. line drawing using mouse

4. Draw a line using Windows Api

5. Search line command with PSET !

6. Does VB5 Line/Pset method honour custom coordinates?

7. How to PSet in a straight line?

8. Using Pset and Point commands

9. I need help with flood fill algorithm using PSet and Point methods

10. Creating a BMP without using PSET

11. Is it possible to draw several lines?

12. Can code draw a line?

 

 
Powered by phpBB® Forum Software