Sign in to follow this  
Followers 0
maestro

GDI+ image question

9 posts in this topic

Hey, is it possible to use GDI+ to "Skew" an image, i know you can load up an image that is a perfect rectangle, but I want to be able to create the image but at a skewed angle so for example the height of the right corner is not the same as the height of the left corner, or the length of one side is longer/shorter then other sides.

Basically I've built a cube with GDI+ and I want to be able to apply textures to the sides by stretching images over them based on the corner points.

Thanks,

Ilmaestro.


Hello, World!... LAME lol

Share this post


Link to post
Share on other sites



UEZ's thread is probably a great source of enlightening examples and solutions.

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

_GDIPlus_Startup()

Local $hBmp = _ScreenCapture_Capture("", 0, 0, -1, -1, False)
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_WinAPI_DeleteObject($hBmp)

; Skew or shear matrix:

;         [ 1 0 0 ] ; identity
; Hx(s) = [ s 1 0 ] ; x = x + sy
;         [ 0 0 1 ] ; identity or no translation

;         [ 1 s 0 ] ; identity
; Hy(s) = [ 0 1 0 ] ; y = y + sx
;         [ 0 0 1 ] ; identity or no translation

; [   1   0   0 ]
; [ 0.25  1   0 ]
; [   0   0   0 ]
Local $nShear = 0.25 ; shear by 25%
Local $hShearMtx = _GDIPlus_MatrixCreate2(1, 0, 0.25, 1, 0, 0)

Local $iW, $iH
$iW = _GDIPlus_ImageGetWidth($hBitmap)
$iH = _GDIPlus_ImageGetHeight($hBitmap)
Local $hNewBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hNewBitmap)
_GDIPlus_GraphicsSetTransform($hGraphics, $hShearMtx)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
_GDIPlus_ImageSaveToFile($hNewBitmap, @ScriptDir & "\shear25px.bmp")

_GDIPlus_MatrixDispose($hShearMtx)
$hShearMtx = _GDIPlus_MatrixCreate2(1, 0.25, 0, 1, 0, 0)
_GDIPlus_GraphicsSetTransform($hGraphics, $hShearMtx)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
_GDIPlus_ImageSaveToFile($hNewBitmap, @ScriptDir & "\shear25py.bmp")

; Cleanup.
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hNewBitmap)
_GDIPlus_MatrixDispose($hShearMtx)
_GDIPlus_BitmapDispose($hBitmap)

_GDIPlus_Shutdown()



Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[6]
EndFunc

