2 Attachment(s)
[RESOLVED] 2D Polygon Clipping (Scissoring)
Using DirectX8, I am immitading World of Warcraft's spell cooldown and I managed to pull it off on my own. However there is just one problem. The diamond I am using over the spell image needs clipped as I do not want it shown, which means I am gonna need 4 clipping regions. Scissoring would have been a great solution but it's only supported in DirectX9 and above. However I ran into this post which has Weiler-Atherton's algorithm method of 2d Polygon clipping but krtxmrtz's code was too complex for me to convert, mostly cause of his variables. If anyone's got the balls and brains to help splice this in somehow, I would apprieciate it. I am uploading an image of what I have achieved along with my project:
Re: 2D Polygon Clipping (Scissoring)
1 Attachment(s)
Re: 2D Polygon Clipping (Scissoring)
God noone ever seems to answer my posts o.O
Anyways I managed to pull it off with a number of twists. First of all I needed a line intersecting algorithm:
vb Code:
Private Function Line_Intersect(ByVal L1_X1 As Single, ByVal L1_Y1 As Single, ByVal L1_X2 As Single, ByVal L1_Y2 As Single, _
ByVal L2_X1 As Single, ByVal L2_Y1 As Single, ByVal L2_X2 As Single, ByVal L2_Y2 As Single, _
ByRef Intersection As Vector) As Boolean
'Denominator for ua and ub are the same, so store this calculation
Dim Denominator As Double
Dim n_a As Double
Dim n_b As Double
Denominator = (L2_Y2 - L2_Y1) * (L1_X2 - L1_X1) - (L2_X2 - L2_X1) * (L1_Y2 - L1_Y1)
'n_a and n_b are calculated as seperate values for readability
' Dim n_a As Double =
'Dim n_b As Double =
'If ua >= 0D AndAlso ua <= 1D AndAlso ub >= 0D AndAlso ub <= 1D Then
' Intersection.X = L1.X1 + (ua * (L1.X2 - L1.X1))
' Intersection.Y = L1.Y1 + (ua * (L1.Y2 - L1.Y1))
' Return True
'End If
'n_a and n_b are calculated as seperate values for readability
n_a = (L2_X2 - L2_X1) * (L1_Y1 - L2_Y1) - (L2_Y2 - L2_Y1) * (L1_X1 - L2_X1)
n_b = (L1_X2 - L1_X1) * (L1_Y1 - L2_Y1) - (L1_Y2 - L1_Y1) * (L1_X1 - L2_X1)
' Make sure there is not a division by zero - this also indicates that
' the lines are parallel.
' If n_a and n_b were both equal to zero the lines would be on top of each
' other (coincidental). This check is not done because it is not
' necessary for this implementation (the parallel check accounts for this).
If Denominator = 0 Then
Line_Intersect = False
Exit Function
End If
' Calculate the intermediate fractional point that the lines potentially intersect.
Dim ua As Double: ua = n_a / Denominator
Dim ub As Double: ub = n_b / Denominator
' The fractional point will be between 0 and 1 inclusive if the lines
' intersect. If the fractional calculation is larger than 1 or smaller
' than 0 the lines would need to be longer to intersect.
If ua >= 0 And ua <= 1 And ub >= 0 And ub <= 1 Then
Intersection.X = L1_X1 + (ua * (L1_X2 - L1_X1))
Intersection.Y = L1_Y1 + (ua * (L1_Y2 - L1_Y1))
Line_Intersect = True
Exit Function
End If
Line_Intersect = False
End Function
Then I had to put the shading polygon into a Vertex Buffer and an Index Buffer so they are easier to handle and I literally had to work with each poly every 45 degrees around the 360 the effect has to go around. You can change the cooldown time to any number of seconds, and itll go around exactly in that time. The World of Warcraft Spell Cooldown effect has been resolved :bigyello:
Re: 2D Polygon Clipping (Scissoring)
Quote:
Originally Posted by
Jacob Roman
God noone ever seems to answer my posts o.O
Anyways I managed to pull it off with a number of twists. ...
In case you want to check on it for future developments, this may be of some help:
http://www.vbforums.com/showpost.php...90&postcount=9
As for that Weiler-Atherton project I didn't work on it any further for I had a lot of trouble withh special cases of e.g. vertices of one polygon falling on the other polygon's edge. The library mentioned in the post linked to above allowed for those degenerate cases.