Newsgroup: it.comp.lang.visual-basic
Titolo: [?] API per rotazioni ?

Ciao !!
Ho in mente di creare un componente Ocx che simuli una "manopola" , tipo
quelle per regolare il volume di una radio per intenderci.
Inizialmente avevo pensato a creare una serie di bitmap raffiguranti ogni
posizione, ma ripensandoci la cosa non mi piace, perche' si vedrebbero gli
"scatti" tra una posizione e l'altra.Quindi per rendere la rotazione piu'
fluida, ho pensato di usare una sola immagine e ruotarla.
Ok, allora... con la funzione BitBlt disegno la mia immagine sul form (cosi'
ottengo un effetto trasparenza attorno al cerchio) , ma ora come la faccio
ruotare ? non mi sembra esista un API per ruotare un immagine bitmap...
...c'e' qualcuno che mi puo' smentire ?
Ciao e grazie, DaVe

Il miglior metodo, e' quello che hai scartato !!!
Quanti piu' sprite disegnerai per la tua animazione, quanto questa sara'
piu' fluida...
Ciao !
[-> DaVe <-] <DaVeGraphix@bluewin[crack].ch> wrote in message
82h91g$1r2$1...@bw107zhb.bluewin.ch...



Io disegnerei la manopola in una bitmap, e poi a seconda della rotazione
disegnerei sulla bitmap la tacchetta (o incavo, o quello che vuoi), il tutto
con l'aiuto di un paio di funzioni trigonometriche.
La soluzione dei molti frames è un po' bruttina (se somani cambi l'aspetto
della manopola che fai? ridisegni da capo tutti i frames? (360!)), e ruotare
l'intera manopola significherebbe ruotare anche l'ombra che invece deve
stare in basso a destra.
Ciao

 Ciao e grazie, DaVe
  Si, io:
Rotating a Picture through any angle
Use this function to rotate a bitmap through a certain
angle. This function is unfortunately quite slow due to
the amount of calculations that it must do. Put this in
a code module:
 Declarations
Public Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y _
As Long) As Long
Public Declare Function SetPixelV Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As _
Long, ByVal crColor As Long) As Long
Public Const Pi = 3.14159265358979
 Procedure
' ************************************************
' Rotate the picture in Source and place it
' in Dest. Rotate the area Left <= x <= right,
' top <= y <= bottom through Angle radians
' around the point (origx, origy). Place the result so
' (origx, origy) maps to (newx, newy).
' ************************************************
Public Sub RotatePicture(ByVal SourcehDC As Long, _
ByVal DesthDC As Long, ByVal AngleInRadians As _
Double, ByVal Left As Integer, ByVal Top As _
Integer, ByVal Right As Integer, ByVal Bottom _
As Integer, ByVal OrigX As Integer, ByVal OrigY _
As Integer, ByVal NewX As Integer, ByVal NewY As Integer)
                        ' Parameters:
' SourcehDC, DesthDC: hDC for source and destinations
' picture boxes or forms
' AngleInRadians: The angle to rotate the picture by
' Left, Top, Right, Bottom: The bounds of the source picture
' OrigX, OrigY, NewX, NewY: OrigX maps to NewX and
' OrigY maps to NewY
Dim sin_theta As Double
Dim cos_theta As Double
Dim MinX As Integer
Dim MaxX As Integer
Dim MinY As Integer
Dim MaxY As Integer
Dim tx As Integer
Dim ty As Integer
Dim fx As Double
Dim fy As Double
Dim ifx As Integer
Dim ify As Integer
' Compute the sine and cosine of theta.
sin_theta = Sin(AngleInRadians)
cos_theta = Cos(AngleInRadians)
' Make some bounds for new picture
MinX = (Left - OrigX) * cos_theta + _
(Top - OrigY) * sin_theta + NewX
MinY = -(Left - OrigX) * sin_theta + _
(Top - OrigY) * cos_theta + NewY
MaxX = MinX
MaxY = MinY
tx = (Left - OrigX) * cos_theta + _
(Bottom - OrigY) * sin_theta + NewX
ty = -(Left - OrigX) * sin_theta + _
(Bottom - OrigY) * cos_theta + NewY
If MinX > tx Then MinX = tx
If MinY > ty Then MinY = ty
If MaxX < tx Then MaxX = tx
If MaxY < ty Then MaxY = ty
tx = (Right - OrigX) * cos_theta + _
(Top - OrigY) * sin_theta + NewX
ty = -(Right - OrigX) * sin_theta + _
(Top - OrigY) * cos_theta + NewY
If MinX > tx Then MinX = tx
If MinY > ty Then MinY = ty
If MaxX < tx Then MaxX = tx
If MaxY < ty Then MaxY = ty
tx = (Right - OrigX) * cos_theta + _
(Bottom - OrigY) * sin_theta + NewX
ty = -(Right - OrigX) * sin_theta + _
(Bottom - OrigY) * cos_theta + NewY
If MinX > tx Then MinX = tx
If MinY > ty Then MinY = ty
If MaxX < tx Then MaxX = tx
If MaxY < ty Then MaxY = ty
If MinX < 1 Then MinX = 1
If MaxX < 1 Then MaxX = 1
If MinY < 1 Then MinY = 1
If MaxY < 1 Then MaxY = 1
' Perform the rotation.
For ty = MinY To MaxY
For tx = MinX To MaxX
' Find the location (fx, fy) that maps to the pixel (tx, ty).
fx = (tx - NewX) * cos_theta - (ty - NewY) * sin_theta + OrigX
fy = (tx - NewX) * sin_theta + (ty - NewY) * cos_theta + OrigY
' Skip it if the nearest source pixel
' lies outside the allowed source area.
ify = Fix(fy)
ifx = Fix(fx)
If ifx >= Left And ifx < Right And ify >= Top And ify < Bottom Then
Call SetPixelV(DesthDC, tx, ty, GetPixel(SourcehDC, ifx, ify))
End If
Next tx
Next ty
End Sub
Then call it as follows:
Dim theta As Double
If Not IsNumeric(txtangle.Text) Then txtangle.Text = 0
txtangle.Text = txtangle.Text - 360 * (txtangle.Text \ 360)
theta = PI * CDbl(txtangle.Text) / 180
topict.Cls
topict.Visible = False
RotatePicture frompict.hdc, topict.hdc, _
theta, 0, 0, frompict.ScaleWidth - 1, _
frompict.ScaleHeight - 1, frompict.ScaleWidth / 2, _
frompict.ScaleHeight / 2, topict.ScaleWidth / 2, _
topict.ScaleHeight / 2
topict.Visible = True
This will rotate the contents of frompict through the
number of degrees in txtAngle and place the result in
topict. The middle of the original picture will map onto
the middle of the new picture.
(Tip by John Percival)
Search for more info on this or other topics Search in VB-World.net