Func _GDIPlus_MatrixCreate2($nM11, $nM12, $nM21, $nM22, $nDX, $nDY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateMatrix2", "float", $nM11, "float", $nM12, "float", $nM21, "float", $nM22, "float", $nDX, "float", $nDY, "int*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[7]
EndFunc

Share this post


Link to post
Share on other sites

Cool thanks, Couldn't find an exact example but found some things that will work.


Hello, World!... LAME lol

Share this post


Link to post
Share on other sites

Here another great example by eukalyptus:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GuiOnEventMode", 1)

Global $aDrag[5][2] = [[0, 0],[0, 0],[800, 50],[100, 530],[700, 450]]

$hGui = GUICreate("DrawImage_4Points Test", 800, 580)
GUISetOnEvent(-3, "_Exit")
GUICtrlCreateButton("render with higher precision", 200, 550, 200, 20)
GUICtrlSetOnEvent(-1, "_Render")
GUICtrlCreateLabel("precision:", 410, 550, 80, 20, 0x0002)
$cSlider = GUICtrlCreateSlider(500, 545, 100, 25)
GUICtrlSetData(-1, 25)
GUICtrlSetOnEvent(-1, "_Slider")
$cLabel = GUICtrlCreateLabel("0.25", 610, 550, 50, 20)

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics(800, 540, $hGraphics)
$hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUISetState()

$hBrush = _GDIPlus_BrushCreateSolid(0x8800FF00)
$hPen = _GDIPlus_PenCreate(0xFFFF0000)

$sFile = FileOpenDialog("open image", "", "(*.jpg;*.bmp;*.png;*.tif;*.gif)")
$hImage = _GDIPlus_ImageLoadFromFile($sFile)

_ReDraw(0.02)

$iIndex = 0
While 1
    $aInfo = GUIGetCursorInfo($hGui)

    If Not $aInfo[2] Then $iIndex = 0
    Switch $iIndex
        Case 0
            If $aInfo[2] Then
                For $I = 1 To 4
                    If $aInfo[0] > $aDrag[$I][0] - 5 And $aInfo[0] < $aDrag[$I][0] + 5 And $aInfo[1] > $aDrag[$I][1] - 5 And $aInfo[1] < $aDrag[$I][1] + 5 Then
                        $iIndex = $I
                        ExitLoop
                    EndIf
                Next
            EndIf
        Case Else
            $aDrag[$iIndex][0] = $aInfo[0]
            $aDrag[$iIndex][1] = $aInfo[1]
            _ReDraw(0.02)
    EndSwitch

    Sleep(20)
WEnd

#cs
Func _GDIPlus_GraphicsDrawImage_4Points($hGraphics, $hImage, $X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4, $fPrecision = 0.25)
    ;by eukalyptus
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False)
    Local $hPath = $aResult[2]

    Local $iW = _GDIPlus_ImageGetWidth($hImage)
    Local $iH = _GDIPlus_ImageGetHeight($hImage)

    If $fPrecision <= 0 Then $fPrecision = 0.01
    If $fPrecision > 1 Then $fPrecision = 1

    Local $iTX = Ceiling($iW * $fPrecision)
    Local $iTY = Ceiling($iH * $fPrecision)
    Local $iCnt = ($iTX + 1) * ($iTY + 1)
    Local $X, $Y

    Local $tPoints = DllStructCreate("float[" & $iCnt * 2 & "]")
    Local $I
    For $Y = 0 To $iTY
        For $X = 0 To $iTX
            $I = ($Y * ($iTX + 1) + $X) * 2
            DllStructSetData($tPoints, 1, $X * $iW / $iTX, $I + 1)
            DllStructSetData($tPoints, 1, $Y * $iH / $iTY, $I + 2)
        Next
    Next

    $aResult = DllCall($ghGDIPDll, "uint", "GdipAddPathPolygon", "hwnd", $hPath, "ptr", DllStructGetPtr($tPoints), "int", $iCnt)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 2, False)

    Local $tWarp = DllStructCreate("float[8]")
    DllStructSetData($tWarp, 1, $X1, 1)
    DllStructSetData($tWarp, 1, $Y1, 2)
    DllStructSetData($tWarp, 1, $X2, 3)
    DllStructSetData($tWarp, 1, $Y2, 4)
    DllStructSetData($tWarp, 1, $X3, 5)
    DllStructSetData($tWarp, 1, $Y3, 6)
    DllStructSetData($tWarp, 1, $X4, 7)
    DllStructSetData($tWarp, 1, $Y4, 8)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPath, "hwnd", 0, "ptr", DllStructGetPtr($tWarp), "int", 4, "float", 0, "float", 0, "float", $iW, "float", $iH, "int", 0, "float", 0)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 3, False)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetPathPoints", "hwnd", $hPath, "ptr", DllStructGetPtr($tPoints), "int", $iCnt)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 4, False)

    Local $tRectF = DllStructCreate("float X;float Y;float Width;float Height")
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tRectF), "hwnd", 0, "hwnd", 0)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 5, False)

    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)

    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(DllStructGetData($tRectF, 1) + DllStructGetData($tRectF, 3), DllStructGetData($tRectF, 2) + DllStructGetData($tRectF, 4), $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    Local $tDraw = DllStructCreate("float[6]")
    Local $pDraw = DllStructGetPtr($tDraw)
    Local $W = $iW / $iTX
    Local $H = $iH / $iTY
    Local $iO = ($iTX + 1) * 2
    Local $fX1, $fY1, $fX2, $fY2, $fX3, $fY3, $fSX, $fSY

    For $Y = 0 To $iTY - 1
        For $X = 0 To $iTX - 1
            $I = ($Y * ($iTX + 1) + $X) * 2
            $fX1 = DllStructGetData($tPoints, 1, $I + 1)
            $fY1 = DllStructGetData($tPoints, 1, $I + 2)

            Switch $X
                Case $iTX - 1
                    $fX2 = DllStructGetData($tPoints, 1, $I + 3)
                    $fY2 = DllStructGetData($tPoints, 1, $I + 4)
                    $fSX = 1
                Case Else
                    $fX2 = DllStructGetData($tPoints, 1, $I + 5)
                    $fY2 = DllStructGetData($tPoints, 1, $I + 6)
                    $fSX = 2
            EndSwitch

            Switch $Y
                Case $iTY - 1
                    $fX3 = DllStructGetData($tPoints, 1, $I + 1 + $iO)
                    $fY3 = DllStructGetData($tPoints, 1, $I + 2 + $iO)
                    $fSY = 1
                Case Else
                    $fX3 = DllStructGetData($tPoints, 1, $I + 1 + $iO * 2)
                    $fY3 = DllStructGetData($tPoints, 1, $I + 2 + $iO * 2)
                    $fSY = 2
            EndSwitch

            DllStructSetData($tDraw, 1, $fX1, 1)
            DllStructSetData($tDraw, 1, $fY1, 2)
            DllStructSetData($tDraw, 1, $fX2, 3)
            DllStructSetData($tDraw, 1, $fY2, 4)
            DllStructSetData($tDraw, 1, $fX3, 5)
            DllStructSetData($tDraw, 1, $fY3, 6)

            DllCall($ghGDIPDll, "uint", "GdipDrawImagePointsRect", "hwnd", $hContext, "hwnd", $hImage, "ptr", $pDraw, "int", 3, "float", $X * $W, "float", $Y * $H, "float", $W * $fSX, "float", $H * $fSY, "int", 2, "hwnd", 0, "ptr", 0, "ptr", 0)
        Next
    Next

    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    _GDIPlus_BitmapDispose($hBitmap)
EndFunc   ;==>_GDIPlus_GraphicsDrawImage_4Points
#ce

Func _GDIPlus_GraphicsDrawImage_4Points($hGraphics, $hImage, $X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4, $fPrecision = 0.25)
    ;by eukalyptus
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False)
    Local $hPath = $aResult[2]

    Local $iW = _GDIPlus_ImageGetWidth($hImage)
    Local $iH = _GDIPlus_ImageGetHeight($hImage)
    Local $details = 1
    For $Y = 0 To $iH - 1 Step $details
        For $X = 0 To $iW - 1 Step $details
            DllCall($ghGDIPDll, "uint", "GdipAddPathRectangle", "hwnd", $hPath, "float", $X, "float", $Y, "float", 1, "float", 1)
        Next
    Next

    Local $tWarp = DllStructCreate("float[8]")
    DllStructSetData($tWarp, 1, $X1, 1)
    DllStructSetData($tWarp, 1, $Y1, 2)
    DllStructSetData($tWarp, 1, $X2, 3)
    DllStructSetData($tWarp, 1, $Y2, 4)
    DllStructSetData($tWarp, 1, $X3, 5)
    DllStructSetData($tWarp, 1, $Y3, 6)
    DllStructSetData($tWarp, 1, $X4, 7)
    DllStructSetData($tWarp, 1, $Y4, 8)

    DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPath, "hwnd", 0, "ptr", DllStructGetPtr($tWarp), "int", 4, "float", 0, "float", 0, "float", $iW, "float", $iH, "int", 0, "float", 0)

    Local $iCnt = $iW * $iH * 4
    Local $tPoints = DllStructCreate("float[" & $iCnt * 2 & "]")
    Local $pPoints = DllStructGetPtr($tPoints)
    DllCall($ghGDIPDll, "uint", "GdipGetPathPoints", "hwnd", $hPath, "ptr", $pPoints, "int", $iCnt)

    Local $tRectF = DllStructCreate("float X;float Y;float Width;float Height")
    DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tRectF), "hwnd", 0, "hwnd", 0)

    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)

    Local $iNW = DllStructGetData($tRectF, 1) + DllStructGetData($tRectF, 3)
    Local $iNH = DllStructGetData($tRectF, 2) + DllStructGetData($tRectF, 4)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iNW, $iNH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)

    Local $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    Local $Stride = DllStructGetData($BitmapData, "Stride")
    Local $Width = DllStructGetData($BitmapData, "Width")
    Local $Height = DllStructGetData($BitmapData, "Height")
    Local $Scan0 = DllStructGetData($BitmapData, "Scan0")
    Local $PixelData
    Local $iOff = 0
    For $row = 0 To $Height - 1 Step $details
        $PixelData = DllStructCreate("dword[" & $Width & ']', $Scan0 + ($row * $Stride))
        For $col = 0 To $Width - 1 Step $details
            DllCall($ghGDIPDll, "int", "GdipSetSolidFillColor", "handle", $hBrush, "dword", DllStructGetData($PixelData, 1, $col + 1))
            DllCall($ghGDIPDll, "uint", "GdipFillPolygon2", "hwnd", $hContext, "hwnd", $hBrush, "ptr", $pPoints + $iOff, "int", 4)
            $iOff += 32
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hImage, $BitmapData)

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    _GDIPlus_BitmapDispose($hBitmap)
EndFunc   ;==>_GDIPlus_GraphicsDrawImage_4Points








