Line drawing problem
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?
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?
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
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
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?
If so, the calc looks correct. Are you rendering triangles in order A-B-C and B-D-C?
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? ç_ç
Well that's strange then. Why it gives those artefacts? ç_ç
Try setting Width to some large number so you can see the individual triangles. That should give you more information.
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
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
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement