-
October 17th, 2012, 07:38 AM
#1
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.
-
October 17th, 2012, 07:40 AM
#2
Re: Problem With DrawLine Function
Please, describe your problem instead of posting some strange link address.
Victor Nijegorodov
-
October 17th, 2012, 07:47 AM
#3
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.
-
October 17th, 2012, 07:51 AM
#4
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
-
October 17th, 2012, 08:05 AM
#5
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.
-
October 17th, 2012, 08:10 AM
#6
Re: Problem With DrawLine Function
Originally Posted by marsh
Here is my fill function.
Where?
Victor Nijegorodov
-
October 17th, 2012, 08:13 AM
#7
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.
-
October 17th, 2012, 08:46 AM
#8
Re: Problem With DrawLine Function
Originally Posted by marsh
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.
-
October 17th, 2012, 10:08 AM
#9
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.
-
October 17th, 2012, 10:52 AM
#10
Re: Problem With DrawLine Function
Originally Posted by Peter_B
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|