Func _ReDraw($fPrecision)
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
    _GDIPlus_GraphicsDrawImage_4Points($hGfxBuffer, $hImage, $aDrag[1][0], $aDrag[1][1], $aDrag[2][0], $aDrag[2][1], $aDrag[3][0], $aDrag[3][1], $aDrag[4][0], $aDrag[4][1], $fPrecision)
    For $I = 1 To 4
        _GDIPlus_GraphicsFillRect($hGfxBuffer, $aDrag[$I][0] - 5, $aDrag[$I][1] - 5, 10, 10, $hBrush)
        _GDIPlus_GraphicsDrawRect($hGfxBuffer, $aDrag[$I][0] - 5, $aDrag[$I][1] - 5, 10, 10, $hPen)
    Next
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
EndFunc   ;==>_ReDraw


Func _Slider()
    GUICtrlSetData($cLabel, GUICtrlRead($cSlider) / 100)
EndFunc   ;==>_Slider


Func _Render()
    Local $fPrecision = GUICtrlRead($cSlider) / 100
    SplashTextOn("Rendering with precision " & $fPrecision, "please wait", 250, 50)
    _ReDraw($fPrecision)
    SplashOff()
EndFunc   ;==>_Render


Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT


Func _Exit()
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

UEZ's thread is probably a great source of enlightening examples and solutions.

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

_GDIPlus_Startup()

Local $hBmp = _ScreenCapture_Capture("", 0, 0, -1, -1, False)
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_WinAPI_DeleteObject($hBmp)

; Skew or shear matrix:

;         [ 1 0 0 ] ; identity
; Hx(s) = [ s 1 0 ] ; x = x + sy
;         [ 0 0 1 ] ; identity or no translation

;         [ 1 s 0 ] ; identity
; Hy(s) = [ 0 1 0 ] ; y = y + sx
;         [ 0 0 1 ] ; identity or no translation

; [   1   0   0 ]
; [ 0.25  1   0 ]
; [   0   0   0 ]
Local $nShear = 0.25 ; shear by 25%
Local $hShearMtx = _GDIPlus_MatrixCreate2(1, 0, 0.25, 1, 0, 0)

Local $iW, $iH
$iW = _GDIPlus_ImageGetWidth($hBitmap)
$iH = _GDIPlus_ImageGetHeight($hBitmap)
Local $hNewBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hNewBitmap)
_GDIPlus_GraphicsSetTransform($hGraphics, $hShearMtx)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
_GDIPlus_ImageSaveToFile($hNewBitmap, @ScriptDir & "\shear25px.bmp")

