Public Sub RotateSurface(ByRef surfSource As DirectDrawSurface7, surfDestination As DirectDrawSurface7, lngAngle As Long, XDest As Long, Ydest As Long)
Dim ddsdOrigine As DDSURFACEDESC2, ddsdDestination As DDSURFACEDESC2
Dim iX As Long, iY As Long
Dim iXDest As Long, iYDest As Long
Dim rEmpty As RECT, rEmpty2 As RECT
Dim sngA As Single, SinA As Single, CosA As Single
Dim dblRMax As Long
Dim lngXO As Long, lngYO As Long
Dim lngColor As Long
Dim lWidth As Long, lHeight As Long
sngA = lngAngle * PI / 180
SinA = Sin(sngA)
CosA = Cos(sngA)
surfSource.GetSurfaceDesc ddsdOrigine
lWidth = ddsdOrigine.lWidth
lHeight = ddsdOrigine.lHeight
dblRMax = Sqr(lWidth ^ 2 + lHeight ^ 2)
surfSource.Lock rEmpty, ddsdOrigine, DDLOCK_WAIT, 0
surfDestination.GetSurfaceDesc ddsdDestination
surfDestination.Lock rEmpty2, ddsdDestination, DDLOCK_WAIT, 0
XDest = XDest + lWidth / 2
Ydest = Ydest + lHeight / 2
For iX = -dblRMax To dblRMax
For iY = -dblRMax To dblRMax
lngXO = lWidth / 2 - (iX * CosA + iY * SinA)
lngYO = lHeight / 2 - (iX * SinA - iY * CosA)
If lngXO >= 0 Then
If lngYO >= 0 Then
If lngXO < lWidth Then
If lngYO < lHeight Then
lngColor = surfSource.GetLockedPixel(lngXO, lngYO)
If lngColor <> 0 Then
surfDestination.SetLockedPixel XDest + iX, Ydest + iY, lngColor
End If
End If
End If
End If
End If
Next iY
Next iX
surfSource.Unlock rEmpty
surfDestination.Unlock rEmpty2
carwidth = lWidth / 2 - (iX * CosA + iY * SinA)
carheight = lHeight / 2 - (iX * SinA - iY * CosA)
End Sub