_GDI+_MatrixRotate

  • Hey Leute,
    kann man irgendwie verhindern, dass MatrixRotate "alles" verwischt?
    so sieht das Ganze vorher aus:

    Spoiler anzeigen

    und so nachher:

    Spoiler anzeigen

    Hab mir überlegt, dass man nach jedem Drehen, alles neuzeichnen könnte, nachdem man

    [autoit]

    _WinAPI_RedrawWindow ($hGUI)

    [/autoit]


    benutzt hat. Dann muss ich jedoch auch immer wieder den Hintergrund zeichnen, wobei er immer wieder aufflimmert.
    achja, die Figur ist ne .png un is transparent...

    Danke

    Einmal editiert, zuletzt von Manlius (3. März 2011 um 14:06)

  • Aber wie kann ich damit nur die Figur übermalen? Weil bei mir is die ganze GUI das Grafikobjekt wegen:

    [autoit]

    _GDIPlus_GraphicsCreateFromHWND ($hGUI)

    [/autoit]

    Es gibt zwar ja auch noch

    [autoit]

    _GDIPlus_GraphicsCreateFromHDC

    [/autoit]

    Aber dann müsste ich ja aus nem image/bild den Gerätekontext auslesen un das geht ja nich (hat ein bild überhaupt so was? :D) Also immer wenn ich

    [autoit]

    _GDIPlus_GraphicsClear()

    [/autoit]

    mach, wird meine ganze GUI weiß...

  • Mhm...hab mir das Ganze mal angeschaut. Sieht übrigens klasse aus ;)
    Bei mir zeichnet´s aufjedenfall die Figur (in dem Fall den foreground) nich mehr.
    Anbei das Script un die Bilder...

    Edit: Ok hab´s jz hinbekommen. Es einzige Problem is jz, dass es die Figur immer um die Hand dreht^^ Also die Hand ist sozusagen der Angelpunkt der Drehung:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GDIPlus.au3>
    #include <StaticConstants.au3>
    #include <GUIConstants.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MouseCoordMode', 2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Const $winwidth = 800
    Const $winheight = 600
    Global $background = @ScriptDir&"\schach.jpg"
    Global $startbutton = @ScriptDir&"\start.png"
    Global $figurpath = @ScriptDir&"\figur.png"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    Global $start = _GDIPlus_ImageLoadFromFile($startbutton)
    Global $figurload = _GDIPlus_BitmapCreateFromFile ($figurpath)
    Global $iWidth = _GDIPlus_ImageGetWidth ($figurload)
    Global $iHeight = _GDIPlus_ImageGetHeight ($figurload)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $backpic = _GDIPlus_BitmapCreateFromFile ($background)
    Global $width = _GDIPlus_ImageGetWidth($backpic)
    Global $height = _GDIPlus_ImageGetHeight($backpic)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate ("Versuch",$winwidth,$winheight)
    GUISetOnEvent ($GUI_EVENT_CLOSE,"ende")
    GUISetState (@SW_Show)

    [/autoit] [autoit][/autoit] [autoit]

    Global $graphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics ($width,$height,$graphic)
    Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    _GDIPlus_GraphicsDrawImage($graphic, $backpic, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImage($graphic,$start,370,230)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hFGBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $graphic)
    Global $hFGBackbuffer = _GDIPlus_ImageGetGraphicsContext($hFGBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $get = GUIGetMsg ()
    $cursor = GUIGetCursorInfo ()
    If not IsArray ($cursor) Then
    ExitLoop
    EndIf
    If $cursor[0] >= 370 and $cursor[0] <= 450 and $cursor[1] >= 230 and $cursor[1] <= 310 and $cursor[2] Then
    Game ()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Switch $get
    Case $GUI_EVENT_CLOSE
    ende ()
    EndSwitch
    Sleep (20)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Game ()
    Global $matrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($matrix, 35, 35)

    While 1
    _GDIPlus_GraphicsDrawImage($hBackbuffer, $backpic, 0, 0) ;draw background
    _GDIPlus_GraphicsClear($hFGBackbuffer, 0x00000000) ;clear backbuffer from foreground graphics

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_MatrixRotate($matrix, 3, "False") ;rotate foreground graphic
    _GDIPlus_GraphicsSetTransform($hFGBackbuffer, $matrix)
    _GDIPlus_GraphicsDrawImage($hFGBackbuffer, $figurload, -$iWidth, -$iHeight)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hFGBitmap, 370, 270, $iWidth, $iHeight) ;copy foreground backbuffer to main backbuffer
    _GDIPlus_GraphicsDrawImageRect($graphic, $hBitmap, 0, 0, $width, $height) ;copy full drawn image to main screen
    Sleep (50)
    WEnd

    Sleep (1000)

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func ende ()
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_ImageDispose($start)
    _GDIPlus_ImageDispose($figurload)
    _GDIPlus_MatrixDispose($matrix)
    _GDIPlus_Shutdown ()
    Exit
    EndFunc

    [/autoit]

    Einmal editiert, zuletzt von Manlius (2. März 2011 um 17:36)

  • Zitat

    Es einzige Problem is jz, dass es die Figur immer um die Hand dreht^^ Also die Hand ist sozusagen der Angelpunkt der Drehung:


    Der Angelpunkt wird durch _GDIPlus_MatrixTranslate bestimmt ;). Wenn du da die Koordinate für die Mitte des Bildes einsetzt dreht es sich auch um seinen Mittelpunkt.
    Allerdings erzeugst du mehrere Matrizen (bei jedem Aufruf der Funktion _Game) und ersetzt jeweils nur das Handle. Die Daten sind aber dann immer noch im Arbeitsspeicher... Also musst du jede erzeugte Matrix mit MatrixDispose auch wieder entfernen.

  • Mit

    [autoit]

    _GDIPlus_MatrixTranslate($hMatrix, $fOffsetX, $fOffsetY

    [/autoit]

    kann ich zwar den Angelpunkt verschieben, jedoch geht das ganze Bild auch mit ?(?(
    Somit is der Angelpunkt dann wieder die Hand^^
    Hier, was ich bis jetzt hab:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GDIPlus.au3>
    #include <StaticConstants.au3>
    #include <GUIConstants.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MouseCoordMode', 2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Const $winwidth = 800
    Const $winheight = 600
    Global $background = @ScriptDir&"\schach.jpg"
    Global $startbutton = @ScriptDir&"\start.png"
    Global $figurpath = @ScriptDir&"\figur.png"
    Global $ausgangx = 400
    Global $ausgangy = 500

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    Global $start = _GDIPlus_ImageLoadFromFile($startbutton)
    Global $figurload = _GDIPlus_BitmapCreateFromFile ($figurpath)
    Global $iWidth = _GDIPlus_ImageGetWidth ($figurload)
    Global $iHeight = _GDIPlus_ImageGetHeight ($figurload)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $backpic = _GDIPlus_BitmapCreateFromFile ($background)
    Global $width = _GDIPlus_ImageGetWidth($backpic)
    Global $height = _GDIPlus_ImageGetHeight($backpic)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate ("Versuch",$winwidth,$winheight)
    GUISetOnEvent ($GUI_EVENT_CLOSE,"ende")
    GUISetState (@SW_Show)

    [/autoit] [autoit][/autoit] [autoit]

    Global $graphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics ($width,$height,$graphic)
    Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    _GDIPlus_GraphicsDrawImage($graphic, $backpic, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImage($graphic,$start,370,230)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hFGBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth+20, $iHeight+20, $graphic)
    Global $hFGBackbuffer = _GDIPlus_ImageGetGraphicsContext($hFGBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $get = GUIGetMsg ()
    $cursor = GUIGetCursorInfo ()
    If not IsArray ($cursor) Then
    ExitLoop
    EndIf
    If $cursor[0] >= 370 and $cursor[0] <= 450 and $cursor[1] >= 230 and $cursor[1] <= 310 and $cursor[2] Then
    Game ()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Switch $get
    Case $GUI_EVENT_CLOSE
    ende ()
    EndSwitch
    Sleep (20)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Game ()
    Global $matrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($matrix, $iWidth/2, $iHeight/2)


    While 1


    _GDIPlus_GraphicsDrawImage($hBackbuffer, $backpic, 0, 0) ;draw background
    _GDIPlus_GraphicsClear($hFGBackbuffer, 0x00000000) ;clear backbuffer from foreground graphics

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_MatrixRotate($matrix, 3, "False") ;rotate foreground graphic
    _GDIPlus_GraphicsSetTransform($hFGBackbuffer, $matrix)
    _GDIPlus_GraphicsDrawImage($hFGBackbuffer, $figurload, -$iWidth, -$iHeight)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hFGBitmap, 355, 250, $iWidth+20, $iHeight+20) ;copy foreground backbuffer to main backbuffer
    _GDIPlus_GraphicsDrawImageRect($graphic, $hBitmap, 0, 0, $width, $height) ;copy full drawn image to main screen
    WEnd

    Sleep (1000)

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func ende ()
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_ImageDispose($start)
    _GDIPlus_ImageDispose($figurload)
    _GDIPlus_MatrixDispose($matrix)
    _GDIPlus_Shutdown ()
    Exit
    EndFunc
    EndFunc

    [/autoit]

    Wenn du die Bilder benötigst, die habe ich weiter oben schonmal hochgeladen...
    Danke

  • Wenn du MatrixTranslate verwendest und eine Graphic damit transfomierst, dann wird sozusagen das Koordinatensystem der Graphic verschoben. Also musst du in deinem Fall das Bild so zeichnen, dass der Mittelpunkt auf dem Punkt 0, 0 in der Graphic liegt...
    Das heißt: -Bildbreite/2, -Bildhöhe/2. ;)