_GDIPlus_MatrixDispose($hShearMtx)
$hShearMtx = _GDIPlus_MatrixCreate2(1, 0.25, 0, 1, 0, 0)
_GDIPlus_GraphicsSetTransform($hGraphics, $hShearMtx)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
_GDIPlus_ImageSaveToFile($hNewBitmap, @ScriptDir & "\shear25py.bmp")

; Cleanup.
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hNewBitmap)
_GDIPlus_MatrixDispose($hShearMtx)
_GDIPlus_BitmapDispose($hBitmap)

_GDIPlus_Shutdown()



Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[6]
EndFunc

Func _GDIPlus_MatrixCreate2($nM11, $nM12, $nM21, $nM22, $nDX, $nDY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateMatrix2", "float", $nM11, "float", $nM12, "float", $nM21, "float", $nM22, "float", $nDX, "float", $nDY, "int*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[7]
EndFunc

Nice example as usual Mr. GDI+ GOD :x

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hey, is it possible to use GDI+ to "Skew" an image

It can be also flipped like this:

;=========================================
; Horizontal & Vertical Flip Example by Matrix2
;=========================================
#include <GDIPlus.au3>
#include <ScreenCapture.au3>

_GDIPlus_Startup()

Local $hBmp = _ScreenCapture_Capture("", 0, 0, -1, -1, False)
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_WinAPI_DeleteObject($hBmp)

Local $iW = _GDIPlus_ImageGetWidth($hBitmap)
Local $iH = _GDIPlus_ImageGetHeight($hBitmap)
Local $hMirrorMtx = _GDIPlus_MatrixCreate2(1.0,0.0,0.0,-1.0, 0, $iH)
Local $hNewBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hNewBitmap)
_GDIPlus_GraphicsSetTransform($hGraphics, $hMirrorMtx)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
_GDIPlus_ImageSaveToFile($hNewBitmap, @ScriptDir & "\VerticalFlip.jpg")

_GDIPlus_MatrixDispose($hMirrorMtx)
$hMirrorMtx = _GDIPlus_MatrixCreate2(-1.0,0.0,0.0,1.0, $iW, 0)
_GDIPlus_GraphicsSetTransform($hGraphics, $hMirrorMtx)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
_GDIPlus_ImageSaveToFile($hNewBitmap, @ScriptDir & "\HorizontalFlip.jpg")

; Cleanup.
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hNewBitmap)
_GDIPlus_MatrixDispose($hMirrorMtx)
_GDIPlus_BitmapDispose($hBitmap)

_GDIPlus_Shutdown()

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[6]
EndFunc

Func _GDIPlus_MatrixCreate2($nM11, $nM12, $nM21, $nM22, $nDX, $nDY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateMatrix2", "float", $nM11, "float", $nM12, "float", $nM21, "float", $nM22, "float", $nDX, "float", $nDY, "int*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[7]
EndFunc
Edited by ValeryVal

The point of world view

Share this post


Link to post
Share on other sites

...Basically I've built a cube with GDI+ and I want to be able to apply textures to the sides by stretching images over them based on the corner points...

I´ve changed the rotating cube example (UEZ/Lakes) to demonstrate my DrawImage_4Points-function:

#include <GDIPlus.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 1)

Global $user32_dll = DllOpen("user32.dll")
Global $Reset, $hPenDotted, $hPenDash, $ResetCube, $CubeX, $CubeY, $CubeZ
Global $CubeX1, $CubeY1, $CubeX2, $CubeY2, $CubeX3, $CubeY3, $CubeX4, $CubeY4
Global $Tog, $Tog1, $Tog2, $Tog3, $Tog4 = True, $Tog5, $Tog6, $Tog7 = True, $T, $Delay = 100
Global $Text = "Press F1 to F6 to Toogle Cube Faces (F7 Toggles the Autoit Logo being Painted)"
Global $text1 = "Left Mouse Button to Rotate, Right Mouse Button to Reset (Mouse wheel to Zoom)"

Local $dot_distance = 150
Local Const $Width = 600
Local Const $Height = $Width
Local Const $W2 = $Width / 2
Local Const $H2 = $Height / 2
Local Const $deg = 180 / ACos(-1)
Local $hwnd = GUICreate("Orginal Code by UEZ ", $Width, $Height)

GUISetState()

If @OSBuild < 7600 Then WinSetTrans($hwnd, "", 0xFF) ;workaround for XP machines when alpha blending is activated on _GDIPlus_GraphicsClear() function to avoid slow drawing

_GDIPlus_Startup()
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hBackbuffer)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

Local $sAutoItPath = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir')
Local $hImage = _GDIPlus_ImageLoadFromFile($sAutoItPath & "\Examples\GUI\logo4.gif")

