Matrix Rotation funktioniert nicht

  • Hey,
    Als allererstes, ich will nicht hören wie Bugschleuderig oder unsauber programmiert diese "Engine" ist, das weiß ich selber nun sehr gut^^
    Nun zu meinem eigentlichen Problem, ich will ein kleines Quadrat rotieren lassen.
    Mit dem Frontbuffer funktioniert es wunderbar, nur nicht mit dem Quadrat, ich habe versucht das Handle von ImageLoadFromFile zu rotieren, also ein Einzelgriff, quasi, das funktioniert schonmal nicht. In der aktuellen Version sieht es so aus, das ich jedes gezeichnete Rechteck rotiere, das klappt leider auch nicht. Also es wird einfach nicht rotiert, ein Fehler kommt nicht.

    Bugschleuder Engine

    Spoiler anzeigen
    [autoit]


    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <Array.au3>
    #include <File.au3>
    #include <WinAPI.au3>

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

    ; #INDEX# =======================================================================================================================
    ; Title .........: CrystalEngine - BugSchleuder Version
    ; AutoIt Version : 3.3.6.1
    ; Language ......: English
    ; Description ...: 2D Game Engine
    ; Author(s) .....: Nakroma
    ; ===============================================================================================================================

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

    Global Const $iVersion = 1.0
    Global Const $iPI = ACos(-1)

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalStart
    ; Description ...: Creates a window and startup Crystal
    ; Syntax.........: _CrystalStart($sName[, $iMaxObj[, bFullscreen[, $iWidth[, $iHeight[, $_BGColor]]]]])
    ; Parameters ....: $sName - Name of the GUI
    ; $iMaxObj - Maximum number of graphical objects
    ; $bFullscreen - [optional] Fullscreen or simple GUI
    ; $iWidth - [optional] Width of the window
    ; $iHeight - [optional] Height of the window
    ; $_BGColor - [optional] Back color of the window
    ; Return values .: Success - Array with the GUI Handle and the backbuffer
    ; Failure - -1
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalStart($sName, $iMaxObj = 999, $bFullscreen = False, $iWidth = 800, $iHeight = 600, $_BGColor = 0x000000)
    Global $aObj[$iMaxObj][8]
    For $i = 0 To UBound($aObj) - 1
    $aObj[$i][0] = False ; Shows if object slot is taken
    $aObj[$i][1] = "" ; Handle of the image
    $aObj[$i][2] = 0 ; X axis
    $aObj[$i][3] = 0 ; Y axis
    $aObj[$i][4] = 0 ; Width
    $aObj[$i][5] = 0 ; Height
    $aObj[$i][6] = True ; Solid
    $aObj[$i][7] = 90 ; Rotation
    Next
    If $bFullscreen = True Then
    Global $iGUI_Width = @DesktopWidth
    Global $iGUI_Height = @DesktopHeight
    $iWidth = @DesktopWidth
    $iHeight = @DesktopHeight
    GUISetCursor(16, 1)
    Else
    Global $iGUI_Height = $iHeight
    Global $iGUI_Width = $iWidth
    EndIf
    Global $hGui = GUICreate($sName, $iWidth, $iHeight, 0, 0)
    If @error Then Return -1
    GUISetBkColor($_BGColor)
    GUISetState(@SW_SHOW)
    If $bFullscreen = True Then GUISetStyle($WS_MAXIMIZEBOX + $WS_MAXIMIZE, -1, $hGui)
    Global $_GuiBackColor = $_BGColor
    _GDIPlus_Startup()
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
    Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hMatrix = _GDIPlus_MatrixCreate()

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

    Local $aReturn[2] = [$hGui, $hBackbuffer]
    Return $aReturn
    EndFunc ;==>_CrystalStart

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalInitialize
    ; Description ...: Draw all images
    ; Syntax.........: _CrystalInitialize($iDegree)
    ; Parameters ....: $iDegree - Rotation
    ; Return values .: Success -
    ; Failure -
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalInitialize()
    For $i = 0 To UBound($aObj) - 1
    If $aObj[$i][0] = True Then
    _GDIPlus_MatrixRotate($hMatrix, $aObj[$i][7])
    Local $hRect = _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $aObj[$i][1], $aObj[$i][2], $aObj[$i][3], $aObj[$i][4], $aObj[$i][5])
    _GDIPlus_GraphicsSetTransform($hRect, $hMatrix)
    EndIf
    Next
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    _GDIPlus_GraphicsClear($hBackbuffer, $_GuiBackColor)
    EndFunc ;==>_CrystalInitialize

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalCreateChar
    ; Description ...: Creates a player controlable NPC
    ; Syntax.........: _CrystalCreateChar($sPath, $iX, $iY, $iWidth, $iHeight)
    ; Parameters ....: $sPath - Path to the image
    ; $iX - X axis where the image has to be loaded
    ; $iY - Y axis where the image has to be loaded
    ; $iWidth - Width of the image
    ; $iHeight - Height of the image
    ; Return values .: Success - GDI+ image handle
    ; Failure - -1
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalCreateChar($sPath, $iX, $iY, $iWidth, $iHeight)
    For $i = 0 To UBound($aObj) - 1
    If $aObj[$i][0] = False Then
    $aObj[$i][0] = True
    $aObj[$i][1] = _GDIPlus_ImageLoadFromFile($sPath)
    $aObj[$i][2] = $iX
    $aObj[$i][3] = $iY
    $aObj[$i][4] = $iWidth
    $aObj[$i][5] = $iHeight
    $aObj[$i][6] = True
    $aObj[$i][7] = 90
    Return $aObj[$i][1]
    ExitLoop
    EndIf
    Next
    Return -1
    EndFunc ;==>_CrystalCreateChar

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalCreateNPC
    ; Description ...: Creates an NPC
    ; Syntax.........: _CrystalCreateNPC($sPath, $iX, $iY, $iWidth, $iHeight)
    ; Parameters ....: $sPath - Path to the image
    ; $iX - X axis where the image has to be loaded
    ; $iY - Y axis where the image has to be loaded
    ; $iWidth - Width of the image
    ; $iHeight - Height of the image
    ; Return values .: Success - GDI+ image handle
    ; Failure - -1
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalCreateNPC($sPath, $iX, $iY, $iWidth, $iHeight)
    For $i = 0 To UBound($aObj) - 1
    If $aObj[$i][0] = False Then
    $aObj[$i][0] = True
    $aObj[$i][1] = _GDIPlus_ImageLoadFromFile($sPath)
    $aObj[$i][2] = $iX
    $aObj[$i][3] = $iY
    $aObj[$i][4] = $iWidth
    $aObj[$i][5] = $iHeight
    $aObj[$i][6] = True
    $aObj[$i][7] = 90
    Return $aObj[$i][1]
    ExitLoop
    EndIf
    Next
    Return -1
    EndFunc ;==>_CrystalCreateNPC

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalMoveChar
    ; Description ...: Moves a player controlable NPC
    ; Syntax.........: _CrystalMoveChar($hGDI, $iDegree[, $iSpeed])
    ; Parameters ....: $hGDI - GDI handle returned from _CrystalCreateChar
    ; $iDegree - Rotation in degree
    ; $iSpeed - [optional] Speed of the NPC
    ; Return values .: Success -
    ; Failure - -1
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalMoveChar($hGDI, $iDegree, $iSpeed = 2)
    For $i = 0 To UBound($aObj) - 1
    If $hGDI = $aObj[$i][1] Then
    $iBogen = ($iDegree * $iPI) / 180
    $aObj[$i][2] += Cos($iBogen) * $iSpeed
    $aObj[$i][3] += Sin($iBogen) * $iSpeed
    For $j=0 To UBound($aObj) - 1
    If (_CrystalCollisionSqSq($aObj[$i][2], $aObj[$i][3], $aObj[$i][4], $aObj[$i][5], $aObj[$j][2], $aObj[$j][3], $aObj[$j][4], $aObj[$j][5])) AND ($aObj[$j][6]=True) AND ($aObj[$j][1]<>$hGDI) Then
    $aObj[$i][2] -= Cos($iBogen) * $iSpeed
    $aObj[$i][3] -= Sin($iBogen) * $iSpeed
    EndIf
    Next
    If $aObj[$i][2] < 0 Then $aObj[$i][2] = 0
    If $aObj[$i][2] > $iGUI_Width - _GDIPlus_ImageGetWidth($hGDI) Then $aObj[$i][2] = $iGUI_Width - _GDIPlus_ImageGetWidth($hGDI)
    If $aObj[$i][3] < 0 Then $aObj[$i][3] = 0
    If $aObj[$i][3] > $iGUI_Height - _GDIPlus_ImageGetHeight($hGDI) Then $aObj[$i][3] = $iGUI_Height - _GDIPlus_ImageGetHeight($hGDI)
    EndIf
    Next
    EndFunc ;==>_CrystalMoveChar

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalRotateNPC
    ; Description ...: Rotates an NPC
    ; Syntax.........: _CrystalRotateNPC($hGDI, $iDegree)
    ; Parameters ....: $hGDI - GDI handle returned from _CrystalCreateChar/NPC
    ; $iDegree - Degree of rotation
    ; Return values .: Success -
    ; Failure -
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalRotateNPC($hGDI, $iDegree)
    For $i = 0 To UBound($aObj) - 1
    If $hGDI = $aObj[$i][1] Then
    $aObj[$i][7] = $iDegree
    EndIf
    Next
    EndFunc ;==>_CrystalRotateNPC

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalCreateRandomMap
    ; Description ...: Creates a random map
    ; Syntax.........: _CrystalCreateRandomMap($sGroundPath)
    ; Parameters ....: $sGroundPath - Path to the ground image
    ; Return values .: Success -
    ; Failure - -1
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalCreateRandomMap($sGroundPath)
    For $i = 0 To UBound($aObj) - 1
    If $aObj[$i][0] = False Then
    $aObj[$i][0] = True
    $aObj[$i][1] = _GDIPlus_ImageLoadFromFile($sGroundPath)
    $aObj[$i][2] = 0
    $aObj[$i][3] = 0
    $aObj[$i][4] = $iGUI_Width
    $aObj[$i][5] = $iGUI_Height
    $aObj[$i][6] = False
    $aObj[$i][7] = 90
    ExitLoop
    EndIf
    Next
    ;_CrystalCreateRandomEnviroment("./src/img/env_sprites/", $iMapSquare)
    EndFunc ;==>_CrystalCreateRandomMap

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalCollisionSqSq
    ; Description ...: Checks if two squares collide
    ; Syntax.........: _CrystalCollisionSqSq($iX1, $iY1, $iW1, $iH1, $iX2, $iY2, $iW2, $iH2)
    ; Parameters ....: $iX - X axis
    ; $iY - Y axis
    ; $iW - Width
    ; $iH - Height
    ; Return values .: Success - True
    ; Failure - False
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalCollisionSqSq($iX1, $iY1, $iW1, $iH1, $iX2, $iY2, $iW2, $iH2)
    If ($iX1 + $iW1 > $iX2 And $iY1 + $iH1 > $iY2 And $iX1 < $iX2 + $iW2 And $iY1 < $iY2 + $iH2) Then
    Return True
    Else
    Return False
    EndIf
    EndFunc ;==>_CrystalCollisionSqSq

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalCreateRandomEnviroment
    ; Description ...: Creates random enviroment over the map
    ; Syntax.........: _CrystalCreateRandomMap($sSpritePath, $iMapSize[, $iNumber])
    ; Parameters ....: $sSpritePath - Path to all enviroment sprites
    ; $iMapSize - Size of map
    ; $iNumber - [optional] Number of enviroment sprites
    ; Return values .: Success -
    ; Failure - -1
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    #cs
    Func _CrystalCreateRandomEnviroment($sSpritePath, $iMapSize, $iNumber = 4)
    Local $iStartNumber = 0
    Local $iSize = $iMapSize * 0.2
    For $i = 0 To 99
    $bF = False
    $iRX = Random(0, $iMapSize - $iSize, 1)
    $iRY = Random(0, $iMapSize - $iSize, 1)
    For $i = 0 To UBound($aObj) - 1
    If $aObj[$i][0] = True Then
    If (_CrystalCollisionSqSq($iRX, $iRY, $iSize, $iSize, $aObj[$i][2], $aObj[$i][3], $aObj[$i][4], $aObj[$i][5]) = False) OR ($aObj[$i][6] = False) Then
    $bF = True
    ExitLoop
    EndIf
    EndIf
    Next
    If $bF = True Then
    $aFiles = _FileListToArray($sSpritePath, "*", 1)
    For $i = 0 To UBound($aObj) - 1
    $iRF = Random(1, $aFiles[0], 1)
    If $aObj[$i][0] = False Then
    $aObj[$i][0] = True
    $aObj[$i][1] = _GDIPlus_ImageLoadFromFile($sSpritePath & $aFiles[$iRF])
    $aObj[$i][2] = $iRX
    $aObj[$i][3] = $iRY
    $aObj[$i][4] = $iMapSize * 0.2
    $aObj[$i][5] = $iMapSize * 0.2
    $aObj[$i][6] = True
    $aObj[$i][7] = 90
    $iStartNumber += 1
    $bF = False
    ExitLoop
    EndIf
    Next
    EndIf
    If $iStartNumber >= $iNumber Then ExitLoop
    Next
    EndFunc ;==>_CrystalCreateRandomEnviroment
    #ce

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalClose
    ; Description ...: Closes the gui and Crystal
    ; Syntax.........: _CrystalClose()
    ; Parameters ....:
    ; Return values .: Success -
    ; Failure -
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalClose()
    For $i = 0 To UBound($aObj) - 1
    If $aObj[$i][0] = True Then
    _GDIPlus_ImageDispose($aObj[$i][1])
    EndIf
    Next
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_Shutdown()
    GUIDelete($hGui)
    EndFunc ;==>_CrystalClose

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _CrystalHideMouse
    ; Description ...: Hides the mouse cursor
    ; Syntax.........: _CrystalHideMouse()
    ; Parameters ....:
    ; Return values .: Success -
    ; Failure -
    ; Author ........: Nakroma (http://www.schmierdeinbrot.de)
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _CrystalHideMouse()
    MouseMove(@DesktopWidth + 500, @DesktopHeight + 500, 1)
    _WinAPI_ShowCursor(False)
    EndFunc

    [/autoit]

    Mainscript

    Spoiler anzeigen
    [autoit]


    #include <CrystalEngine.au3>
    #include <GuiConstants.au3>
    #include <Misc.au3>
    Opt("GUIOnEventMode", 1)
    HotKeySet("{ESC}", "_Exit")

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

    $iDegree = 90

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

    $iGUI_Width = @DesktopWidth
    $iGUI_Height = @DesktopHeight

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

    _CrystalStart("Test", 999, True)
    If @Error Then _Exit()
    _CrystalCreateRandomMap("./src/img/ground.gif")
    $hChar = _CrystalCreateChar("./src/img/env_sprites/sprite_1.gif", $iGUI_Width/2 - 10, 20, 25, 25)
    _CrystalCreateNPC("./src/img/env_sprites/sprite_2.gif", 100, 20, 25, 25)

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

    While 1
    _CrystalInitialize()
    _CrystalHideMouse()
    If _IsPressed("57") Then _CrystalMoveChar($hChar, $iDegree)
    If _IsPressed("44") Then
    $iDegree += 10
    _CrystalRotateNPC($hChar, $iDegree)
    EndIf
    If _IsPressed("41") Then
    $iDegree -= 10
    _CrystalRotateNPC($hChar, $iDegree)
    EndIf
    WEnd

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

    Func _Exit()
    _CrystalClose()
    Exit
    EndFunc

    [/autoit]
  • Schau dir doch mal das Beispiel in der Hilfe an...
    Du musst nicht den Rückgabewert von DrawImageRect rotieren (was sowieso kein Sinn macht, weil dieser Wert kein Handle ist sondern lediglich der rückmeldung dient ob die Funktion geklappt hat), sondern die Grafik in die du etwas zeichnen willst. Und zwar bevor du das zeichnest!
    Bitte informiere dich mal darüber wie diese Funktion angewendet wird. Dazu gibt es Beispiele in der Hilfe und sogar hier im Forum (ich sollte es wissen, ich habe schließlich eins davon geschrieben).

  • Dann musst du dir vielleicht andere Berater suchen :whistling: .
    Ein Handle ist eine Zahl, eine Art Adresse mit der man auf Obekte im Speicher zugreifen kann. Was komt dabei raus wenn man versucht eine Zahl zu rotieren? Richtig, nichts. Weil das kein bisschen Sinn macht.
    Außerdem ist das was von DrawImageRect zurückgegeben wird kein Handle. Wenn du mal die Hilfe lesen würdest, dann wüsstest du nämlich, dass diese Funktion bei Erfolg True und im Falle eines Fehlers False zurückgibt.