Results 1 to 2 of 2

Thread: Could someone please help with this Rotating RECT [Resolved]

Threaded View

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Resolved Could someone please help with this Rotating RECT [Resolved]

    Can someone please help me with the code below? I'm trying to rotate a RECT structure (Sprite(iSpriteIndex1).dstRect) and then create a new RECT (S1) that will be just the right size to contain the rotated RECT. I thought I had it but I'm getting some strange results and I can't figure out why.
    VB Code:
    1. Dim Angle As Single
    2. Dim XCenter As Single
    3. Dim YCenter As Single
    4. Dim BL As POINTAPI
    5. Dim TL As POINTAPI
    6. Dim BR As POINTAPI
    7. Dim TR As POINTAPI
    8.  
    9.  
    10. If Sprite(iSpriteIndex1).Angle = 0 Then
    11.     S1 = Sprite(iSpriteIndex1).dstRect
    12. Else
    13.     TempRect = Sprite(iSpriteIndex1).dstRect
    14.     XCenter = TempRect.Left + ((TempRect.Right - TempRect.Left - 1) / 2)
    15.     YCenter = TempRect.Top + ((TempRect.Bottom - TempRect.Top - 1) / 2)
    16.     Angle = Sprite(iSpriteIndex1).Angle + (Pi / 2)
    17.     If Angle >= 2 * Pi Then Angle = Angle - ((2 * Pi) * CInt(Angle / (2 * Pi)))
    18.     If Angle < 4.714 And Angle > 4.71 Then
    19.         Angle = 3 * Pi / 2
    20.     ElseIf Angle < 3.143 And Angle > 3.14 Then
    21.         Angle = Pi
    22.     ElseIf Angle < 6.284 And Angle > 6.282 Then
    23.         Angle = 2 * Pi
    24.     End If
    25.    
    26.     'Bottom Left
    27.     BL.x = XCenter + (TempRect.Left - XCenter) * Sin(Angle) + (TempRect.Bottom - YCenter) * Cos(Angle)
    28.     BL.y = YCenter + (TempRect.Bottom - YCenter) * Sin(Angle) - (TempRect.Left - XCenter) * Cos(Angle)
    29.     'Top Left
    30.     TL.x = XCenter + (TempRect.Left - XCenter) * Sin(Angle) + (TempRect.Top - YCenter) * Cos(Angle)
    31.     TL.y = YCenter + (TempRect.Top - YCenter) * Sin(Angle) - (TempRect.Left - XCenter) * Cos(Angle)
    32.  
    33.     'Bottom Right
    34.     BR.x = XCenter + (TempRect.Right - XCenter) * Sin(Angle) + (TempRect.Bottom - YCenter) * Cos(Angle)
    35.     BR.y = YCenter + (TempRect.Bottom - YCenter) * Sin(Angle) - (TempRect.Right - XCenter) * Cos(Angle)
    36.     'Top Right
    37.     TR.x = XCenter + (TempRect.Right - XCenter) * Sin(Angle) + (TempRect.Top - YCenter) * Cos(Angle)
    38.     TR.y = YCenter + (TempRect.Top - YCenter) * Sin(Angle) - (TempRect.Right - XCenter) * Cos(Angle)
    39.     'Set S1...
    40.     SetRect R1, TL.x, TL.y, BL.x, BL.y
    41.     SetRect R2, BL.x, BL.y, BR.x, BR.y
    42.     SetRect R3, BR.x, BR.y, TR.x, TR.y
    43.     SetRect R4, TR.x, TR.y, TL.x, TL.y
    44.     UnionRect S1, R1, R2
    45.     UnionRect S1, R3, S1
    46.     UnionRect S1, R4, S1
    47.     'S1 is now the RECT for the area needed to paint the first sprite
    48. End If

    I'd greatly appreciate any help anyone has.
    Last edited by Electroman; Sep 20th, 2004 at 09:11 AM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

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