# Pixel Collision with Rotation. Again!

I have looked at this subject many times now, and every search has found the same answer.

If you do any search you’ll find the same answer I have. In VB this is:

Public Function Collision(rectangleA As Rectangle, dataA As Color(), rectangleB As Rectangle, dataB As Color()) As Boolean

``````    Dim top As Integer = Math.Max(rectangleA.Top, rectangleB.Top)
Dim bottom As Integer = Math.Min(rectangleA.Bottom, rectangleB.Bottom)
Dim left As Integer = Math.Max(rectangleA.Left, rectangleB.Left)
Dim right As Integer = Math.Min(rectangleA.Right, rectangleB.Right)

For y As Integer = top To bottom - 1
For x As Integer = left To right - 1

Dim colorA As Color = dataA((x - rectangleA.Left) + (y - rectangleA.Top) * rectangleA.Width)
Dim colorB As Color = dataB((x - rectangleB.Left) + (y - rectangleB.Top) * rectangleB.Width)

If colorA.A <> 0 And colorB.A <> 0 Then
Return True
End If
Next
Next

Return False
End Function
``````

I’m sorry this isn’t in a code bracket, but it isn’t working.

What I don’t understand, is where the rotation is coming in. I’m building the color array, or DataA and DataB well before this routine is called, but what I can’t seem to find is how these arrays are rotated.

Can someone fill this black hole?
Thanks.

Edit - Oh, it is in a code block. It wasn’t on the preview box.

I dont quite understand exactly what it is you are asking about the rotation,
it seems like you may be asking where rotation should be added to this example?
If so you should put it before the dims(so the math it is doing is based on the after rotation

Sorry if I wasn’t clear, it had been a long painful day.

The code to create the color map that I’m using is:

`DataA = New Color(Texture.Width * Texture.Height - 1) {} Texture.GetData(DataA)`

But this is obviously not rotated. So how do I rotate the map before sending it to the above function.