|
-
Feb 14th, 2003, 04:42 PM
#1
Thread Starter
Ex-Super Mod'rater
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:
Dim Angle As Single
Dim XCenter As Single
Dim YCenter As Single
Dim BL As POINTAPI
Dim TL As POINTAPI
Dim BR As POINTAPI
Dim TR As POINTAPI
If Sprite(iSpriteIndex1).Angle = 0 Then
S1 = Sprite(iSpriteIndex1).dstRect
Else
TempRect = Sprite(iSpriteIndex1).dstRect
XCenter = TempRect.Left + ((TempRect.Right - TempRect.Left - 1) / 2)
YCenter = TempRect.Top + ((TempRect.Bottom - TempRect.Top - 1) / 2)
Angle = Sprite(iSpriteIndex1).Angle + (Pi / 2)
If Angle >= 2 * Pi Then Angle = Angle - ((2 * Pi) * CInt(Angle / (2 * Pi)))
If Angle < 4.714 And Angle > 4.71 Then
Angle = 3 * Pi / 2
ElseIf Angle < 3.143 And Angle > 3.14 Then
Angle = Pi
ElseIf Angle < 6.284 And Angle > 6.282 Then
Angle = 2 * Pi
End If
'Bottom Left
BL.x = XCenter + (TempRect.Left - XCenter) * Sin(Angle) + (TempRect.Bottom - YCenter) * Cos(Angle)
BL.y = YCenter + (TempRect.Bottom - YCenter) * Sin(Angle) - (TempRect.Left - XCenter) * Cos(Angle)
'Top Left
TL.x = XCenter + (TempRect.Left - XCenter) * Sin(Angle) + (TempRect.Top - YCenter) * Cos(Angle)
TL.y = YCenter + (TempRect.Top - YCenter) * Sin(Angle) - (TempRect.Left - XCenter) * Cos(Angle)
'Bottom Right
BR.x = XCenter + (TempRect.Right - XCenter) * Sin(Angle) + (TempRect.Bottom - YCenter) * Cos(Angle)
BR.y = YCenter + (TempRect.Bottom - YCenter) * Sin(Angle) - (TempRect.Right - XCenter) * Cos(Angle)
'Top Right
TR.x = XCenter + (TempRect.Right - XCenter) * Sin(Angle) + (TempRect.Top - YCenter) * Cos(Angle)
TR.y = YCenter + (TempRect.Top - YCenter) * Sin(Angle) - (TempRect.Right - XCenter) * Cos(Angle)
'Set S1...
SetRect R1, TL.x, TL.y, BL.x, BL.y
SetRect R2, BL.x, BL.y, BR.x, BR.y
SetRect R3, BR.x, BR.y, TR.x, TR.y
SetRect R4, TR.x, TR.y, TL.x, TL.y
UnionRect S1, R1, R2
UnionRect S1, R3, S1
UnionRect S1, R4, S1
'S1 is now the RECT for the area needed to paint the first sprite
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.

-
Feb 15th, 2003, 09:09 AM
#2
Thread Starter
Ex-Super Mod'rater
I sorted it out with this code instead:
VB Code:
If Sprite(iSpriteIndex1).Angle = 0 Then
S1 = Sprite(iSpriteIndex1).dstRect
Else
TempRect = Sprite(iSpriteIndex1).dstRect
XCenter = TempRect.Left + ((TempRect.Right - TempRect.Left - 1) / 2)
YCenter = TempRect.Top + ((TempRect.Bottom - TempRect.Top - 1) / 2)
Angle = Sprite(iSpriteIndex1).Angle + (Pi / 2)
If Angle >= 2 * Pi Then Angle = Angle - ((2 * Pi) * CInt(Angle / (2 * Pi)))
If Angle < 4.714 And Angle > 4.71 Then
Angle = 3 * Pi / 2
ElseIf Angle < 3.143 And Angle > 3.14 Then
Angle = Pi
ElseIf Angle < 6.284 And Angle > 6.282 Then
Angle = 2 * Pi
End If
'Bottom Left
BL.x = XCenter + (TempRect.Left - XCenter) * Sin(Angle) + (TempRect.Bottom - YCenter) * Cos(Angle)
BL.y = YCenter + (TempRect.Bottom - YCenter) * Sin(Angle) - (TempRect.Left - XCenter) * Cos(Angle)
'Top Left
TL.x = XCenter + (TempRect.Left - XCenter) * Sin(Angle) + (TempRect.Top - YCenter) * Cos(Angle)
TL.y = YCenter + (TempRect.Top - YCenter) * Sin(Angle) - (TempRect.Left - XCenter) * Cos(Angle)
'Bottom Right
BR.x = XCenter + (TempRect.Right - XCenter) * Sin(Angle) + (TempRect.Bottom - YCenter) * Cos(Angle)
BR.y = YCenter + (TempRect.Bottom - YCenter) * Sin(Angle) - (TempRect.Right - XCenter) * Cos(Angle)
'Top Right
TR.x = XCenter + (TempRect.Right - XCenter) * Sin(Angle) + (TempRect.Top - YCenter) * Cos(Angle)
TR.y = YCenter + (TempRect.Top - YCenter) * Sin(Angle) - (TempRect.Right - XCenter) * Cos(Angle)
'Set S1...
'R1 is made from TL and BR...
If TL.y < BR.y Then
R1.Top = TL.y
R1.Bottom = BR.y
Else
R1.Top = BR.y
R1.Bottom = TL.y
End If
If TL.x < BR.x Then
R1.Left = TL.x
R1.Right = BR.x
Else
R1.Left = BR.x
R1.Right = TL.x
End If
'R2 is made from BL and TR...
If TR.y < BL.y Then
R2.Top = TR.y
R2.Bottom = BL.y
Else
R2.Top = BL.y
R2.Bottom = TR.y
End If
If BL.x < TR.x Then
R2.Left = BL.x
R2.Right = TR.x
Else
R2.Left = TR.x
R2.Right = BL.x
End If
'S1 is made from R1 and R2...
If R1.Top < R2.Top Then
S1.Top = R1.Top
Else
S1.Top = R2.Top
End If
If R1.Left < R2.Left Then
S1.Left = R1.Left
Else
S1.Left = R2.Left
End If
If R1.Bottom > R2.Bottom Then
S1.Bottom = R1.Bottom
Else
S1.Bottom = R2.Bottom
End If
If R1.Right > R2.Right Then
S1.Right = R1.Right
Else
S1.Right = R2.Right
End If
'S1 is now the RECT for the area needed to paint the first sprite
End If
It seems it was something to do with the fact that Left was sometimes greater than Right and when that happens the Union API doesn't work all that well. Well the main thing this is part of is still throwing errors out so looks like I still got quite a bit of work left on it.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|