Results 1 to 4 of 4

Thread: [RESOLVED] 2D Polygon Clipping (Scissoring)

  1. #1

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Resolved [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:
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: 2D Polygon Clipping (Scissoring)

    Anyone

  3. #3

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    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:
    1. Private Function Line_Intersect(ByVal L1_X1 As Single, ByVal L1_Y1 As Single, ByVal L1_X2 As Single, ByVal L1_Y2 As Single, _
    2.                                   ByVal L2_X1 As Single, ByVal L2_Y1 As Single, ByVal L2_X2 As Single, ByVal L2_Y2 As Single, _
    3.                                   ByRef Intersection As Vector) As Boolean
    4.                                  
    5.     'Denominator for ua and ub are the same, so store this calculation
    6.     Dim Denominator As Double
    7.     Dim n_a As Double
    8.     Dim n_b As Double
    9.     Denominator = (L2_Y2 - L2_Y1) * (L1_X2 - L1_X1) - (L2_X2 - L2_X1) * (L1_Y2 - L1_Y1)
    10.  
    11.       'n_a and n_b are calculated as seperate values for readability
    12.      ' Dim n_a As Double =
    13.  
    14.       'Dim n_b As Double =
    15.  
    16.  
    17.       'If ua >= 0D AndAlso ua <= 1D AndAlso ub >= 0D AndAlso ub <= 1D Then
    18.       '   Intersection.X = L1.X1 + (ua * (L1.X2 - L1.X1))
    19.       '   Intersection.Y = L1.Y1 + (ua * (L1.Y2 - L1.Y1))
    20.        '  Return True
    21.       'End If
    22.  
    23.     'n_a and n_b are calculated as seperate values for readability
    24.     n_a = (L2_X2 - L2_X1) * (L1_Y1 - L2_Y1) - (L2_Y2 - L2_Y1) * (L1_X1 - L2_X1)
    25.     n_b = (L1_X2 - L1_X1) * (L1_Y1 - L2_Y1) - (L1_Y2 - L1_Y1) * (L1_X1 - L2_X1)
    26.    
    27.     ' Make sure there is not a division by zero - this also indicates that
    28.     ' the lines are parallel.
    29.     ' If n_a and n_b were both equal to zero the lines would be on top of each
    30.     ' other (coincidental).  This check is not done because it is not
    31.     ' necessary for this implementation (the parallel check accounts for this).
    32.     If Denominator = 0 Then
    33.         Line_Intersect = False
    34.         Exit Function
    35.     End If
    36.    
    37.     ' Calculate the intermediate fractional point that the lines potentially intersect.
    38.     Dim ua As Double: ua = n_a / Denominator
    39.     Dim ub As Double: ub = n_b / Denominator
    40.    
    41.     ' The fractional point will be between 0 and 1 inclusive if the lines
    42.     ' intersect.  If the fractional calculation is larger than 1 or smaller
    43.     ' than 0 the lines would need to be longer to intersect.
    44.    
    45.     If ua >= 0 And ua <= 1 And ub >= 0 And ub <= 1 Then
    46.         Intersection.X = L1_X1 + (ua * (L1_X2 - L1_X1))
    47.         Intersection.Y = L1_Y1 + (ua * (L1_Y2 - L1_Y1))
    48.         Line_Intersect = True
    49.         Exit Function
    50.     End If
    51.  
    52.    Line_Intersect = False
    53.    
    54. 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
    Attached Files Attached Files

  4. #4
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: 2D Polygon Clipping (Scissoring)

    Quote Originally Posted by Jacob Roman View Post
    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.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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