Local $Str
Local $pColor = 0xFF0000F0
Local $hPen = _GDIPlus_PenCreate($pColor, 8)
_GDIPlus_PenSetEndCap($hPen, $GDIP_LINECAPARROWANCHOR)
Local $hCubePen = _GDIPlus_PenCreate(0x400000F0, 8)
_GDIPlus_PenSetEndCap($hCubePen, $GDIP_LINECAPARROWANCHOR)
Local $hBrush = _GDIPlus_BrushCreateSolid()
Local $hBrush1 = _GDIPlus_BrushCreateSolid(0x60FFFF00)
Local $hBrush2 = _GDIPlus_BrushCreateSolid(0x60FF8000)
$hPenDash = _GDIPlus_PenCreate(0xFF000000, 2)
_GDIPlus_PenSetDashStyle($hPenDash, $GDIP_DASHSTYLEDASH)
$hPenDotted = _GDIPlus_PenCreate(0xFF000000, 2)
_GDIPlus_PenSetDashStyle($hPenDotted, $GDIP_DASHSTYLEDOT)
Local Const $length = 250
Local Const $Pi = ACos(-1)
Local Const $amout_of_dots = 6
Local Const $amout_of_cube_dots = 9

#cs
    X           Y           Z
    ---------------------------------------
    1    [-$length,     0,          0 ], _
    2    [ $length,     0,          0 ], _
    3    [  0,      -$length,       0 ], _
    4    [  0,       $length,       0 ], _
    5    [  0,          0,      -$length ], _
    6    [  0,          0,       $length ]]
#ce

; Axis Coords
Local $draw_coordinates[$amout_of_dots][4] = [ _;   X                   y                   Z
        [-$length, 0, 0], _
        [$length, 0, 0], _
        [0, -$length, 0], _
        [0, $length, 0], _
        [0, 0, -$length], _
        [0, 0, $length]]
$Reset = $draw_coordinates

Local $cube_coordinates[$amout_of_cube_dots][4] = [ _;  X                   y                   Z
        [-$dot_distance, -$dot_distance, -$dot_distance], _
        [$dot_distance, -$dot_distance, -$dot_distance], _
        [$dot_distance, $dot_distance, -$dot_distance], _
        [-$dot_distance, $dot_distance, -$dot_distance], _
        [-$dot_distance, -$dot_distance, $dot_distance], _
        [$dot_distance, -$dot_distance, $dot_distance], _
        [$dot_distance, $dot_distance, $dot_distance], _
        [-$dot_distance, $dot_distance, $dot_distance]]
$ResetCube = $cube_coordinates


Local $x1, $y1, $x2, $y2
Local $b, $j, $x, $y, $z, $mx, $my, $MPos
Local $zoom_counter = 100
Local Const $zoom_min = 50
Local Const $zoom_max = 125
Local Const $mouse_sense = 4000
Local Const $start_x = $Width / 2
Local Const $start_y = $Height / 2
Local Const $dx = @DesktopWidth / 2, $dy = @DesktopHeight / 2
Local Const $Red = 0xFFF00000
Local Const $Green = 0xFF00F000
Local Const $Blue = 0xFF0000F0
Local $mwx, $mwy, $mwz, $angle, $rad = 180 / $Pi

MouseMove($dx, $dy, 1)

GUIRegisterMsg(0x020A, "WM_MOUSEWHEEL")

GUISetOnEvent(-3, "Close")

Do
    _GDIPlus_GraphicsClear($hBackbuffer, 0xF0FFFFFF)

    For $b = 0 To $amout_of_dots - 1 ;correct axis perspective
        $draw_coordinates[$b][3] = 1 + $draw_coordinates[$b][2] / 1500
    Next
    For $c = 0 To $amout_of_cube_dots - 1 ;correct  cube perspective
        $cube_coordinates[$c][3] = 1 + $cube_coordinates[$c][2] / 0x600
    Next

    ;draw axis lines
    Draw_Lines(0, 1, $Red) ;draw x axis - red
    Draw_Lines(2, 3, $Green) ;draw y axis - green
    Draw_Lines(4, 5, $Blue) ;draw z axis - blue
    ;--------------------------------------------------------------------

    Select
        Case _IsPressed("70", $user32_dll)
            Sleep($Delay)
            $Tog1 = Not $Tog1
            ;       Beep(100,50)

        Case _IsPressed("71", $user32_dll)
            Sleep($Delay)
            $Tog2 = Not $Tog2
            ;       Beep(200,50)

        Case _IsPressed("72", $user32_dll)
            Sleep($Delay)
            $Tog3 = Not $Tog3
            ;       Beep(300,50)

        Case _IsPressed("73", $user32_dll)
            Sleep($Delay)
            $Tog4 = Not $Tog4
            ;       Beep(400,50)

        Case _IsPressed("74", $user32_dll)
            Sleep($Delay)
            $Tog5 = Not $Tog5
            ;       Beep(500,50)

        Case _IsPressed("75", $user32_dll)
            Sleep($Delay)
            $Tog6 = Not $Tog6
            ;       Beep(600,50)

        Case _IsPressed("76", $user32_dll)
            Sleep($Delay)
            $Tog7 = Not $Tog7
            ;       Beep(700,50)
    EndSelect

    ;       4 -- - - - 5
    ;     / |        / |
    ;    0 - -  - - 1  |
    ;    |  |       |  |
    ;    |  7 -- - -|- 6
    ;    | /        | /
    ;    3 - -  - - 2
    If $Tog1 = True Then Draw_Cube_Lines(3, 2, 6, 7) ;F1 bottom
    If $Tog2 = True Then Draw_Cube_Lines(5, 1, 0, 4) ;F2 top
    If $Tog3 = True Then Draw_Cube_Lines(1, 2, 3, 0) ;F3 front
    If $Tog4 = True Then Draw_Cube_Lines(7, 6, 5, 4) ;F4 rear
    If $Tog5 = True Then Draw_Cube_Lines(6, 2, 1, 5) ;F5 right
    If $Tog6 = True Then Draw_Cube_Lines(0, 3, 7, 4) ;F6 left

    If _IsPressed("01", $user32_dll) Then ; Left mouse button to Rotate
        $MPos = MouseGetPos()
        For $j = 0 To $amout_of_dots - 1
            $mx = ($dx - $MPos[0]) / $mouse_sense
            $my = -($dy - $MPos[1]) / $mouse_sense
            Calc($my, $mx, $j) ;calculate axis coordinates
        Next
        For $j = 0 To $amout_of_cube_dots - 1
            CubeCalc($my, $mx, $j) ;calculate cube coordinates
        Next
    EndIf
    If _IsPressed("02", $user32_dll) Then ;Right mouse button to Reset CoOrds and Toggles to inital values
        $draw_coordinates = $Reset
        $cube_coordinates = $ResetCube
        $Tog1 = False
        $Tog2 = False
        $Tog3 = False
        $Tog4 = True ;Draw this Face as Default
        $Tog5 = False
        $Tog6 = False
        $Tog7 = True ;Paint Logo
    EndIf

    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $Width, $Height)
