Jump to content
  • Advertisement
Sign in to follow this  
feal87

Line drawing problem

This topic is 3046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to implement a thick line drawing and i'm encountering a little problem. (That i think its not aliasing) see the following image that's the result of the algorithm at various angulations : http://img99.imageshack.us/img99/9480/whatzy.png As you see, as we reach the 45° angulation the line begin to look REALLy weird while its fine at more acute angulations, or at 45° precise. This is how I calculate the 4 points of the quad Single L = (Single)Math.Sqrt(Math.Pow((PosizioneFine.X - Posizione.X), 2) + Math.Pow((PosizioneFine.Y - Posizione.Y), 2)); Single X = (PosizioneFine.X - Posizione.X) / L; Single Y = (PosizioneFine.Y - Posizione.Y) / L; And use the X and Y multiplied per Width to create the 2 new points. Any clues?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
use the X and Y multiplied per Width to create the 2 new points

Can you post the code? And can you clarify what "the quad" is that you're referring to?

Share this post


Link to post
Share on other sites
The line to be able of have a width is drawed as a series of 2 triangles with the vertices calculated as follow

A (X,Y,0)
B (XEnd, YEnd, 0)

Single L = (Single)Math.Sqrt(Math.Pow((PosizioneFine.X - Posizione.X), 2) + Math.Pow((PosizioneFine.Y - Posizione.Y), 2));
Single XVAR = (PosizioneFine.X - Posizione.X) / L;
Single YVAR = (PosizioneFine.Y - Posizione.Y) / L;

C (X - (YVAR * Width), Y + (XVAR * Width))
D (XEnd - (YVAR * Width), YEnd + (XVAR * Width))

the triangles are

ABC, BDC

Share this post


Link to post
Share on other sites
Your English is better than my Italian. [wink] Is PosizioneFine = B and Posizione = A?

If so, the calc looks correct. Are you rendering triangles in order A-B-C and B-D-C?

Share this post


Link to post
Share on other sites
Yes, they are B and A and yes i'm drawing them in the correct order (otherwise they would get culled :P)
Well that's strange then. Why it gives those artefacts? ç_ç

Share this post


Link to post
Share on other sites
Try setting Width to some large number so you can see the individual triangles. That should give you more information.

Share this post


Link to post
Share on other sites
On higher width 5+, the problem isn't present.
Between 4 and 5 the problem is not much visible.
On 1 or 3 width the problem is there.

For the 1 width I can use directly a simple DirectX line, but for 2 and 3? :P

Share this post


Link to post
Share on other sites
Quote:
For the 1 width I can use directly a simple DirectX line, but for 2 and 3?

At low Widths, Width*sin(angle) and Width*cos(angle) may be less than 1 pixel and you're getting degenerate triangles. You can add a check something like:

if( XVAR < 1 ) XVAR = 1;
if( YVAR < 1 ) YVAR = 1;

That still won't be perfect, but it'll be close.

Share this post


Link to post
Share on other sites
That would not work...
if XVar and YVar are always 1 if under 1 you will get always the same diagonal 45° line in those cases. :P

Anyway i'll try. :P

Share this post


Link to post
Share on other sites
Well, my assumption was wrong. Now it works perfectly even at 1 width, with that change you give me lol. :P

Thanks a lot!!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!