![]() |
|
|
|
| Rotozoom |
One
of the cooler oldskool routines is the rotozoom.The hart of the routine is the following calculation: '**** Rotozoom **** For lX = 0 To lMaxWidth lXpos = lX * 3 For lY = 0 To lMaxHeight '**** Calculate rotation **** lSourceX = lXCenter + (lX - lXCenter) * dSin + (lY - lYCenter) * dCos lSourceY = lYCenter + (lY - lYCenter) * dSin - (lX - lXCenter) * dCos If (lSourceX >= 0) And (lSourceX <= lMaxWidth) Then If (lSourceY >= 0) And (lSourceY <= lMaxHeight) Then lXSourcePos = lSourceX * 3 '**** Blue **** aRotozoom(lXpos, lY) = aRotozoom2(lXSourcePos, lSourceY) '**** Green **** aRotozoom(lXpos + 1, lY) = aRotozoom2(lXSourcePos + 1, lSourceY) '**** Red **** aRotozoom(lXpos + 2, lY) = aRotozoom2(lXSourcePos + 2, lSourceY) End If End If Next Next We have one source surface (aRotozoom2) with the picture and one destination surface ("the screen" aRotozoom). What we have to do is to calculate from where in the source picture we shall copy the pixels after rotation. The strange lXpos = lX * 3 and lXSourcePos = lSourceX * 3 calculations is because the surfaces is in 24-bit format this makes the the picture data 3 times wider. See the surface help for more information. The Rotozoom demo uses Y data from a SineEngine control to calculate the zoom factor. Change SineEngine settings to change the zooming curve. Private Sub SineEngine1_SineMove(Index As Long, X As Long, Y As Long) dZoom = Y End Sub '**** Rotate and Zoom **** dCos = Cos(dAngle) * dZoom / 100 dSin = Sin(dAngle) * dZoom / 100 Rotozoom does a lot of calculations therefore to test it with full speed compile and run the exe-file. Run from vb environment and you get for example 11 FPS then run it as a compiled exe and you get 60 FPS. See Optimize in the surface help for more information. Download source and exe to check it out. Require SineMaker controls or S.M.A.K version: 1.0 or higher Download: rotozoom.zip (File size: 81 KB) |
|
Copyright © 2002 Lars-Håkan Jönsson |