Until Not Sleep(30)

;Draw Axis Lines
Func Draw_Lines($p1, $p2, $pColor)
    $x1 = $start_x + $draw_coordinates[$p1][0] * $draw_coordinates[$p1][3]
    $y1 = $start_y + $draw_coordinates[$p1][1] * $draw_coordinates[$p1][3]

    $x2 = $start_x + $draw_coordinates[$p2][0] * $draw_coordinates[$p2][3]
    $y2 = $start_y + $draw_coordinates[$p2][1] * $draw_coordinates[$p2][3]

    _GDIPlus_PenSetColor($hPen, $pColor)
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $x1, $y1, $x2, $y2, $hPen)

    _GDIPlus_BrushSetSolidColor($hBrush, $pColor)
    _GDIPlus_GraphicsFillEllipse($hBackbuffer, $x1 - 10, $y1 - 10, 20, 20, $hBrush)

    $angle = Mod(360 - Abs(Angle($draw_coordinates[$p1][0], $draw_coordinates[$p2][1])), 360)
    Select
        Case $pColor = $Red
            $Str = "XAngle = " & StringFormat("%.2f", $angle)
        Case $pColor = $Green
            $Str = "YAngle = " & StringFormat("%.2f", $angle)
        Case $pColor = $Blue
            $Str = "ZAngle = " & StringFormat("%.2f", $angle)
    EndSelect
    _GDIPlus_GraphicsFillEllipse($hBackbuffer, $start_x - 10, $start_y - 10, 20, 20, 0) ; Origin
    _GDIPlus_GraphicsDrawString($hBackbuffer, "Origin", $start_x - 20, $start_y - 30)
    _GDIPlus_GraphicsDrawString($hBackbuffer, $Str, $x2 - 20, $y2 - 30)
EndFunc   ;==>Draw_Lines

Func Draw_Cube_Lines($Cp1, $Cp2, $Cp3, $Cp4)
    $CubeX1 = $start_x + $cube_coordinates[$Cp1][0] * $cube_coordinates[$Cp1][3]
    $CubeY1 = $start_y + $cube_coordinates[$Cp1][1] * $cube_coordinates[$Cp1][3]

    $CubeX2 = $start_x + $cube_coordinates[$Cp2][0] * $cube_coordinates[$Cp2][3]
    $CubeY2 = $start_y + $cube_coordinates[$Cp2][1] * $cube_coordinates[$Cp2][3]

    $CubeX3 = $start_x + $cube_coordinates[$Cp3][0] * $cube_coordinates[$Cp3][3]
    $CubeY3 = $start_y + $cube_coordinates[$Cp3][1] * $cube_coordinates[$Cp3][3]

    $CubeX4 = $start_x + $cube_coordinates[$Cp4][0] * $cube_coordinates[$Cp4][3]
    $CubeY4 = $start_y + $cube_coordinates[$Cp4][1] * $cube_coordinates[$Cp4][3]

    ;#######                    For Front Face              #########
    ;------------------------------- Top -------------------------------------------------------
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $CubeX4, $CubeY4, $CubeX1, $CubeY1, $hCubePen) ; top 0 - 1
    _GDIPlus_GraphicsFillEllipse($hBackbuffer, $CubeX4 - 5, $CubeY4 - 5, 10, 10, 0)

    _GDIPlus_GraphicsDrawLine($hBackbuffer, $start_x, $start_y, $CubeX4, $CubeY4, $hPenDash)
    _GDIPlus_GraphicsDrawString($hBackbuffer, $Cp4, $CubeX4 - 10, $CubeY4 - 20, "Arial", 12)
    _GDIPlus_GraphicsDrawString($hBackbuffer, $Cp1, $CubeX1, $CubeY1 - 20, "Arial", 12)
    ;-------------------------------------------------------------------------------------------
    ;------------------------------- Right -------------------------------------------------------
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $CubeX1, $CubeY1, $CubeX2, $CubeY2, $hCubePen) ; right 2 - 1
    ;---------------------------------------------------------------------------------------------
    ;------------------------------- Bottom -------------------------------------------------------
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $CubeX2, $CubeY2, $CubeX3, $CubeY3, $hCubePen) ; bottom 3 - 2
    _GDIPlus_GraphicsFillEllipse($hBackbuffer, $CubeX2 - 5, $CubeY2 - 5, 10, 10, 0)

    _GDIPlus_GraphicsDrawLine($hBackbuffer, $start_x, $start_y, $CubeX2, $CubeY2, $hPenDash)
    _GDIPlus_GraphicsDrawString($hBackbuffer, $Cp2, $CubeX2 + 5, $CubeY2, "Arial", 12)
    _GDIPlus_GraphicsDrawString($hBackbuffer, $Cp3, $CubeX3 - 10, $CubeY3, "Arial", 12)
    ;----------------------------------------------------------------------------------------------
    _GDIPlus_GraphicsDrawString($hBackbuffer, $Text, 5, 550, "Arial", 12) ;Instructions
    _GDIPlus_GraphicsDrawString($hBackbuffer, $text1, 5, 570, "Arial", 12)

    ;------------------------------- Left --------------------------------------------------------
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $CubeX3, $CubeY3, $CubeX4, $CubeY4, $hCubePen) ; left
    ;----------------------------------------------------------------------------------------------
    _GDIPlus_GraphicsDrawString($hBackbuffer, $Cp3, $CubeX3 - 10, $CubeY3, "Arial", 12)
    ;--------------------------- Put the Autoit Logo image on one Face ----------------------------------------------
    If $Cp1 = 7 And $Tog7 = True Then
        _GDIPlus_GraphicsDrawImage_4Points($hBackbuffer, $hImage, $CubeX4, $CubeY4, _
                $CubeX3, $CubeY3, _
                $CubeX1, $CubeY1, _
                $CubeX2, $CubeY2, 0.05)
    EndIf
