CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2008
    Posts
    70

    Problem With DrawLine Function

    Any advice? This is due in 3 hours so its super time important

    http://pastebin.com/dxg9HyT9

    Even if you spot a problem with the math or have some advice please help. Been working on this all night. It almost works, just a few lines out of place.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem With DrawLine Function

    Please, describe your problem instead of posting some strange link address.
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2008
    Posts
    70

    Re: Problem With DrawLine Function

    Pastebin is a strange link address?

    Either way, sorry about that. I am trying to draw a line. My point.draw function places a pixel on the screen. This function is reading two points and drawing every point in between them. It almost works but certain specific angles do not draw correctly. I am guessing there is something wrong with the math. If Anyone who has done something like this before i would greatly appreciate the help.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem With DrawLine Function

    perhaps, you will show us your code that "almost works but certain specific angles do not draw correctly"?
    Victor Nijegorodov

  5. #5
    Join Date
    Sep 2008
    Posts
    70

    Re: Problem With DrawLine Function

    The problem is i am not sure of the exact angle that does not work. So i cant show a single line. Here is my fill function.


    You notice the dotted lines that appear. It may be a problem with my fill function though i had a similar problem with my lines earlier so i am pretty certain this is the issue. Any help would be great. Thanks.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem With DrawLine Function

    Quote Originally Posted by marsh View Post
    Here is my fill function.
    Where?
    Victor Nijegorodov

  7. #7
    Join Date
    Sep 2008
    Posts
    70

    Re: Problem With DrawLine Function

    I didnt post it, becouse i dont believe the problem is there. Also then i would need to include a lot of other classes etc. The actual project is huge.

    If this is not enough information to solve the problem i understand.

  8. #8
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Problem With DrawLine Function

    Quote Originally Posted by marsh View Post
    If Anyone who has done something like this before i would greatly appreciate the help.
    I haven't ever done that myself (at least not successfully... ), but eventually there never has been a real need to do it anyway, and I'm quite happy about it...

    At any rate, and since you neither posted code nor the problematic angles are really clear from your screen shot, perhaps the commonly used Bresenham line algorithm is helpful for you, either as a reference to spot what's wrong with your function, or as a basis to re-implement your function from scratch.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  9. #9
    Join Date
    Jan 2009
    Posts
    596

    Re: Problem With DrawLine Function

    Looking at the image you provided, it is clear that the way you are drawing the filled triangles is by drawing a lot of lines radiating from one of the triangle corners. This is not a good way to draw filled triangles for the following reasons:

    1) If you don't draw enough lines you get missing pixels - as you are seeing
    2) Pixels near the corner you are drawing from are overwritten (drawn more than once) - this is inefficient.

    So it is your fill algorithm which is wrong.

    To draw filled triangles you should use a scan-line fill algorithm, such as that shown here (http://www-users.mat.uni.torun.pl/~w...i_fillers.html). NB: I just found that on a quick google - I can't vouch for it's correctness.

  10. #10
    Join Date
    Sep 2008
    Posts
    70

    Re: Problem With DrawLine Function

    Quote Originally Posted by Peter_B View Post
    Looking at the image you provided, it is clear that the way you are drawing the filled triangles is by drawing a lot of lines radiating from one of the triangle corners. This is not a good way to draw filled triangles for the following reasons:

    1) If you don't draw enough lines you get missing pixels - as you are seeing
    2) Pixels near the corner you are drawing from are overwritten (drawn more than once) - this is inefficient.

    So it is your fill algorithm which is wrong.

    To draw filled triangles you should use a scan-line fill algorithm, such as that shown here (http://www-users.mat.uni.torun.pl/~w...i_fillers.html). NB: I just found that on a quick google - I can't vouch for it's correctness.
    Ah, thanks. I will check out that link. Sorry for my ignorance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured