Rotation d'une Ellipse

Contenu du snippet

Const GM_ADVANCED As Long = 2
Const Pi          As Single = 3.141593

Private Type XForm
    eM11 As Single
    eM12 As Single
    eM21 As Single
    eM22 As Single
    eDx As Single
    eDy As Single
End Type

Private Type RectAPI
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type PointAPI
    X As Long
    Y As Long
End Type

Dim OldXForm  As XForm
Dim MyXForm   As XForm
Dim WndArea   As RectAPI
Dim OldOrg      As PointAPI
Dim OldMode   As Long
Dim RotAng     As Single
Dim RotRad     As Single

Private Declare Function SetViewportOrgEx Lib "gdi32" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As PointAPI) As Long
Private Declare Function SetGraphicsMode Lib "GDI32.dll" (ByVal hDC As Long, ByVal iMode As Long) As Long
Private Declare Function GetWorldTransform Lib "GDI32.dll" (ByVal hDC As Long, ByRef lpXform As XForm) As Long
Private Declare Function SetWorldTransform Lib "GDI32.dll" (ByVal hDC As Long, ByRef lpXform As XForm) As Long
Private Declare Function GetClientRect Lib "User32.dll" (ByVal hWnd As Long, ByRef lpRect As RectAPI) As Long

Private Sub Timer1_Timer()
    RotAng = RotAng + 2
    RotRad = (RotAng / 180) * Pi
    MyXForm.eM11 = Cos(RotRad)
    MyXForm.eM12 = Sin(RotRad)
    MyXForm.eM21 = -MyXForm.eM12
    MyXForm.eM22 = MyXForm.eM11
    Me.Cls
    Call SetViewportOrgEx(Me.hDC, WndArea.Right \ 2, WndArea.Bottom \ 2, OldOrg)
    Call SetGraphicsMode(Me.hDC, GM_ADVANCED)
    Call SetWorldTransform(Me.hDC, MyXForm)
    Me.Line (-1500, 0)-(1500, 0), vbBlue
    Me.Line (0, -750)-(0, 750), vbBlue
    Me.Circle (0, 0), 1500, vbRed, , , 0.5
End Sub

'   utilisation: il faut un Timer
    Call GetClientRect(Me.hWnd, WndArea)
    Timer1.Interval = 50
    Timer1.Enabled = True



Compatibilité : VB6

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.