EndFunc   ;==>Draw_Cube_Lines





Func _GDIPlus_GraphicsDrawImage_4Points($hGraphics, $hImage, $X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4, $fPrecision = 0.25)
    ;by eukalyptus
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False)
    Local $hPath = $aResult[2]

    Local $iW = _GDIPlus_ImageGetWidth($hImage)
    Local $iH = _GDIPlus_ImageGetHeight($hImage)

    If $fPrecision <= 0 Then $fPrecision = 0.01
    If $fPrecision > 1 Then $fPrecision = 1

    Local $iTX = Ceiling($iW * $fPrecision)
    Local $iTY = Ceiling($iH * $fPrecision)
    Local $iCnt = ($iTX + 1) * ($iTY + 1)
    Local $X, $Y

    Local $tPoints = DllStructCreate("float[" & $iCnt * 2 & "]")
    Local $I
    For $Y = 0 To $iTY
        For $X = 0 To $iTX
            $I = ($Y * ($iTX + 1) + $X) * 2
            DllStructSetData($tPoints, 1, $X * $iW / $iTX, $I + 1)
            DllStructSetData($tPoints, 1, $Y * $iH / $iTY, $I + 2)
        Next
    Next

    $aResult = DllCall($ghGDIPDll, "uint", "GdipAddPathPolygon", "hwnd", $hPath, "ptr", DllStructGetPtr($tPoints), "int", $iCnt)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 2, False)

    Local $tWarp = DllStructCreate("float[8]")
    DllStructSetData($tWarp, 1, $X1, 1)
    DllStructSetData($tWarp, 1, $Y1, 2)
    DllStructSetData($tWarp, 1, $X2, 3)
    DllStructSetData($tWarp, 1, $Y2, 4)
    DllStructSetData($tWarp, 1, $X3, 5)
    DllStructSetData($tWarp, 1, $Y3, 6)
    DllStructSetData($tWarp, 1, $X4, 7)
    DllStructSetData($tWarp, 1, $Y4, 8)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPath, "hwnd", 0, "ptr", DllStructGetPtr($tWarp), "int", 4, "float", 0, "float", 0, "float", $iW, "float", $iH, "int", 0, "float", 0)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 3, False)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetPathPoints", "hwnd", $hPath, "ptr", DllStructGetPtr($tPoints), "int", $iCnt)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 4, False)

    Local $tRectF = DllStructCreate("float X;float Y;float Width;float Height")
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tRectF), "hwnd", 0, "hwnd", 0)
    If @error Or Not IsArray($aResult) Then Return SetError(1, 5, False)

    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)

    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(DllStructGetData($tRectF, 1) + DllStructGetData($tRectF, 3), DllStructGetData($tRectF, 2) + DllStructGetData($tRectF, 4), $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    Local $tDraw = DllStructCreate("float[6]")
    Local $pDraw = DllStructGetPtr($tDraw)
    Local $W = $iW / $iTX
    Local $H = $iH / $iTY
    Local $iO = ($iTX + 1) * 2
    Local $fX1, $fY1, $fX2, $fY2, $fX3, $fY3, $fSX, $fSY

    For $Y = 0 To $iTY - 1
        For $X = 0 To $iTX - 1
            $I = ($Y * ($iTX + 1) + $X) * 2
            $fX1 = DllStructGetData($tPoints, 1, $I + 1)
            $fY1 = DllStructGetData($tPoints, 1, $I + 2)

            Switch $X
                Case $iTX - 1
                    $fX2 = DllStructGetData($tPoints, 1, $I + 3)
                    $fY2 = DllStructGetData($tPoints, 1, $I + 4)
                    $fSX = 1
                Case Else
                    $fX2 = DllStructGetData($tPoints, 1, $I + 5)
                    $fY2 = DllStructGetData($tPoints, 1, $I + 6)
                    $fSX = 2
            EndSwitch

            Switch $Y
                Case $iTY - 1
                    $fX3 = DllStructGetData($tPoints, 1, $I + 1 + $iO)
                    $fY3 = DllStructGetData($tPoints, 1, $I + 2 + $iO)
                    $fSY = 1
                Case Else
                    $fX3 = DllStructGetData($tPoints, 1, $I + 1 + $iO * 2)
                    $fY3 = DllStructGetData($tPoints, 1, $I + 2 + $iO * 2)
                    $fSY = 2
            EndSwitch

            DllStructSetData($tDraw, 1, $fX1, 1)
            DllStructSetData($tDraw, 1, $fY1, 2)
            DllStructSetData($tDraw, 1, $fX2, 3)
            DllStructSetData($tDraw, 1, $fY2, 4)
            DllStructSetData($tDraw, 1, $fX3, 5)
            DllStructSetData($tDraw, 1, $fY3, 6)

            DllCall($ghGDIPDll, "uint", "GdipDrawImagePointsRect", "hwnd", $hContext, "hwnd", $hImage, "ptr", $pDraw, "int", 3, "float", $X * $W, "float", $Y * $H, "float", $W * $fSX, "float", $H * $fSY, "int", 2, "hwnd", 0, "ptr", 0, "ptr", 0)
        Next
    Next

    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    _GDIPlus_BitmapDispose($hBitmap)
EndFunc   ;==>_GDIPlus_GraphicsDrawImage_4Points






Func Angle($x, $y)
    Local $angle
    If $x = 0 Then
        $angle = 0
    Else
        $angle = -ATan($y / - $x) * $deg
    EndIf
    If - $x < 0 Then
        $angle = -180 + $angle
    ElseIf - $x >= 0 And $y < 0 Then
        $angle = -360 + $angle
    EndIf
    Return $angle
EndFunc   ;==>Angle

Func Calc($angle_x, $angle_y, $I, $angle_z = 0)
    ;calculate axis 3D rotation
    $x = $draw_coordinates[$I][0] * Cos($angle_y) + $draw_coordinates[$I][2] * Sin($angle_y)
    $y = $draw_coordinates[$I][1]
    $z = -$draw_coordinates[$I][0] * Sin($angle_y) + $draw_coordinates[$I][2] * Cos($angle_y)

    $draw_coordinates[$I][0] = $x
    $draw_coordinates[$I][1] = $y * Cos($angle_x) - $z * Sin($angle_x)
    $draw_coordinates[$I][2] = $y * Sin($angle_x) + $z * Cos($angle_x)
EndFunc   ;==>Calc

Func CubeCalc($angle_x, $angle_y, $I)
    ;calculate Cube 3D rotation
    $CubeX = $cube_coordinates[$I][0] * Cos($angle_y) + $cube_coordinates[$I][2] * Sin($angle_y)
    $CubeY = $cube_coordinates[$I][1]
    $CubeZ = -$cube_coordinates[$I][0] * Sin($angle_y) + $cube_coordinates[$I][2] * Cos($angle_y)

    $cube_coordinates[$I][0] = $CubeX
    $cube_coordinates[$I][1] = $CubeY * Cos($angle_x) - $CubeZ * Sin($angle_x)
    $cube_coordinates[$I][2] = $CubeY * Sin($angle_x) + $CubeZ * Cos($angle_x)
EndFunc   ;==>CubeCalc

Func Close()
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPenDash)
    _GDIPlus_PenDispose($hPenDotted)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    DllClose($user32_dll)
    Exit
