КАк определять collision и делать rotate?
rtfm- не предлогать!
Модератор: Mikle
Я извиняюсь, но в среде VB такой перебор точек работает очень медленно, тем паче для изображений более, скажем, 200*200
Public Const Deg2Rad As Double = 0.017453292519943
Public Sub DXRotateSprite(Source As DirectDrawSurface7, Region As RECT, ByVal Angle As Double, dest As DirectDrawSurface7)
Dim RegTmp As RECT
Dim X As Integer
Dim Y As Integer
Dim SourceWidth As Integer
Dim SourceHeight As Integer
Dim DestWidth As Integer
Dim DestHeight As Integer
Dim cx As Integer
Dim cy As Integer
Dim DX As Integer
Dim dy As Integer
Dim cosa As Double
Dim sina As Double
Dim yin As Double
Dim xin As Double
Dim rx As Double
Dim ry As Double
Dim irx As Double
Dim iry As Double
Dim pcol As Long
RegTmp.Left = 0
RegTmp.Top = 0
RegTmp.Right = Region.Right - Region.Left
RegTmp.Bottom = Region.Bottom - Region.Top
dest.BltColorFill RegTmp, 0
Source.Lock Region, ddsd2, DDLOCK_WAIT, 0
dest.Lock RegTmp, ddsd2, DDLOCK_WAIT, 0
SourceWidth = RegTmp.Right + 1
SourceHeight = RegTmp.Bottom + 1
DestWidth = SourceWidth
DestHeight = SourceHeight
cx = SourceWidth * 0.5
cy = SourceHeight * 0.5
DX = DestWidth * 0.5
dy = DestHeight * 0.5
cosa = Cos(Angle * Deg2Rad * -1)
sina = Sin(Angle * Deg2Rad * -1)
For Y = Region.Top To Region.Bottom
yin = Y - dy
For X = Region.Left To Region.Right
xin = X - DX
rx = xin * cosa - yin * sina + cx
ry = xin * sina + yin * cosa + cy
irx = Int(rx)
iry = Int(ry)
If (PtInRect(RegTmp, irx, iry)) Then
pcol = Source.GetLockedPixel(irx, iry)
dest.SetLockedPixel X, Y, pcol
End If
Next X
Next Y
Source.Unlock Region
dest.Unlock RegTmp
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 23