EndFunc   ;==>Close

Func Zoom($factor)
    Local $m
    For $m = 0 To $amout_of_dots - 1
        $draw_coordinates[$m][0] *= $factor
        $draw_coordinates[$m][1] *= $factor
        $draw_coordinates[$m][2] *= $factor
    Next
    For $m = 0 To $amout_of_cube_dots - 1
        $cube_coordinates[$m][0] *= $factor
        $cube_coordinates[$m][1] *= $factor
        $cube_coordinates[$m][2] *= $factor
    Next
EndFunc   ;==>Zoom

Func WM_MOUSEWHEEL($hwnd, $iMsg, $wParam, $lParam)
    Local $wheel_Dir = BitAND($wParam, 0x800000)
    If $wheel_Dir > 0 Then
        If $zoom_counter <= $zoom_max Then
            Zoom(1.05)
            $zoom_counter += 1
        EndIf
    Else
        If $zoom_counter >= $zoom_min Then
            Zoom(0.95)
            $zoom_counter -= 1
        EndIf
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_MOUSEWHEEL

E

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Here an alpha release of the rotating cube with textures:

Look here (1 month available): Rotating Cube with textures (sorry my attachment quota is full, I cannot upload it here directly!)

Do not rotate to the left first because it will crash!

Original _GDIPlus_GraphicsDrawImage_4Points code: eukalyptus

Converted to ASM by: AndyG

Original cube code: UEZ

Currently it is slow but it's an ALPHA RELEASE!!!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0