Sign in to follow this  
Followers 0
Starg

Simple 3D Graphics with GDI+

50 posts in this topic

Nice work. If you set smoothing for the gfx handle it looks much better ;)
 

Func _S3d_SelectGraphic($hGraphic, $iWidth, $iHeight)
    $__S3d_hGraphic = $hGraphic
    $__S3d_iWidth = $iWidth
    $__S3d_iHeight = $iHeight
    _GDIPlus_GraphicsSetSmoothingMode($__S3d_hGraphic, 2)
EndFunc ;==>_S3d_SelectGraphic

Using matrices to rotate the object is cool.  :thumbsup: 
 
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,

Thanks for the advice.

Using matrices to rotate the object is cool. :thumbsup:

I'm going to write some examples to show the power of Local Matrices.

Share this post


Link to post
Share on other sites

This looks like something I can use.

I have a small program for editing meshes but it lacks a preview feature and have to use another program to see my results.

It is able to draw UV stamps for the models using GDI, so it shouldn't be too different to adapt to this.

This looks approachable. Thanks for sharing.  I'll be back with results after trying it out.

Share this post


Link to post
Share on other sites

UPDATE

New version (v1.1.0) released!

Please see the first post.

  • Added: _S3d_RegPolygon, _S3d_Star
  • Added: _S3d_LocalTranslate, _S3d_LocalScale, _S3d_LocalRotateX, _S3d_LocalRotateY, _S3d_LocalRotateZ
  • Added: _S3d_SelectGraphic sets smoothing mode for Graphics object
  • Changed: default value of $fFill in _S3d_Square changed to True

 

Enjoy!

Share this post


Link to post
Share on other sites

UPDATE

New version (v1.1.1) released! Please see the first post.

  • Added an example of _S3d_Star function.

Any comments are welcome.

Share this post


Link to post
Share on other sites

Using floating point calls gives the movement more smoothness:

S3d.au3

;=================================================
; S3d - Simple 3D Graphic Library
; v1.1.1 (26/JUL/2013)
;
; Author: Starg
;
; - Tested on: Windows XP SP3
; AutoIt v3.3.8.1, v3.3.9.12
; - Requires GDIPlus.au3
;
; * Use at your own risk!
;
; - Special Thanks: S.Programs
;=================================================

#include-once
#include <GDIPlus.au3>

;=================================================
; Constants
;=================================================

Global Const $__S3d_PI = 3.14159265358979

;=================================================
; Global Variables
;=================================================

Global $__S3d_hGraphic, $__S3d_iWidth, $__S3d_iHeight
Global $__S3d_nFAngleTan, $__S3d_nFScale

Global $__S3d_hPen, $__S3d_hBrush, $__S3d_hFont, $__S3d_hFormat

Global $__S3d_aConvertMatrix = __S3d_CreateMatrix()
Global $__S3d_aLocalMatrix = __S3d_CreateMatrix()
Global $__S3d_aCameraMatrix = __S3d_CreateMatrix()

Global $__S3d_aCameraPos[3]

; $__S3d_nPosBuf0X and $__S3d_nPosBuf0Y are used as "Current Position"
Global $__S3d_nPosBuf0X, $__S3d_nPosBuf0Y, $__S3d_nPosBuf1X, $__S3d_nPosBuf1Y


;=================================================
; Functions
;=================================================
; _S3d_SelectGraphic -- select a graphic object to write to
Func _S3d_SelectGraphic($hGraphic, $iWidth, $iHeight)
$__S3d_hGraphic = $hGraphic
$__S3d_iWidth = $iWidth
$__S3d_iHeight = $iHeight

_GDIPlus_GraphicsSetSmoothingMode($__S3d_hGraphic, 2) ; Thanks to UEZ
EndFunc ;==>_S3d_SelectGraphic

; _S3d_SelectPen -- select a pen object
Func _S3d_SelectPen($hPen)
$__S3d_hPen = $hPen
EndFunc ;==>_S3d_SelectPen

; _S3d_SelectBrush -- select a brush object
Func _S3d_SelectBrush($hBrush)
$__S3d_hBrush = $hBrush
EndFunc ;==>_S3d_SelectBrush

; _S3d_SelectFont -- select a Font object
Func _S3d_SelectFont($hFont)
$__S3d_hFont = $hFont
EndFunc ;==>_S3d_SelectFont

; _S3d_SelectFormat -- select a String Format object
Func _S3d_SelectFormat($hFormat)
$__S3d_hFormat = $hFormat
EndFunc ;==>_S3d_SelectFormat

;=================================================

; _S3d_Dist -- returns the distance betwenn two points
Func _S3d_Dist($nPos1X = 0, $nPos1Y = 0, $nPos1Z = 0, $nPos2X = 0, $nPos2Y = 0, $nPos2Z = 0)
Return Sqrt(($nPos2X - $nPos1X) ^ 2 + ($nPos2Y - $nPos1Y) ^ 2 + ($nPos2Z - $nPos1Z) ^ 2)
EndFunc ;==>_S3d_Dist

Func _S3d_DistFromCamera($nPosX = 0, $nPosY = 0, $nPosZ = 0)
Return Sqrt(($nPosX - $__S3d_aCameraPos[0]) ^ 2 + ($nPosY - $__S3d_aCameraPos[1]) ^ 2 + ($nPosZ - $__S3d_aCameraPos[2]) ^ 2)
EndFunc ;==>_S3d_DistFromCamera


; _S3d_SetCamera -- sets camera and target coordinates
Func _S3d_SetCamera($nCameraX, $nCameraY, $nCameraZ, $nTargetX, $nTargetY, $nTargetZ, $nVAngle = 0, $nFAngle = 0.8, $nFScale = 1000)

Local $nDist = _S3d_Dist($nTargetX, $nTargetY, $nTargetZ, $nCameraX, $nCameraY, $nCameraZ)
Local $nXYLen = _S3d_Dist($nTargetX, $nTargetY, 0, $nCameraX, $nCameraY, 0)

; cos(-a) = cos(a)
; sin(-a) = - sin(a)
Local $nXYCos = ($nTargetX - $nCameraX) / $nXYLen
Local $nXYSin = -($nTargetY - $nCameraY) / $nXYLen

Local $nXZCos = $nXYLen / $nDist
Local $nXZSin = -($nTargetZ - $nCameraZ) / $nDist

Local $aMxXY = __S3d_CreateMatrix(), $aMxXZ = __S3d_CreateMatrix(), $aMxV = __S3d_CreateMatrix()
Local $aTransMatrix = __S3d_CreateMatrix()
Local $aTempMatrix = __S3d_CreateMatrix()

__S3d_SetMatrix($aTransMatrix, _
1, 0, 0, -$nCameraX, _
0, 1, 0, -$nCameraY, _
0, 0, 1, -$nCameraZ, _
0, 0, 0, 1)

__S3d_SetMatrix($aMxXY, _
$nXYCos, -$nXYSin, 0, 0, _
$nXYSin, $nXYCos, 0, 0, _
0, 0, 1, 0, _
0, 0, 0, 1)

__S3d_SetMatrix($aMxXZ, _
$nXZCos, 0, -$nXZSin, 0, _
0, 1, 0, 0, _
$nXZSin, 0, $nXZCos, 0, _
0, 0, 0, 1)

__S3d_SetMatrix($aMxV, _
1, 0, 0, 0, _
0, Cos(-$nVAngle), -Sin(-$nVAngle), 0, _
0, Sin(-$nVAngle), Cos(-$nVAngle), 0, _
0, 0, 0, 1)

__S3d_MultiplyMatrix($__S3d_aCameraMatrix, $aMxXY, $aTransMatrix)
__S3d_MultiplyMatrix($aTempMatrix, $aMxXZ, $__S3d_aCameraMatrix)
__S3d_MultiplyMatrix($__S3d_aCameraMatrix, $aMxV, $aTempMatrix)

_S3d_SetLocalMatrix()

$__S3d_nFAngleTan = Tan($nFAngle)
$__S3d_nFScale = $nFScale

$__S3d_aCameraPos[0] = $nCameraX
$__S3d_aCameraPos[1] = $nCameraY
$__S3d_aCameraPos[2] = $nCameraZ
EndFunc ;==>_S3d_SetCamera

; _S3d_SetLocalMatrix - local coordinates -> world coordinates
Func _S3d_SetLocalMatrix( _
$n00 = 1, $n01 = 0, $n02 = 0, $n03 = 0, _
$n10 = 0, $n11 = 1, $n12 = 0, $n13 = 0, _
$n20 = 0, $n21 = 0, $n22 = 1, $n23 = 0, _
$n30 = 0, $n31 = 0, $n32 = 0, $n33 = 1)

__S3d_SetMatrix($__S3d_aLocalMatrix, _
$n00, $n01, $n02, $n03, _
$n10, $n11, $n12, $n13, _
$n20, $n21, $n22, $n23, _
$n30, $n31, $n32, $n33)

__S3d_MultiplyMatrix($__S3d_aConvertMatrix, $__S3d_aCameraMatrix, $__S3d_aLocalMatrix)

EndFunc ;==>_S3d_SetLocalMatrix

; _S3d_MultiplyLocalMatrix
Func _S3d_MultiplyLocalMatrix( _
$n00 = 1, $n01 = 0, $n02 = 0, $n03 = 0, _
$n10 = 0, $n11 = 1, $n12 = 0, $n13 = 0, _
$n20 = 0, $n21 = 0, $n22 = 1, $n23 = 0, _
$n30 = 0, $n31 = 0, $n32 = 0, $n33 = 1)

Local $aMatrix = __S3d_CreateMatrix(), $aBufLocalMatrix = $__S3d_aLocalMatrix

__S3d_SetMatrix($aMatrix, _
$n00, $n01, $n02, $n03, _
$n10, $n11, $n12, $n13, _
$n20, $n21, $n22, $n23, _
$n30, $n31, $n32, $n33)

__S3d_MultiplyMatrix($__S3d_aLocalMatrix, $aMatrix, $aBufLocalMatrix)
__S3d_MultiplyMatrix($__S3d_aConvertMatrix, $__S3d_aCameraMatrix, $__S3d_aLocalMatrix)

EndFunc ;==>_S3d_MultiplyLocalMatrix


Func _S3d_LocalTranslate($nX, $nY, $nZ)
_S3d_MultiplyLocalMatrix( _
1, 0, 0, $nX, _
0, 1, 0, $nY, _
0, 0, 1, $nZ, _
0, 0, 0, 1)

EndFunc ;==>_S3d_LocalTranslate

Func _S3d_LocalScale($nX, $nY, $nZ)
_S3d_MultiplyLocalMatrix( _
$nX, 0, 0, 0, _
0, $nY, 0, 0, _
0, 0, $nZ, 0, _
0, 0, 0, 1)

EndFunc ;==>_S3d_LocalScale

; $nAngle is radians if $fDeg is false, degrees if true.
Func _S3d_LocalRotateX($nAngle, $fDeg = False)
If $fDeg Then $nAngle = __S3d_Deg2Rad($nAngle)
_S3d_MultiplyLocalMatrix( _
1, 0, 0, 0, _
0, Cos($nAngle), -Sin($nAngle), 0, _
0, Sin($nAngle), Cos($nAngle), 0, _
0, 0, 0, 1)

EndFunc ;==>_S3d_LocalRotateX

Func _S3d_LocalRotateY($nAngle, $fDeg = False)
If $fDeg Then $nAngle = __S3d_Deg2Rad($nAngle)
_S3d_MultiplyLocalMatrix( _
Cos($nAngle), 0, -Sin($nAngle), 0, _
0, 1, 0, 0, _
Sin($nAngle), 0, Cos($nAngle), 0, _
0, 0, 0, 1)
EndFunc ;==>_S3d_LocalRotateY

Func _S3d_LocalRotateZ($nAngle, $fDeg = False)
If $fDeg Then $nAngle = __S3d_Deg2Rad($nAngle)
_S3d_MultiplyLocalMatrix( _
Cos($nAngle), -Sin($nAngle), 0, 0, _
Sin($nAngle), Cos($nAngle), 0, 0, _
0, 0, 1, 0, _
0, 0, 0, 1)
EndFunc ;==>_S3d_LocalRotateZ


Func _S3d_GetLocalMatrix()
Return $__S3d_aLocalMatrix
EndFunc ;==>_S3d_GetLocalMatrix

;=================================================

; _S3d_GetPos - converts 3D -> 2D
Func _S3d_GetPos($nX, $nY, $nZ)
Local $aPos[2]
__S3d_ConvertPos($aPos[0], $aPos[1], $nX, $nY, $nZ)
If @error Then Return SetError(1, 0, 0)
Return $aPos
EndFunc ;==>_S3d_GetPos

Func _S3d_MoveTo($nX, $nY, $nZ = Default)
If IsKeyword($nZ) Then
$__S3d_nPosBuf0X = $nX
$__S3d_nPosBuf0Y = $nY
Else
__S3d_ConvertPos($__S3d_nPosBuf0X, $__S3d_nPosBuf0Y, $nX, $nY, $nZ)
If @error Then Return SetError(1, 0, 0)
EndIf
Return 1
EndFunc ;==>_S3d_MoveTo

Func _S3d_Clear($nColor = 0xFF000000)
Return _GDIPlus_GraphicsClear($__S3d_hGraphic, $nColor)
EndFunc ;==>_S3d_Clear

Func _S3d_Line($nX1, $nY1, $nZ1, $nX2, $nY2, $nZ2)
Local $nOutX1, $nOutY1, $nOutX2, $nOutY2, $iError1, $iError2

__S3d_ConvertPos($nOutX1, $nOutY1, $nX1, $nY1, $nZ1)
$iError1 = @error
__S3d_ConvertPos($nOutX2, $nOutY2, $nX2, $nY2, $nZ2)
$iError2 = @error

If (Not $iError1) And (Not $iError2) Then
;~ _GDIPlus_GraphicsDrawLine($__S3d_hGraphic, $nOutX1, $nOutY1, $nOutX2, $nOutY2, $__S3d_hPen)
DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $__S3d_hGraphic, "handle", $__S3d_hPen, "float", $nOutX1, "float", $nOutY1, "float", $nOutX2, "float", $nOutY2)
Return 1
ElseIf (Not $iError1) Or (Not $iError2) Then
; clipping

Local $nAX, $nAY, $nAZ, $nBX, $nBY, $nBZ
Local $nCX, $nCY, $nCZ, $nPos3X, $nPos3Y

If Not $iError1 Then
$__S3d_nPosBuf0X = $nOutX1
$__S3d_nPosBuf0Y = $nOutY1

$nAX = $nX1
$nAY = $nY1
$nAZ = $nZ1

$nBX = $nX2
$nBY = $nY2
$nBZ = $nZ2
Else
$__S3d_nPosBuf0X = $nOutX2
$__S3d_nPosBuf0Y = $nOutY2

$nAX = $nX2
$nAY = $nY2
$nAZ = $nZ2

$nBX = $nX1
$nBY = $nY1
$nBZ = $nZ1
EndIf

Local $i
For $i = 1 To 10 ; 2 ^ 10 = 1024

$nCX = ($nAX + $nBX) / 2
$nCY = ($nAY + $nBY) / 2
$nCZ = ($nAZ + $nBZ) / 2

__S3d_ConvertPos($nPos3X, $nPos3Y, $nCX, $nCY, $nCZ)

If Not @error Then
$nAX = $nCX
$nAY = $nCY
$nAZ = $nCZ

;~ _GDIPlus_GraphicsDrawLine($__S3d_hGraphic, $__S3d_nPosBuf0X, $__S3d_nPosBuf0Y, $nPos3X, $nPos3Y, $__S3d_hPen)
DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $__S3d_hGraphic, "handle", $__S3d_hPen, "float", $__S3d_nPosBuf0X, "float", $__S3d_nPosBuf0Y, "float", $nPos3X, "float", $nPos3Y)

$__S3d_nPosBuf0X = $nPos3X
$__S3d_nPosBuf0Y = $nPos3Y
Else
$nBX = $nCX
$nBY = $nCY
$nBZ = $nCZ
EndIf

Next

Return 2
Else
Return 0
EndIf
EndFunc ;==>_S3d_Line

Func _S3d_LineTo($nX, $nY, $nZ)
Local $nOutX, $nOutY
__S3d_ConvertPos($nOutX, $nOutY, $nX, $nY, $nZ)

;~ _GDIPlus_GraphicsDrawLine($__S3d_hGraphic, $__S3d_nPosBuf0X, $__S3d_nPosBuf0Y, $nOutX, $nOutY, $__S3d_hPen)
DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $__S3d_hGraphic, "handle", $__S3d_hPen, "float", $__S3d_nPosBuf0X, "float", $__S3d_nPosBuf0Y, "float", $nOutX, "float", $nOutY)

$__S3d_nPosBuf0X = $nOutX
$__S3d_nPosBuf0Y = $nOutY
EndFunc ;==>_S3d_LineTo

Func _S3d_Box($nX1, $nY1, $nZ1, $nX2, $nY2, $nZ2)

_S3d_Line($nX1, $nY1, $nZ1, $nX2, $nY1, $nZ1)
_S3d_Line($nX2, $nY1, $nZ1, $nX2, $nY2, $nZ1)
_S3d_Line($nX2, $nY2, $nZ1, $nX1, $nY2, $nZ1)
_S3d_Line($nX1, $nY2, $nZ1, $nX1, $nY1, $nZ1)

_S3d_Line($nX1, $nY1, $nZ2, $nX2, $nY1, $nZ2)
_S3d_Line($nX2, $nY1, $nZ2, $nX2, $nY2, $nZ2)
_S3d_Line($nX2, $nY2, $nZ2, $nX1, $nY2, $nZ2)
_S3d_Line($nX1, $nY2, $nZ2, $nX1, $nY1, $nZ2)

_S3d_Line($nX1, $nY1, $nZ1, $nX1, $nY1, $nZ2)
_S3d_Line($nX1, $nY2, $nZ1, $nX1, $nY2, $nZ2)
_S3d_Line($nX2, $nY1, $nZ1, $nX2, $nY1, $nZ2)
_S3d_Line($nX2, $nY2, $nZ1, $nX2, $nY2, $nZ2)

EndFunc ;==>_S3d_Box

Func _S3d_Arrow($nX1, $nY1, $nZ1, $nX2, $nY2, $nZ2, $nLen = 30, $nAngle = 0.6)

If $nLen < 0 Then Return SetError(1, 0, 0)

Local $nPos1X, $nPos1Y, $nPos2X, $nPos2Y
__S3d_ConvertPos($nPos1X, $nPos1Y, $nX1, $nY1, $nZ1)
If @error Then Return SetError(2, 0, 0)
__S3d_ConvertPos($nPos2X, $nPos2Y, $nX2, $nY2, $nZ2)
If @error Then Return SetError(3, 0, 0)

;~ _GDIPlus_GraphicsDrawLine($__S3d_hGraphic, $nPos1X, $nPos1Y, $nPos2X, $nPos2Y, $__S3d_hPen)
DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $__S3d_hGraphic, "handle", $__S3d_hPen, "float", $nPos1X, "float", $nPos1Y, "float", $nPos2X, "float", $nPos2Y)

Local $nDist = _S3d_Dist($nPos1X, $nPos1Y, 0, $nPos2X, $nPos2Y, 0)

Local $nCenX = ($nPos1X - $nPos2X) / $nDist * $nLen
Local $nCenY = ($nPos1Y - $nPos2Y) / $nDist * $nLen

Local $nCos = Cos($nAngle), $nSin = Sin($nAngle)

Local $aPosA1X = $nCenX * $nCos - $nCenY * $nSin + $nPos2X
Local $aPosA1Y = $nCenX * $nSin + $nCenY * $nCos + $nPos2Y
; sin (-a) = - sin a
; cos (-a) = cos a
Local $aPosA2X = $nCenX * $nCos + $nCenY * $nSin + $nPos2X
Local $aPosA2Y = -$nCenX * $nSin + $nCenY * $nCos + $nPos2Y

;~ _GDIPlus_GraphicsDrawLine($__S3d_hGraphic, $nPos2X, $nPos2Y, $aPosA1X, $aPosA1Y, $__S3d_hPen)
DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $__S3d_hGraphic, "handle", $__S3d_hPen, "float", $nPos2X, "float", $nPos2Y, "float", $aPosA1X, "float", $aPosA1Y)
;~ _GDIPlus_GraphicsDrawLine($__S3d_hGraphic, $nPos2X, $nPos2Y, $aPosA2X, $aPosA2Y, $__S3d_hPen)
DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $__S3d_hGraphic, "handle", $__S3d_hPen, "float", $nPos2X, "float", $nPos2Y, "float", $aPosA2X, "float", $aPosA2Y)

Return 1
EndFunc ;==>_S3d_Arrow

Func _S3d_Circle($nX, $nY, $nZ, $nRad, $fFill = False)

If $nRad <= 0 Then Return SetError(1, 0, 0)
Local $nPosX, $nPosY
; (_S3d_DistFromCamera($nX, $nY, $nZ) * $__S3d_nFAngleTan) : $nRad = $__S3d_nFScale : $nVRad
Local $nVRad = $nRad * $__S3d_nFScale / _S3d_DistFromCamera($nX, $nY, $nZ) / $__S3d_nFAngleTan
__S3d_ConvertPos($nPosX, $nPosY, $nX, $nY, $nZ)
If @error Then Return SetError(2, 0, 0)

If $fFill Then
;~ Return _GDIPlus_GraphicsFillEllipse($__S3d_hGraphic, $nPosX - $nVRad, $nPosY - $nVRad, $nVRad * 2, $nVRad * 2, $__S3d_hBrush)
Return DllCall($ghGDIPDll, "int", "GdipFillEllipse", "handle", $__S3d_hGraphic, "handle", $__S3d_hBrush, "float", $nPosX - $nVRad, "float", $nPosY - $nVRad, "float", $nVRad * 2, "float", $nVRad * 2)
Else
;~ Return _GDIPlus_GraphicsDrawEllipse($__S3d_hGraphic, $nPosX - $nVRad, $nPosY - $nVRad, $nVRad * 2, $nVRad * 2, $__S3d_hPen)
Return DllCall($ghGDIPDll, "int", "GdipDrawEllipse", "handle", $__S3d_hGraphic, "handle", $__S3d_hPen, "float", $nPosX - $nVRad, "float", $nPosY - $nVRad, "float", $nVRad * 2, "float", $nVRad * 2)
EndIf
EndFunc ;==>_S3d_Circle

; $aPoints[0][0] : The number of points
; $aPoints[n][0] : nth X
; $aPoints[n][1] : nth Y
; $aPoints[n][2] : nth Z
Func _S3d_Polygon($aPoints, $fFill = False)
If Not IsArray($aPoints) Then Return SetError(1, 0, 0)
Local $a2dPoints[$aPoints[0][0] + 1][2], $i
$a2dPoints[0][0] = $aPoints[0][0]

For $i = 1 To $aPoints[0][0]
__S3d_ConvertPos($a2dPoints[$i][0], $a2dPoints[$i][1], $aPoints[$i][0], $aPoints[$i][1], $aPoints[$i][2])
If @error Then Return SetError(2, $i, 0)
Next

If $fFill Then
;~ SetError(_GDIPlus_GraphicsFillPolygon($__S3d_hGraphic, $a2dPoints, $__S3d_hBrush))
SetError(_GDIPlus_GraphicsFillPolygonF($__S3d_hGraphic, $a2dPoints, $__S3d_hBrush))
Else
;~ _GDIPlus_GraphicsDrawPolygon($__S3d_hGraphic, $a2dPoints, $__S3d_hPen)
_GDIPlus_GraphicsDrawPolygonF($__S3d_hGraphic, $a2dPoints, $__S3d_hPen)
EndIf
Return 1
EndFunc ;==>_S3d_Polygon

; Always draw on XY plane
Func _S3d_RegPolygon($nX, $nY, $nZ, $nRad, $iNum, $fFill = True)
If $nRad <= 0 Then Return SetError(1, 0, 0)
If (Not IsInt($iNum)) Or $iNum <= 0 Then Return SetError(2, 0, 0)

Local $aPoints[$iNum + 1][3], $i, $nCurDir = 0
$aPoints[0][0] = $iNum

For $i = 1 To $iNum
$aPoints[$i][0] = $nX + $nRad * Cos($nCurDir)
$aPoints[$i][1] = $nY + $nRad * Sin($nCurDir)
$aPoints[$i][2] = $nZ
$nCurDir += $__S3d_PI * 2 / $iNum
Next

Return _S3d_Polygon($aPoints, $fFill)
EndFunc ;==>_S3d_RegPolygon

; Always draw on XY plane
Func _S3d_Star($nX, $nY, $nZ, $nRad1, $nRad2, $iNum, $fFill = True)
If $nRad1 <= 0 Then Return SetError(1, 0, 0)
If $nRad2 <= 0 Then Return SetError(2, 0, 0)
If (Not IsInt($iNum)) Or $iNum <= 0 Then Return SetError(3, 0, 0)

Local $aPoints[$iNum * 2 + 1][3], $i, $nCurDir = 0
$aPoints[0][0] = $iNum * 2

For $i = 1 To $iNum * 2 Step 2
$aPoints[$i][0] = $nX + $nRad1 * Cos($nCurDir)
$aPoints[$i][1] = $nY + $nRad1 * Sin($nCurDir)
$aPoints[$i][2] = $nZ
$nCurDir += $__S3d_PI / $iNum

$aPoints[$i + 1][0] = $nX + $nRad2 * Cos($nCurDir)
$aPoints[$i + 1][1] = $nY + $nRad2 * Sin($nCurDir)
$aPoints[$i + 1][2] = $nZ
$nCurDir += $__S3d_PI / $iNum
Next

Return _S3d_Polygon($aPoints, $fFill)
EndFunc ;==>_S3d_Star

Func _S3d_Square($nX1, $nY1, $nZ1, $nX2, $nY2, $nZ2, $nX3, $nY3, $nZ3, $nX4, $nY4, $nZ4, $fFill = True)
Local $aPoints[5][3] = [[4, 0, 0], [$nX1, $nY1, $nZ1], [$nX2, $nY2, $nZ2], [$nX3, $nY3, $nZ3], [$nX4, $nY4, $nZ4]]
Return _S3d_Polygon($aPoints, $fFill)
EndFunc ;==>_S3d_Square

Func _S3d_MoveTo2($nXL, $nYL, $nZL, $nXR, $nYR, $nZR)
__S3d_ConvertPos($__S3d_nPosBuf0X, $__S3d_nPosBuf0Y, $nXL, $nYL, $nZL)
If @error Then Return SetError(1, 0, 0)
__S3d_ConvertPos($__S3d_nPosBuf1X, $__S3d_nPosBuf1Y, $nXR, $nYR, $nZR)
If @error Then Return SetError(2, 0, 0)
Return 1
EndFunc ;==>_S3d_MoveTo2

Func _S3d_RibbonTo($nXL, $nYL, $nZL, $nXR, $nYR, $nZR)
Local $aPos[5][2]
$aPos[0][0] = 4

$aPos[1][0] = $__S3d_nPosBuf0X
$aPos[1][1] = $__S3d_nPosBuf0Y
$aPos[2][0] = $__S3d_nPosBuf1X
$aPos[2][1] = $__S3d_nPosBuf1Y

__S3d_ConvertPos($aPos[4][0], $aPos[4][1], $nXL, $nYL, $nZL)
If @error Then Return SetError(1, 0, 0)
__S3d_ConvertPos($aPos[3][0], $aPos[3][1], $nXR, $nYR, $nZR)
If @error Then Return SetError(2, 0, 0)

;~ _GDIPlus_GraphicsFillPolygon($__S3d_hGraphic, $aPos, $__S3d_hBrush)
_GDIPlus_GraphicsFillPolygonF($__S3d_hGraphic, $aPos, $__S3d_hBrush)

$__S3d_nPosBuf0X = $aPos[4][0]
$__S3d_nPosBuf0Y = $aPos[4][1]
$__S3d_nPosBuf1X = $aPos[3][0]
$__S3d_nPosBuf1Y = $aPos[3][1]

EndFunc ;==>_S3d_RibbonTo

Func _S3d_String($sString, $nX, $nY, $nZ)
Local $nPosX, $nPosY
__S3d_ConvertPos($nPosX, $nPosY, $nX, $nY, $nZ)
If @error Then Return SetError(1, 0, 0)

Local $tLayout = _GDIPlus_RectFCreate($nPosX, $nPosY, 0, 0)
Local $aInfo = _GDIPlus_GraphicsMeasureString($__S3d_hGraphic, $sString, $__S3d_hFont, $tLayout, $__S3d_hFormat)
Return _GDIPlus_GraphicsDrawStringEx($__S3d_hGraphic, $sString, $__S3d_hFont, $aInfo[0], $__S3d_hFormat, $__S3d_hBrush)
EndFunc ;==>_S3d_String

;=================================================
; Functions (Internal use only)
;=================================================

; __S3d_Rotate -- ($nInX, $nInY) -> ($nOutX, $nOutY)
Func __S3d_Rotate(ByRef $nOutX, ByRef $nOutY, $nInX, $nInY, $nCenterX, $nCenterY, $nAngle)
$nOutX = ($nInX - $nCenterX) * Cos($nAngle) - ($nInY - $nCenterY) * Sin($nAngle) + $nInX
$nOutY = ($nInX - $nCenterX) * Sin($nAngle) + ($nInY - $nCenterY) * Cos($nAngle) + $nInY
EndFunc ;==>__S3d_Rotate

Func __S3d_CreateMatrix()
Local $aMatrix[4][4], $i, $j

For $i = 0 To 3
For $j = 0 To 3
$aMatrix[$i][$j] = 0
Next
Next

Return $aMatrix
EndFunc ;==>__S3d_CreateMatrix

Func __S3d_SetMatrix(ByRef $aMatrix, _
$n00 = 1, $n01 = 0, $n02 = 0, $n03 = 0, _
$n10 = 0, $n11 = 1, $n12 = 0, $n13 = 0, _
$n20 = 0, $n21 = 0, $n22 = 1, $n23 = 0, _
$n30 = 0, $n31 = 0, $n32 = 0, $n33 = 1)

$aMatrix[0][0] = $n00
$aMatrix[0][1] = $n01
$aMatrix[0][2] = $n02
$aMatrix[0][3] = $n03

$aMatrix[1][0] = $n10
$aMatrix[1][1] = $n11
$aMatrix[1][2] = $n12
$aMatrix[1][3] = $n13

$aMatrix[2][0] = $n20
$aMatrix[2][1] = $n21
$aMatrix[2][2] = $n22
$aMatrix[2][3] = $n23

$aMatrix[3][0] = $n30
$aMatrix[3][1] = $n31
$aMatrix[3][2] = $n32
$aMatrix[3][3] = $n33

EndFunc ;==>__S3d_SetMatrix


; $aOutMatrix = $nInMatrix1 * $nInMatrix2
Func __S3d_MultiplyMatrix(ByRef $aOutMatrix, ByRef $aInMatrix1, ByRef $aInMatrix2)

Local $i, $j, $k
For $i = 0 To 3
For $j = 0 To 3
$aOutMatrix[$i][$j] = 0
For $k = 0 To 3
$aOutMatrix[$i][$j] += $aInMatrix1[$i][$k] * $aInMatrix2[$k][$j]
Next
Next
Next

EndFunc ;==>__S3d_MultiplyMatrix

; __S3d_ConvertPos - converts 3D -> 2D
Func __S3d_ConvertPos(ByRef $nOutX, ByRef $nOutY, $nInX, $nInY, $nInZ)

Local $aInPos[4] = [$nInX, $nInY, $nInZ ,1], $aOutPos[4] = [0, 0, 0, 0], $i, $j
For $i = 0 To 3
For $j = 0 To 3
$aOutPos[$i] += $__S3d_aConvertMatrix[$i][$j] * $aInPos[$j]
Next
Next

If $aOutPos[0] <= 0 Then Return SetError(1, 0, 0) ; behind the camera

$nOutX = (- $aOutPos[1] / $aOutPos[0] / $__S3d_nFAngleTan) * ($__S3d_nFScale / 2) + ($__S3d_iWidth / 2)
$nOutY = (- $aOutPos[2] / $aOutPos[0] / $__S3d_nFAngleTan) * ($__S3d_nFScale / 2) + ($__S3d_iHeight / 2)

Return 1
EndFunc ;==>__S3d_ConvertPos

Func __S3d_Deg2Rad($nDeg)
Return $nDeg / 180 * $__S3d_PI
EndFunc ;==>__S3d_Deg2Rad

Func _GDIPlus_GraphicsFillPolygonF($hGraphics, $aPoints, $hBrush = 0)
Local $iCount = $aPoints[0][0]
Local $tPoints = DllStructCreate("float[" & $iCount * 2 & "]")
For $iI = 1 To $iCount
DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
Next

__GDIPlus_BrushDefCreate($hBrush)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygon", "handle", $hGraphics, "handle", $hBrush, _
"struct*", $tPoints, "int", $iCount, "int", "FillModeAlternate")
Local $tmpError = @error, $tmpExtended = @extended
__GDIPlus_BrushDefDispose()
If $tmpError Then Return SetError($tmpError, $tmpExtended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsFillPolygon

Func _GDIPlus_GraphicsDrawPolygonF($hGraphics, $aPoints, $hPen = 0)
Local $iCount = $aPoints[0][0]
Local $tPoints = DllStructCreate("float[" & $iCount * 2 & "]")
For $iI = 1 To $iCount
DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
Next

__GDIPlus_PenDefCreate($hPen)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawPolygon", "handle", $hGraphics, "handle", $hPen, "struct*", $tPoints, "int", $iCount)
Local $tmpError = @error, $tmpExtended = @extended
__GDIPlus_PenDefDispose()
If $tmpError Then Return SetError($tmpError, $tmpExtended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsDrawPolygon

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

Enjoying this.

 

I have a question about _S3d_SetCamera()

 

I am drawing a wireframe of a mesh using a vertex list and a triangle list. ( _S3d_Line() works perfect for this. )

 

But I am having trouble positioning the camera.

_S3d_SetCamera() accepts $position_x, $position_y, $position_z and $target_x, $target_y, $target_z

Target is behaving exactly how I expect it to.

But when changing the position values, it seems to be rotating the view instead of translating.

  

Local $position_x = $Model_Width / 2
Local $position_y = $Model_Height / 2
Local $position_z = $Model_depth * 2 ; guessing
Local $target_x = 0
Local $target_y = 0
Local $target_z = 0

_S3d_SetCamera( $position_x, $position_y, $position_z, $target_x, $target_y, $target_z )
I expected this to put the camera at roughly the center of mass in the x/y plane and some amount out along the z plane, looking at the mesh's feet (which are at 0,0,0.)

Instead it is below and somewhere behind the origin.

I am assuming x is left-right, y is up-down, and z is fore-aft.

Is this correct?

And do the position values translate or rotate? Or am I missing something completely.

(attached a pic to show that it is indeed drawing.. which I find to be very cool.)

post-66299-0-22428900-1374910449_thumb.p

Share this post


Link to post
Share on other sites

I am assuming x is left-right, y is up-down, and z is fore-aft.

Is this correct?

By default, z is up-down.

 

And do the position values translate or rotate? Or am I missing something completely.

To translate the view, you need to change both Position and Target.

Example:

_S3d_SetCamera(500 + $i, 200, 300, $i, 0, 0)

Share this post


Link to post
Share on other sites

I'm glad it was just a difference of axis alignments. I can accommodate that by just switching how I load the data from the vertex list.

I started playing with the target values (instead of leaving them at 0) and the camera view began behaving as expected. Thanks for clearing that up.

I intend to use this as a wireframe preview for a little mesh editing tool. It's just enough to help identify pieces and features within the model (that's all that is needed.) Once I have a cleaner implementation of it, I'll post an example of the code that uses your functions here.

Thanks again for putting this together. I have ideas for working with 3d models, but am terrible at the math behind it.

Share this post


Link to post
Share on other sites

Thanks for using my UDF!

Example usage of _S3d_SetLocalMatrix

#include <GUIConstantsEx.au3>
#include <S3d.au3>

Main()

Func Main()
    ; Create a window and initialize GDI+
    Local $hGUI = GUICreate("S3d Example", 650, 550)
    GUISetState()
    _GDIPlus_Startup()
    
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(650, 550, $hGraphics)
    Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    Local $hFont = _GDIPlus_FontCreate($hFamily, 30, 2)
    
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xCC448844)
    
    ; Select a Graphic object
    ; width = 650, height = 550
    _S3d_SelectGraphic($hGraphic, 650, 550)
    
    ; Select brush, font, and format object
    _S3d_SelectBrush($hBrush)
    _S3d_SelectFont($hFont)
    _S3d_SelectFormat($hFormat)
    
    Local $hPenB = _GDIPlus_PenCreate(0xAA0044FF, 2)
    Local $hPenR = _GDIPlus_PenCreate(0xAAFF6633, 3)
    
    Local $i = 0
    ; Loop until user exits
    Do
        ; Clear the Graphics object
        _S3d_Clear(0xFFFFFFFF)
        
        ; Set camera
        _S3d_SetCamera(500 * Cos($i), 500 * Sin($i), 300 * Cos($i * 1.5), 0, 0, 0)
        _GDIPlus_GraphicsDrawString($hGraphic, "Camera (" & Round(500 * Cos($i)) & ", " & Round(500 * Sin($i)) & ", " & Round(300 * Cos($i * 1.5)) & ")", 20, 20)
        
        ;**************************************************
        ; _S3d_SetLocalMatrix examples
        Switch 1   ; <- change this!
            Case 0
                ; do nothing
            Case 1
                ; Y <-> Z
                _S3d_SetLocalMatrix( _
                    1, 0, 0, 0, _
                    0, 0, 1, 0, _
                    0, 1, 0, 0, _
                    0, 0, 0, 1)
            Case 2
                ; Z -> -Z
                _S3d_SetLocalMatrix( _
                    1, 0,  0, 0, _
                    0, 1,  0, 0, _
                    0, 0, -1, 0, _
                    0, 0,  0, 1)
            Case 3
                ; X -> Y, Y -> Z, Z -> X
                _S3d_SetLocalMatrix( _
                    0, 1, 0, 0, _
                    0, 0, 1, 0, _
                    1, 0, 0, 0, _
                    0, 0, 0, 1)
            Case 4
                ; rotation in XZ plane by 2 radians   This is equivalent to _S3d_LocalRotateY(2)
                _S3d_SetLocalMatrix( _
                    Cos(2),      0, -Sin(2),      0, _
                         0,      1,       0,      0, _
                    Sin(2),      0,  Cos(2),      0, _
                         0,      0,       0,      1)
            Case 5
                ; X -> X + 300    This is equivalent to _S3d_LocalTranslate(300, 0, 0)
                _S3d_SetLocalMatrix( _
                    1, 0, 0, 300, _
                    0, 1, 0,   0, _
                    0, 0, 1,   0, _
                    0, 0, 0,   1)
            Case 6
                ; Z -> -Z
                _S3d_SetLocalMatrix( _
                    1, 0,  0, 0, _
                    0, 1,  0, 0, _
                    0, 0, -1, 0, _
                    0, 0,  0, 1)
                ; and then X -> X + 300
                _S3d_MultiplyLocalMatrix( _
                    1, 0, 0, 300, _
                    0, 1, 0,   0, _
                    0, 0, 1,   0, _
                    0, 0, 0,   1)
        EndSwitch
        ;**************************************************
        
        ; Select a pen obiect
        _S3d_SelectPen($hPenB)
        ; Draw cube
        _S3d_Box(-100, -100, -100, 100, 100, 100)
        
        ; Select a pen obiect
        _S3d_SelectPen($hPenR)
        
        ; Draw an arrow from (0, 0, 0) to (200, 0, 0)
        _S3d_Arrow(0, 0, 0, 200, 0, 0)
        ; Draw a string
        _S3d_String("X", 250, 0, 0)
        
        _S3d_Arrow(0, 0, 0, 0, 200, 0)
        _S3d_String("Y", 0, 250, 0)
        
        _S3d_Arrow(0, 0, 0, 0, 0, 200)
        _S3d_String("Z", 0, 0, 250)
        
        ; Copy to the window
        _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
        
        $i += 0.04
        Sleep(30)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    
    ; Clean up resources
    
    _GDIPlus_PenDispose($hPenB)
    _GDIPlus_PenDispose($hPenR)
    _GDIPlus_BrushDispose($hBrush)
    
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    
    GUIDelete($hGUI)
EndFunc ;==>Main

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I made this FPS controller a while back, all you need to do is add a 3-D world and edit the _PlayerTransform() funtion.

; Simple FPS style control, change the _PlayerTransform() function to use it in a game.
#include <Misc.au3>

; #PUBLIC VARIABLES# ==============================================================================
; Position and rotation of the player, change it to alter the starting position.
Global $anPlayerPosition[3] = [0, 0, 0]
Global $anPlayerRotation[2] = [180, 0]

Global $aiRotationLimit[2] = [180, 180] ; Limit for rotation, can be used to constrain rotation
Global $nWalkSpeed = 0.1 ; Speed when walking (W, A, S, D)
Global $nSprintSpeed = 0.25 ; Speed when sprinting (SHIFT+W)
Global $nJumpHeight = 10 ; Height when jumping (SPACE)
Global $nJumpSpeed = 1.5
Global $nFallSpeed = 1.0
Global $nClimbSpeed = 1.0
Global $nFloorHeight = 0 ; Height of the floor, change it and the player falls/climbs
; =================================================================================================

Global $fCrouched = False, $fJumping = False, $fGoingUp = False, $fLeftMouse = False
Global $hDLL = DllOpen("user32.dll")

; _FPS_Control() should get called every frame
AdlibRegister("_FPS_Control", 1000 / 30)
HotKeySet("{ESC}", "_Exit")
HotKeySet("{F2}", "_ChangeFloorHeight")

; The main loop (GUI, GDI+, etc) goes here
While 1
    Sleep(1000)
WEnd

; This function should move the player to the mew position
Func _PlayerTransform(ByRef $anPlayerPosition, ByRef $anPlayerRotation, $fCrouched, $fJumping, $fLeftMouse, $fMiddleMouse, $fRightMouse)
    ToolTip("XYZ = " & $anPlayerPosition[0] & ", " & $anPlayerPosition[1] & ", " & $anPlayerPosition[2] & @CRLF _
             & "Rot = " & $anPlayerRotation[0] & ", " & $anPlayerRotation[1] & @CRLF _
             & "$fCrouched = " & $fCrouched & @CRLF _
             & "$fJumping = " & $fJumping & @CRLF & @CRLF _
             & "$fLeftMouse = " & $fLeftMouse & @CRLF _
             & "$fMiddleMouse = " & $fMiddleMouse & @CRLF _
             & "$fRightMouse= " & $fRightMouse, 0, 0)
EndFunc   ;==>_PlayerTransform

Func _ChangeFloorHeight()
    $sInput = InputBox("", "Input the new value for $nFloorHeight" & @CRLF & "$nFloorHeight = " & $nFloorHeight)
    If @error = 0 Then
        $nFloorHeight = Number($sInput)
    EndIf
EndFunc   ;==>_ChangeFloorHeight

Func _Exit()
    DllClose($hDLL)
    Exit
EndFunc   ;==>_Exit

Func _FPS_Control()
    If MouseGetPos(0) <= 0 Then
        MouseMove(@DesktopWidth - 2, MouseGetPos(1), 0)
    ElseIf MouseGetPos(0) >= @DesktopWidth - 1 Then
        MouseMove(0, MouseGetPos(1), 0)
    EndIf

    $anPlayerRotation[0] = (MouseGetPos(0) - (@DesktopWidth / 2)) / (@DesktopWidth / 2) * $aiRotationLimit[0] + $aiRotationLimit[0]
    $anPlayerRotation[0] = Round($anPlayerRotation[0])

    $anPlayerRotation[1] = (MouseGetPos(1) - (@DesktopHeight / 2)) / (@DesktopHeight / 2) * $aiRotationLimit[1]
    $anPlayerRotation[1] = Round($anPlayerRotation[1])

    $fLeftMouse = _IsPressed("01", $hDLL)
    $fMiddleMouse = _IsPressed("04", $hDLL)
    $fRightMouse = _IsPressed("02", $hDLL)

    If _IsPressed("57", $hDLL) Then
        If _IsPressed("10", $hDLL) Then
            $anPlayerPosition[1] += $nSprintSpeed
        Else
            $anPlayerPosition[1] += $nWalkSpeed
        EndIf
    ElseIf _IsPressed("53", $hDLL) Then
        If _IsPressed("10", $hDLL) Then
            $anPlayerPosition[1] -= $nSprintSpeed
        Else
            $anPlayerPosition[1] -= $nWalkSpeed
        EndIf
    EndIf

    If _IsPressed("41", $hDLL) Then
        If _IsPressed("10", $hDLL) Then
            $anPlayerPosition[0] -= $nSprintSpeed
        Else
            $anPlayerPosition[0] -= $nWalkSpeed
        EndIf
    EndIf
    If _IsPressed("44", $hDLL) Then
        If _IsPressed("10", $hDLL) Then
            $anPlayerPosition[0] += $nSprintSpeed
        Else
            $anPlayerPosition[0] += $nWalkSpeed
        EndIf
    EndIf

    If _GetButtonUp("11", $hDLL) Then
        If $fCrouched Then
            $anPlayerPosition[2] = $nFloorHeight
        Else
            $anPlayerPosition[2] = $nFloorHeight - 5
        EndIf
        $fCrouched = Not $fCrouched
        $fJumping = False
    ElseIf $fJumping = False And _GetButtonUp("20", $hDLL) Then
        $fJumping = True
        $fGoingUp = True
    EndIf
    If $fJumping Then
        If $fGoingUp Then
            $anPlayerPosition[2] += $nJumpSpeed
        Else
            $anPlayerPosition[2] -= $nFallSpeed
        EndIf
        If $anPlayerPosition[2] >= $nFloorHeight + $nJumpHeight Then
            $fGoingUp = False
        EndIf
        If $fGoingUp = False Then
            If ($fCrouched And $anPlayerPosition[2] <= $nFloorHeight - 5) Or (Not $fCrouched And $anPlayerPosition[2] <= $nFloorHeight) Then
                $fJumping = False
            EndIf
        EndIf
    Else
        If ($fCrouched And $anPlayerPosition[2] < $nFloorHeight - 5) Or (Not $fCrouched And $anPlayerPosition[2] < $nFloorHeight) Then
            $anPlayerPosition[2] += $nClimbSpeed
        ElseIf ($fCrouched And $anPlayerPosition[2] > $nFloorHeight - 5) Or (Not $fCrouched And $anPlayerPosition[2] > $nFloorHeight) Then
            $anPlayerPosition[2] -= $nFallSpeed
        EndIf
        If $anPlayerPosition[2] <> $nFloorHeight And _IsBetween($anPlayerPosition[2], $nFloorHeight - $nFallSpeed, $nFloorHeight + $nClimbSpeed) Then
            If $fCrouched Then
                $anPlayerPosition[2] = $nFloorHeight - 5
            Else
                $anPlayerPosition[2] = $nFloorHeight
            EndIf
        EndIf
    EndIf

    ; Round the XYZ pos
    For $x = 0 To 2
        $anPlayerPosition[$x] = Round($anPlayerPosition[$x], 5)
    Next

    ; Call the tramsforming function
    _PlayerTransform($anPlayerPosition, $anPlayerRotation, $fCrouched, $fJumping, $fLeftMouse, $fMiddleMouse, $fRightMouse)
EndFunc   ;==>_FPS_Control

Func _IsBetween($iNumber, $iLowNum, $iHighNum)
    Return $iNumber >= $iLowNum And $iNumber <= $iHighNum
EndFunc   ;==>_IsBetween

Func _GetButtonUp($sHexKey, $vDLL)
    If _IsPressed($sHexKey, $vDLL) Then
        While _IsPressed($sHexKey, $vDLL)
            Sleep(10)
        WEnd
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_GetButtonUp
Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

UPDATE

New version (v1.1.2) released! Please see the first post.

  • _S3d_Arrow and _S3d_Square now work even if some of the points (one for _S3d_Arrow, up to three for _S3d_Square) are behind the camera.

If you have written some example scripts that use S3d.au3, feel free to post them here.

Edited by Starg

Share this post


Link to post
Share on other sites

Very nice work. thank you.

regards

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

UPDATE

New version (v1.1.2) released! Please see the first post.

  • _S3d_Arrow and _S3d_Square now work even if some of the points is behind the camera.

If you have written some example scripts that use S3d.au3, feel free to post them here.

 

Could you add an array that stores all the drawn objects so when I call _S3d_SetCamera() it redraws all the objects

Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Share this post


Link to post
Share on other sites

Could you add an array that stores all the drawn objects so when I call _S3d_SetCamera() it redraws all the objects

Thanks for the suggestion. I think making a wrapper for it is better than changing S3d itself.

Share this post


Link to post
Share on other sites

You can make the help file >by means of it

Thanks. I'll try it.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

This might help:

'?do=embed' frameborder='0' data-embedContent>>

Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

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

  • Similar Content

    • UEZ
      By UEZ
      Nothing special - just another analogue clock.  -> Read https://en.wikipedia.org/wiki/Swiss_railway_clock for more information.

       
      ;the Hilfiker / MobaTime Swiss Railway Clock ;coded by UEZ build 2018-02-16 ;thanks to Eukalyptus for the _CreateBrushedAluminum() function! #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #AutoIt3Wrapper_UseX64=n #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit Global Const $iW = 500, $iH = $iW, $iWh = $iW / 2, $iHh = $iH / 2, $sTitle = "GDI+ Swiss Railway Clock v1.1" Global Const $fRad = ACos(-1) / 180, $fDeg = 180 / ACos(-1), $iTimer = 30 Global $fMin_next, $hDC, $hCanvas, $hBitmap_Clock, $fDiameter, $hDC_backbuffer, $fShadowAngle AutoItSetOption("GUIOnEventMode", 1) GDIPlus_SwissRailwayClock() AutoItSetOption("GUIOnEventMode", 0) _GDIPlus_Shutdown() Func GDIPlus_SwissRailwayClock() $bExit = False $hGUI = GUICreate($sTitle, $iW, $iH, -1, -1, -1, $WS_EX_TOPMOST) GUISetBkColor(0xFFFFFF, $hGUI) GUISetState(@SW_SHOW, $hGUI) ;~ GUISetCursor(16, 1) ;create canvas elements $hDC = _WinAPI_GetDC($hGUI) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local Const $hBrush_Clr = _GDIPlus_BrushCreateSolid(0xFF000000), _ $hBrush_FPS = _GDIPlus_BrushCreateSolid(0xF0808080), _ $hFormat_FPS = _GDIPlus_StringFormatCreate(), _ $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial"), _ $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 8), _ $tLayout_FPS = _GDIPlus_RectFCreate(0, 0, 60, 16) $fDiameter = $iW $hBitmap_Clock = GenerateClockBg($fDiameter) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") $fMin_next = @MIN GUIRegisterMsg($WM_TIMER, "Draw") ;$WM_TIMER = 0x0113 DllCall("User32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iTimer, "int", 0) Do If $bExit Then ExitLoop Until Not Sleep(100) ;release resources GUIRegisterMsg($WM_TIMER, "") _GDIPlus_FontDispose($hFont_FPS) _GDIPlus_FontFamilyDispose($hFamily_FPS) _GDIPlus_StringFormatDispose($hFormat_FPS) _GDIPlus_BrushDispose($hBrush_Clr) _GDIPlus_BrushDispose($hBrush_FPS) _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($hGUI, $hDC) GUIDelete($hGUI) EndFunc ;==>GDIPlus_SwissRailwayClock Func Draw() _GDIPlus_GraphicsDrawImageRect($hCanvas, $hBitmap_Clock, 0, 0, $fDiameter, $fDiameter) UpdateClock($hCanvas, $fDiameter) _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY) EndFunc Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func UpdateClock($hGfx, $fDiameter) Local Const $fRadius = $fDiameter / 2, $hBrush_Shadow = _GDIPlus_BrushCreateSolid(0x18A8A8A8) Local $fSec, $fMin, $fHr Static $bBounce = 0, $f = 0, $fAmplitude = 3 Local $m1 = $fDiameter * 0.015 ;hour $fHr = 30 * (@HOUR + @MIN / 60) _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, $fHr) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xFF101010) Local $iWidth1 = $fDiameter * 0.0375, _ $iHeight1 = $fDiameter / 2.5, _ $iWidth12 = $iWidth1 / 2, _ $fPosY = $fDiameter * 0.2, $iWidth2, $iWidth22, $fPosY2 DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hGfx, "handle", $hBrush_Shadow, _ "float", $fRadius - $iWidth12 + Cos(($fShadowAngle - $fHr) * $fRad) * $m1, _ "float", $fPosY + Sin(($fShadowAngle - $fHr) * $fRad) * $m1, _ "float", $iWidth1, "float", $iHeight1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hGfx, "handle", $hBrush, _ "float", $fRadius - $iWidth12, _ "float", $fPosY, _ "float", $iWidth1, "float", $iHeight1) _GDIPlus_GraphicsResetTransform($hGfx) ;min If $fMin_next <> @MIN Then $bBounce = 1 Switch $bBounce Case 1 $fMin = (6 * Mod(($fMin_next + 1), 60)) + Sin($f * 1.9) * $fAmplitude If $fAmplitude = 0 Then $fMin_next = @MIN $f = 0 $fAmplitude = 3 $bBounce = 0 Else $fAmplitude -= 0.5 $fAmplitude = $fAmplitude <= 0 ? 0 : $fAmplitude $f += 1 EndIf Case Else $fMin = (6 * @MIN) EndSwitch _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, $fMin) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) $iWidth1 = $fDiameter * 0.03 $iHeight1 = $fRadius $iWidth12 = $iWidth1 / 2 $fPosY = $fDiameter * 0.1 DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hGfx, "handle", $hBrush_Shadow, _ "float", $fRadius - $iWidth12 + Cos(($fShadowAngle - $fMin) * $fRad) * $m1, _ "float", $fPosY + Sin(($fShadowAngle - $fMin) * $fRad) * $m1, _ "float", $iWidth1, "float", $iHeight1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hGfx, "handle", $hBrush, _ "float", $fRadius - $iWidth12, _ "float", $fPosY, _ "float", $iWidth1, "float", $iHeight1) _GDIPlus_GraphicsResetTransform($hGfx) ;sec $fSec = 6 * (@SEC * 1.02564 + @MSEC / 1000) If $fSec >= 360 Then $fSec = 0 _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, $fSec) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) $fPosY = $fDiameter * 0.27 $fPosY2 = $fDiameter * 0.19 $iWidth1 = $fDiameter * 0.0095 $iHeight1 = $fRadius * 1.3 - $fPosY $iWidth12 = $iWidth1 / 2 $iWidth2 = $fDiameter * 0.083333 $iWidth22 = $iWidth2 / 2 ;shadow seconds DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hGfx, "handle", $hBrush_Shadow, _ "float", $fRadius + Cos(($fShadowAngle - $fSec) * $fRad) * $m1, _ "float", $fPosY + Sin(($fShadowAngle - $fSec) * $fRad) * $m1, _ "float", $iWidth1 + $fDiameter * 0.006667, "float", $iHeight1 + $fDiameter * 0.006667) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hGfx, "handle", $hBrush_Shadow, _ "float", $fRadius - $iWidth22 + Cos(($fShadowAngle - $fSec) * $fRad) * $m1, _ "float", $fPosY2 + Sin(($fShadowAngle - $fSec) * $fRad) * $m1, _ "float", $iWidth2, "float", $iWidth2) ;seconds _GDIPlus_BrushSetSolidColor($hBrush, 0xF8C01010) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hGfx, "handle", $hBrush, _ "float", $fRadius - $iWidth12, _ "float", $fPosY, _ "float", $iWidth1, "float", $iHeight1) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hGfx, "handle", $hBrush, _ "float", $fRadius - $iWidth22, _ "float", $fPosY2, _ "float", $iWidth2, "float", $iWidth2) _GDIPlus_GraphicsResetTransform($hGfx) Local Const $hPen = _GDIPlus_PenCreate(0xFFA02020) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hGfx, "handle", $hBrush, _ "float", $fRadius - $iWidth1, _ "float", $fRadius - $iWidth1, _ "float", 2 * $iWidth1, "float", 2 * $iWidth1) DllCall($__g_hGDIPDll, "int", "GdipDrawEllipse", "handle", $hGfx, "handle", $hPen, _ "float", $fRadius - $iWidth1, _ "float", $fRadius - $iWidth1, _ "float", 2 * $iWidth1, "float", 2 * $iWidth1) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrush_Shadow) EndFunc Func GenerateClockBg($fDiameter) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($fDiameter, $fDiameter), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap), _ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000), $hPen = _GDIPlus_PenCreate(0xFF000000), _ $hEffect = _GDIPlus_EffectCreateBlur(10.5, 0), $fBorderSize = $fDiameter * 0.03333 _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4) _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 4) _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 4) _GDIPlus_GraphicsClear($hGfx, 0xFFFFFFFF) _GDIPlus_PenSetColor($hPen, 0xA0000000) _GDIPlus_PenSetWidth($hPen, $fBorderSize) Local Const $fSize = $fDiameter * 0.95 - $fBorderSize / 2, $fRadius = $fDiameter / 2 Local $fShadow_vx = $fDiameter * 0.0095, $fShadow_vy = $fDiameter * 0.01 $fShadowAngle = ATan($fShadow_vy / $fShadow_vx) * $fDeg If $fShadow_vx < 0 And $fShadow_vy >= 0 Then $fShadowAngle += 180 If $fShadow_vx < 0 And $fShadow_vy < 0 Then $fShadowAngle -= 180 _GDIPlus_GraphicsDrawEllipse($hGfx, $fBorderSize + $fShadow_vx, $fBorderSize + $fShadow_vy, $fSize, $fSize, $hPen) _GDIPlus_BitmapApplyEffect($hBitmap, $hEffect) _GDIPlus_PenSetColor($hPen, 0xF0000000) Local Const $hBitmap_Texture = _CreateBrushedAluminum($fDiameter, $fDiameter, $fShadowAngle) Local Const $hTexture = _GDIPlus_TextureCreate($hBitmap_Texture) DllCall($__g_hGDIPDll, "int", "GdipSetPenBrushFill", "ptr", $hPen, "ptr", $hTexture) _GDIPlus_GraphicsDrawEllipse($hGfx, $fBorderSize, $fBorderSize, $fSize, $fSize, $hPen) _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, -6) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) Local $iWidth1 = $fDiameter * 0.026667, $iHeight1 = $fDiameter / 10, $iWidth12 = $iWidth1 / 2, $fPosY = $fDiameter * 0.083333, _ $iWidth2 = $fDiameter * 0.013333, $iHeight2 = $fDiameter * 0.0416667, $iWidth22 = $iWidth2 / 2 For $i = 0 to 59 _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, 6) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) Switch Mod($i, 5) Case 0 _GDIPlus_GraphicsFillRect($hGfx, $fRadius - $iWidth12, $fPosY, $iWidth1, $iHeight1, $hBrush) Case Else _GDIPlus_GraphicsFillRect($hGfx, $fRadius - $iWidth22, $fPosY, $iWidth2, $iHeight2, $hBrush) EndSwitch Next _GDIPlus_GraphicsResetTransform($hGfx) Local Const $hBitmap_Logo = _GDIPlus_BitmapCreateFromMemory(_Au3_Icon()) Local Const $hBitmap_Logo_Scaled = _GDIPlus_ImageResize($hBitmap_Logo, $fDiameter * 0.08, $fDiameter * 0.08) Local $aDim = _GDIPlus_ImageGetDimension($hBitmap_Logo_Scaled) _GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap_Logo_Scaled, $fRadius - $aDim[0] / 2, $fRadius / 1.75, $aDim[0], $aDim[1]) _GDIPlus_ImageDispose($hBitmap_Logo) _GDIPlus_ImageDispose($hBitmap_Logo_Scaled) Local Const $hFamily = _GDIPlus_FontFamilyCreate("Segoe Script"), $hFont = _GDIPlus_FontCreate($hFamily, $fDiameter * 0.025), $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ;~ _GDIPlus_BrushSetSolidColor($hBrush, 0xFF400000) _GDIPlus_GraphicsDrawStringEx($hGfx, "Clock by" & @CRLF & "UEZ", $hFont, _GDIPlus_RectFCreate($fRadius - $fRadius * 0.2, $fRadius + $fRadius * 0.2, $fRadius * 0.4, $fRadius * 0.4), $hFormat, $hBrush) _GDIPlus_ImageDispose($hBitmap_Texture) _GDIPlus_BrushDispose($hTexture) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_EffectDispose($hEffect) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGfx) Return $hBitmap EndFunc Func _CreateBrushedAluminum($iW, $iH, $fLightAngle = 40, $iBlurDist = 12, $fBlurTrans = 0.6666, $fRed = 0.8, $fGreen = 0.9, $fBlue = 1, $iLightColor = 0xF0FFFFFF, $fLightSigma = 0.5, $fLightScale = 0.83) ;coded by Eukalyptus! $iBlurDist = Ceiling($iBlurDist) $iBlurDist += 1 - Mod($iBlurDist, 2) Local $iOverSize = 0 For $i = 1 To $iBlurDist Step 2 $iOverSize += $i + $i + 1 Next Local $iWO = $iW + $iOverSize ;========================================= ; Add Noise ;========================================= Local $iNoiseSize = 40 Local $hBmp_Noise = _GDIPlus_BitmapCreateFromScan0($iNoiseSize, $iNoiseSize) Local $hGfx_Noise = _GDIPlus_ImageGetGraphicsContext($hBmp_Noise) Local $tData = _GDIPlus_BitmapLockBits($hBmp_Noise, 0, 0, $iNoiseSize, $iNoiseSize, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB) Local $iStride = DllStructGetData($tData, "Stride") Local $iWidth = DllStructGetData($tData, "Width") Local $iHeight = DllStructGetData($tData, "Height") Local $pScan0 = DllStructGetData($tData, "Scan0") Local $tPixel = DllStructCreate("dword[" & $iWidth * $iHeight & "];", $pScan0) Local $iAmp For $row = 0 To $iHeight - 1 For $col = 0 To $iWidth - 1 $iAmp = Random(0, 0xFF, 1) DllStructSetData($tPixel, 1, BitOR(0xFF000000, BitShift($iAmp, -16), BitShift($iAmp, -8), $iAmp), $row * $iWidth + $col + 1) Next Next _GDIPlus_BitmapUnlockBits($hBmp_Noise, $tData) ;========================================= ; Create Full NoiseBitmap ;========================================= Local $hBmp_Full = _GDIPlus_BitmapCreateFromScan0($iWO, $iH) Local $hGfx_Full = _GDIPlus_ImageGetGraphicsContext($hBmp_Full) _GDIPlus_GraphicsSetSmoothingMode($hGfx_Full, 4) _GDIPlus_GraphicsSetInterpolationMode($hGfx_Full, 3) Local $iXOff, $iYOff, $iSizeX, $iSizeY For $y = 0 To $iH Step $iNoiseSize / 2 For $x = 0 To $iWO Step $iNoiseSize / 2 $iXOff = Random(0, $iNoiseSize / 2, 1) $iYOff = Random(0, $iNoiseSize / 2, 1) $iSizeX = $iNoiseSize - $iXOff $iSizeY = $iNoiseSize - $iYOff _GDIPlus_GraphicsDrawImageRectRect($hGfx_Full, $hBmp_Noise, $iXOff, $iYOff, $iSizeX, $iSizeY, $x, $y, $iSizeX, $iSizeY) Next Next _GDIPlus_GraphicsDispose($hGfx_Noise) _GDIPlus_BitmapDispose($hBmp_Noise) ;========================================= ; MotionBlur ;========================================= Local $hBmp_Full2 = _GDIPlus_BitmapCreateFromScan0($iWO, $iH) Local $hGfx_Full2 = _GDIPlus_ImageGetGraphicsContext($hBmp_Full2) _GDIPlus_GraphicsSetSmoothingMode($hGfx_Full2, 4) _GDIPlus_GraphicsSetInterpolationMode($hGfx_Full, 3) Local $tColorMatrix = DllStructCreate("float[5]; float[5]; float[5]; float[5]; float[5];") DllStructSetData($tColorMatrix, 1, 1, 1) DllStructSetData($tColorMatrix, 2, 1, 2) DllStructSetData($tColorMatrix, 3, 1, 3) DllStructSetData($tColorMatrix, 4, $fBlurTrans, 4) DllStructSetData($tColorMatrix, 5, 1, 5) Local $hImgAttrib = _GDIPlus_ImageAttributesCreate() DllCall($__g_hGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr", $hImgAttrib, "int", 1, "int", 1, "struct*", $tColorMatrix, "struct*", 0, "int", 0) For $i = 1 To $iBlurDist Step 2 DllCall($__g_hGDIPDll, "int", "GdipDrawImageRectRect", "ptr", $hGfx_Full2, "ptr", $hBmp_Full, _ "float", $i, "float", 0, "float", $iWO, "float", $iH, _ "float", 0, "float", 0, "float", $iWO, "float", $iH, _ "int", 2, "ptr", $hImgAttrib, "ptr", 0, "ptr", 0) If $i >= $iBlurDist Then DllStructSetData($tColorMatrix, 1, $fRed, 1) DllStructSetData($tColorMatrix, 2, $fGreen, 2) DllStructSetData($tColorMatrix, 3, $fBlue, 3) DllStructSetData($tColorMatrix, 4, 1, 4) DllCall($__g_hGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr", $hImgAttrib, "int", 1, "int", 1, "struct*", $tColorMatrix, "struct*", 0, "int", 0) EndIf DllCall($__g_hGDIPDll, "int", "GdipDrawImageRectRect", "ptr", $hGfx_Full, "ptr", $hBmp_Full2, _ "float", $i + 1, "float", 0, "float", $iWO, "float", $iH, _ "float", 0, "float", 0, "float", $iWO, "float", $iH, _ "int", 2, "ptr", $hImgAttrib, "ptr", 0, "ptr", 0) Next _GDIPlus_ImageAttributesDispose($hImgAttrib) _GDIPlus_GraphicsDispose($hGfx_Full2) _GDIPlus_BitmapDispose($hBmp_Full2) _GDIPlus_GraphicsDispose($hGfx_Full) ;========================================= ; Add Light ;========================================= Local $hBmp_Alu = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local $hGfx_Alu = _GDIPlus_ImageGetGraphicsContext($hBmp_Alu) _GDIPlus_GraphicsSetSmoothingMode($hGfx_Alu, 4) _GDIPlus_GraphicsSetInterpolationMode($hGfx_Full, 3) _GDIPlus_GraphicsDrawImage($hGfx_Alu, $hBmp_Full, -$iOverSize, 0) _GDIPlus_BitmapDispose($hBmp_Full) Local $tPointF1 = DllStructCreate("float; float;") Local $tPointF2 = DllStructCreate("float; float;") DllStructSetData($tPointF2, 2, $iH * $fLightScale) $aResult = DllCall($__g_hGDIPDll, "int", "GdipCreateLineBrush", "struct*", $tPointF1, "struct*", $tPointF2, "uint", 0, "uint", $iLightColor, "int", 0, "handle*", 0) If @error Or Not IsArray($aResult) Then Return SetError(1, 4, False) Local $hBrush = $aResult[6] _GDIPlus_LineBrushSetSigmaBlend($hBrush, $fLightSigma) _GDIPlus_LineBrushSetGammaCorrection($hBrush) DllCall($__g_hGDIPDll, "int", "GdipRotateLineTransform", "ptr", $hBrush, "float", $fLightAngle, "int", 0) _GDIPlus_GraphicsFillRect($hGfx_Alu, 0, 0, $iW, $iH, $hBrush) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGfx_Alu) Return $hBmp_Alu EndFunc ;==>_CreateBrushedAluminum ;Code below was generated by: 'File to Base64 String' Code Generator v1.20 Build 2018-02-02 Func _Au3_Icon($bSaveBinary = False, $sSavePath = @ScriptDir) Local $Au3_Icon $Au3_Icon &= 'iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAP0ElEQVR4XtWZW4hs6VXHf+v79qWquruquqtvZ/r0uc8540yScTIQQ0JkDOYyGhIkhhAxxhdR8mDAgAg+6FsE9UVffNMH8S0ERAwS1DFeEo3m6owzmUySc+Zc+15VXZd9+dZyp6ro4pDTORlGIfnDn703TW/+//X9v/Wt3i3PPfccP85w/GhBgLqkS23ixhpRfau6bgItIPpRN5Ag0Xl88jYrxu/E+KA492E0vJd44d245BKQ/H8bkAe80wMOEE5HA5c8SpQ822yv/ubW9vnfffyxR3+vs7r6YcS9HewZnP9ZXPwE0Py/NuCBJj65iERvQPybcNFP4JKzuPgq+CeR6GnwV3FJB4juM+mSNj55Ehe97/LFC5947PL2ey5tb755daW1+fiVc295+qk3fuTShfPPPnb10d+J60sfI6o9BbRer4EIaOLis1Nh6dtBfs6ljY82ljqfiNLFX8X597uk/ksrG4/8ftJo/lq62P51XPQOJHoc3DV8egZYxLkLcW3xQ088fvWTj2ysXItjnxRlGY6Ojmxvb98iJwtnz6xeXO80tx+9tP0Rcf6tuHhzLuS1YwmJLiHuslRVbzQbjydJsrXSbl4RIVlpLZ0xM71+e+cbC41a+8zayuVxlo9CCPnX/vslt7S89iEzy4/7R/+MT7+Lhq2V5dbbO63Ftbwog/feDYdDt7e3R71eo9vt2tbWlkZRRC1NFkHWQDpACmQ/bBuVWUyaiN+Kk9oH2q3mO/Ky0HNn1p9sNxeaBpiBmpl3TlTNqouoqkmFoKp5XuT1NKlVFS5ffOXm54ui2EFIr17afudCLV1SM5mBity+fRuAzc1NVC1EkfN3dg+/9e1vf/ePMfssYXz9hzXQJKo/BTyKlovrZ7Y+fPXi1luryubOOeKqPBpKQiilLAMhBAwEw7x3RN9jFImPIhTR8TjPQghFvZY2s7wYpkmc' $Au3_Icon &= 'Ag5ARFBVuXHjBpVPqurTaDRMVRERQgjll776wp9YKP+KMP5a9NCsS7SBuHMgb2stt9+13FraXltubYegmkRRMh4POTwccdAbMy4CQTFDBBEDABMvYmnirNVIaC3UpVFP667WqFdmrRLfYA7MDIBWq0WaplQRIo5j8d6bVvDOxbV6fXV03C0BeYgBvyxx7R1prfbs2srym8+e6bxhtrwMjnt276Bv3UGOuYQ4bVCrJ1JVWtxEvxO0xBHIiiBVpbnbLexetysLidjmygKLCwsYzjATwACpQK/XY2VlBTNjZ2cHVTXvvYkgg3F2lI2z2+ByIEScjgRx23GSPvPU41d+BQE1zMqCnb197h2NxCeLttBeliiOmCUGDIIJFgIbzYh2IyUoqBrHo0LuHQ4ozMl37g1sqTaUrdWWJbW6haAChnOOPM/Z3d1lNBpRVX/CEJTIOxkOs2Mt8z4iAHa6ARdvVnzL+a3NnzfMVNEyz/z1Wzt2XHgWW+tUwkUV8tKYlQ81IZLA9nJMI40IaohAFAnLSxHeSm7sDWi0VuR4cMxLN/fl0maLxsICqlRUVldXOTg4IEkSOp2OVUAE1Iz+YLSHyAAYndZGE1yyAXqt1Wq/b3Vl6WxQC/lo4F5+dccK15Dmchs1yEpAHCAwEe+IKbm8GhN5T6mKEwGmwgAWFxdYHo7Y6fdoLDUZDz0vvnrI1S1lYXEJnRmuhANYBalozolT1dDt97+Chq+j+f6DDUh0Bh8/k9br7754buOng5oW2ci9fGNHxtRoLrbIgwEecw5sasAQRAPnVx3eC0UIE/FmxhxgwMZqm1G+T/d4SL3eoAzKizcPefycUG8soqqEEAxMzFARIcvL8fWbO18YH/c+DfICcPwgA4JZa2lp6b3XLp39kK8QQtBbd/ZlUIgttJakNFA8OIeZQ5hVPyhnm0Y9dpTBEMDMeBBMPGc6i/RvdRnnCVWTIMvHfPPWEU+c97iohpmad47jcda/u3Pw/MHh' $Au3_Icon &= '0b+Zll8GfREtd08bJSJ81DgeDO6WQYOBHh3uy04/M5c0RCaxEBSHmsNMUKBUo5Uo6w0hVwEzToOZQcW01uCR5ZQym2zqSRcbZyW39gdgATPEgLu7hy/v7+3+jWn5GUz/Hi1vAPagUaKGS65geqndbD2ZJnE8Hh3bzb0BuFgkignq0FnmMWaCIHElFzuO0jwOQ+bR+YFGaomHMJyumIvAp1RdirVmnaRWMxGcqwi2i9mrhGyHOe43gEQrLq698+wj6x9f77SvWYVefyjjgOBjwKMiGG4uXsBZydU1jyGoKhpK8iLHe08cJ4gID4aAAhZQA8GBj7Gi4Ob+gMuPREBCGUKJWQNYBASw08bpBbDVtZXWNQPLs6FVvV6QyHAROmuRChigCGjg0rIjdTqpYlHk3L5zl2rO4Tu39iZmDDCzCZnfT4gTmL8PnAMXczTIyPOAqlk1JJ73Sf2NOH9pZoIHGYiApXqjcQVMMXQ8GssoV8NFgngMhyLA1IgLGRfa0K4beZCJ2J3dXfa7Q6I4pV9E3D0YYmV2f/7n90RRTC1yWChQExAPPsJUORzkTjVYNaVuXLm0/UHEXcDXaqcZSBBZi6NoAwRMGWUlhkzE4zwgqBoGYIGzLWG1rmQlOIHjfo+j45z11RUKE6ivcHsYca+bI9j0d21OMMR5Uq9okaEA4k5YGTBMKVV1MBwfYhpVbJy+AuKaYJEZqAbpjQoQx5yCMTspG8ZG05Opm4kL9IYZucJOd0AZL4G4yQgQxTXAMO6PkAF5NqY/KjAXA8LcgGecl6JBEcH1+sd3QFpA68EGosbC7IfxNNqlZaWdCAem92Y0IuXiMuQB5EQUdNotttY7bK52OL+6yLWO8pObsLboCMr3nws2NZAFAZ8whZwY0aAoAoY16rVVIIAVD+5CpklVqcvVmHwFM1TVBTU5GRNwiBnLDcfVjpIHB6bMAbVaQqNeQ8RQVcBRmCGnHWYYWZ5jEoGraDoTP6WpEYKK91YV' $Au3_Icon &= 'pX1ld+/Ah6zonxYhFCsXGumqqk2fDDspCkanIVxbKRkHh6l+X09XNcoQKEolmKAnwgUDzO7fyKZKVgTwMYh7gEFsQtNw697BC6HIR4ic0oUEESQKqkFEHCYmjpMe5zAudCLGFoHp97dDQEQwZmbKchqPYZ9B/4DxoIdqeSJezQhlwTAvwaecQDiBiMwe8cvtxS0fpxfAWoB7QIQoQlm8/NIrNz9z7fLZ94vzSeycZaWJYDzxSB1MmW2q+0TrieAReZ6RF4FRHhgXSqEQJkl0PLadkiR+ZkIIoWCUGdRjmB/rJxQRvBfMQIwESEGSmQG930AY7+HS5/N8fCXPy6KeuiSNnR2Pc1mqJ5ONOywU78BsLjwfjRj0e5NO0s+UIH5aUV+HKJlm21fUkkwhwVAzBCiLgmCAiwG7n6b4yIub6VcsA7uO6Q4QHjRKFGg5rObzs/VasmiqZZr4qJrd7bGtBcnyAifzHIeg9LoH7B70GWoEyRIsLEzFu1nnMuaVRRjmBUupYgrihLIsURyIZ155nVIDjSRR50Sq9tx7+ZXrf46Gf8TKm4CdMguJz4uil+fFKIp80lxo2NZ6g+oZVQXmq9w9OuDmzhFaW4HFzrTSGNicU9hJsPMAmAIOwyjLAM7PzOr9xGgvpZhBvz/aE/HerMiA0WldSIGeqXZFJC6Dulq9ThmChBAwM0wVMxgOj7m730NrHVhYB+fAwikjtIAACGqAKjp7V1AD8QD3VZ5Q4H1kywux5EXQ732Ra7eab0I1AO40AyCupxpe2T/qf9P7yMTUiqKwk9YnMhnWDg+PyKUOjc682gg/EMJ8jzKFqoG4k8xjYUot6LQagikGriyDdnv9zyNyBJSnG9C8b0X2D3mpN9MkcveJB1SV7tE+B4MwFY8ADxEv833pBEwAM8bjMaNxBshcvJYQcpyPbKtTpyjNIufk7l73q1qMvoiVuwCnGRAgixvNKxe21t+VZVlpZq6izA4pBsd9dg5HkDZn' $Au3_Icon &= 'J2eYb9RTMPdn1GLBcJhN33WUCcQNCMWEUwMF2+st0RCsAkf94W7/ePAVzO4Ag1MNzNDcPrP+B2aBEALARLzBJDp7B10CHnwCIQct59l/iAlBaUSgBoJRBp2KdxHo7F3FiFaraZ0Fb3kRDCyr/pz8pyIbfRa4B+hpBhLAti9cfmahnjyd53kBRFYBwFSt1+vZOC8hSkHnFZsygCmg87zcvwSIMR2bDcyUrFSAaSFCCeWIWr1hV9YbMspKjSPnrt/e/fdsNPg7TL9xWnyYn2qkYL/ovVPVWVLNBGA4HNLrDzmz1rbVVsMIGRVtugoFWDE3MjMzp4HmRGSIQBXNybfOLC/BbGqgGFq93uCJc21GeaFR5P0oK3pl0Bugz6P57R+U0wgoN7fO/8Zyq/nRooJhEYZUsLIsqDqA1Bs1lpotW9IgiXfcORqJlSNwCfgIxE84H78FYHofCupRCfjJp8K9wz4BD24SQVtpt+XiRsOqTY2A6/aGt1+9c+8vLBSfI4RXgIzTQQSki43axzHVEILI/Eua9fsDd9TtXd/c2Iy9d49kQfP2YhotNWJ5dW/EMJusguBicBMTcwPCFKqYQCgDg1FGXhqIWpQmnD/Tpplig9EYAesNsnu37tz7S9Pw14Tsf4AeD0F0/tLlReekphoEEDAB0SzL5ODoqI/qn+0e9ZezUp9dbjbOJ/W0aRAurNUlK+vubndsw6zAilwQARy4+SqIlZShIGt2LIQgca1h651l1tt1iqKQ42EIceTdzn7v+b39/U+L889j4VtT8Q+HfOUbL3zq7Ob6J800VlWbfR3W3b193z06/EPEfwoXP+ai+BdWO+0PFEXIq/3wBjAwVGazd29U0q+YFYGghjFF7KDmApVGGQ2PbWOtI1WzIC8Vg1Bp94fdwau37+78KdhzaHgFLbpA4OEgwmzNmPR8RCZDVuj2elG3e/S5NIn/KMuLQyR+Ucv80zs7ey+BbVVinIjUVpcXL816O82613Zd' $Au3_Icon &= 'gMTEOQcCqIo4RlkpVRu2Uk129w8DneWxeO9v3N79l+pCnuVfxvRfCdkLwIDXAPnSf33tU+fOnvktEXNFUUi1af3e3sHXNRQfA746P0+p4eJlxJ9D5I3OR09fPnfml6vD5m6rubCdRC4FAUDNdDTOe977ej2NUjOjdzxgNBwVh73h3/ooGXrvk2w8esE0PI9Nus11oM9rhHzhi//xtpXV1c+msW92uz0ODw6fA/1t4Es8GDEu3kDcFRclP6Ua2nGcbMdxvI4hzossLdQvAeRFeS/Liv00jddUtej2Bs9pKP4TDYdgOdBD3C4h2wcCrx1M/8kn7j2Y/gxwM03Tz2RZdouHo4GLOuA2EGliNBGpY3qM8+uAoeV3MBvjXBucTJ5dfIcwGgIGlIDxOjAx8DrhgQioEdUjxCmmEQDlaDATGTPF+JRKv24Dbp71GX9M8L84Jo46QVTs6gAAAABJRU5ErkJggg==' Local $bString = _WinAPI_Base64Decode($Au3_Icon) If @error Then Return SetError(1, 0, 0) $bString = Binary($bString) If $bSaveBinary Then Local Const $hFile = FileOpen($sSavePath & "\au3-icon2.png", 18) If @error Then Return SetError(2, 0, $bString) FileWrite($hFile, $bString) FileClose($hFile) EndIf Return $bString EndFunc ;==>_Au3_Icon Func _WinAPI_Base64Decode($sB64String) Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "") Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]") $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "") Return DllStructGetData($bBuffer, 1) EndFunc ;==>_WinAPI_Base64Decode  
      If you want to run in x64 mode please use AutoIt version 3.3.14.3 since the bug in function _GDIPlus_EffectCreate() has been fixed!
    • Blaxxun
      By Blaxxun
      #include <GDIPlus.au3> Text2PNG(@DesktopDir & "\MyPNG.png", 0x00FFFFFF) ; Transparent but bold ugly text ;Text2PNG(@DesktopDir & "\MyPNG.png", 0xFFFFFFFF) ; Nice Text but not transparent Func Text2PNG($sFile, $iColor) _GDIPlus_Startup() Local $hImage = _GDIPlus_BitmapCreateFromScan0(50, 25) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsClear($hGraphics, $iColor) _GDIPlus_GraphicsDrawString($hGraphics, "Hello", 0, 0, "Arial", 12, 0) _GDIPlus_ImageSaveToFile($hImage, $sFile) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>Text2PNG  
      Hello ladys and gentlemen,
      I have this piece of code and it does what it's supposed to do.
      I want to use it to create an image sequence with frame/image information for compositing overlay.
      However, when i use a transparent background the text starts to look kinda bold or fat.
      I dont know what causes this ugly effect.
      Is there a way to avoid this effect somehow?
      Thanks!
       
       
    • UEZ
      By UEZ
      I saw this code here: http://zoomquilt.org/ and here: http://arkadia.xyz and thought how this can be implemented in AutoIt. Here the results.
       
      The Zoomquilt:
      ;coded by UEZ build 2018-01-10, idea and images taken from http://zoomquilt.org/ ;thanks to spudw2k for the MouseZoom function #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit, $iW, $iH Global Const $sTitle = "GDI Image Zoom v2.1.2 coded by UEZ" AutoItSetOption("GUIOnEventMode", 1) Downloader() GDIPlus_ZoomImage() AutoItSetOption("GUIOnEventMode", 0) _GDIPlus_Shutdown() Func GDIPlus_ZoomImage($bMultimonitor = False) $bExit = False Local $i, $aImages[46], $hImage, $hObj ConsoleWrite("Loading images from local disk..." & @CRLF) Local $fTimer = TimerInit() For $i = 0 To UBound($aImages) - 1 $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\TheZoomquilt" & StringFormat("%02i.jpg", $i)) $aImages[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) Next ConsoleWrite(UBound($aImages) & " images loaded in " & TimerDiff($fTimer) & " ms" & @CRLF) Local $tDim = DllStructCreate($tagBITMAP) DllCall("GDI32.dll", 'int', 'GetObject', 'int', $aImages[0], 'int', DllStructGetSize($tDim), 'ptr', DllStructGetPtr($tDim)) $iW = $tDim.bmWidth $iH = $tDim.bmHeight Local $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]"), $aFullScreen[4], $iW_Dt, $iH_Dt $aFullScreen = WinGetPos($hFullScreen) If $bMultimonitor Then $iW_Dt = $aFullScreen[2] $iH_Dt = $aFullScreen[3] Else $iW_Dt = @DesktopWidth $iH_Dt = @DesktopHeight $aFullScreen[0] = "" $aFullScreen[1] = "" EndIf $hGUI = GUICreate($sTitle, $iW_Dt, $iH_Dt, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, $WS_EX_TOPMOST) GUISetState(@SW_SHOW, $hGUI) GUISetCursor(16, 1) ;create canvas elements Local Const $hDC = _WinAPI_GetDC($hGUI) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW_Dt, $iH_Dt) Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC) _WinAPI_SetStretchBltMode($hDC_backbuffer, $STRETCH_DELETESCANS) Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local Const $hBrush_Clr = _GDIPlus_BrushCreateSolid(0xFF000000), _ $hBrush_FPS = _GDIPlus_BrushCreateSolid(0xFFFFFFFF), _ $hFormat_FPS = _GDIPlus_StringFormatCreate(), _ $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial"), _ $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 8), _ $tLayout_FPS = _GDIPlus_RectFCreate(0, 0, 130, 16) $iFPS = 0 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") AdlibRegister("CalcFPS", 1000) Local $a[3], $b = 1, $c, $x, $e, $y, $w, $h, $w2 = $iW_Dt / 2, $h2 = $iH_Dt / 2, $q, $r If $iW_Dt > 1.5 * $iH_Dt Then $q = $iW_Dt $r = 0.75 * $iW_Dt Else $q = 1.5 * $iH_Dt $r = 0.75 * $iH_Dt EndIf Do For $e = 0 To 2 $a[$e] = $aImages[Mod(Floor($b) + $e, UBound($aImages))] Next $c = 2^(Mod($b, 1)) For $e = 0 To 2 $x = $w2 - $q / 2 * $c $y = $h2 - $r / 2 * $c $w = $q * $c $h = $r * $c $hObj = _WinAPI_SelectObject($hMemDC, $a[$e]) _WinAPI_StretchBlt($hDC_backbuffer, $x, $y, $w, $h, $hMemDC, 0, 0, $iW, $iH, $SRCCOPY) $c *= 0.5 Next $b += MouseZoom() IF $b < 0 Then $b = UBound($aImages) - $b _GDIPlus_GraphicsDrawStringEx($hCanvas, "FPS: " & $iShowFPS & " @ " & $iW_Dt & "x" & $iH_Dt & " px", $hFont_FPS, $tLayout_FPS, $hFormat_FPS, $hBrush_FPS) _WinAPI_BitBlt($hDC, 0, 0, $iW_Dt, $iH_Dt, $hDC_backbuffer, 0, 0, $SRCCOPY) $iFPS += 1 If $bExit Then ExitLoop Until Not Sleep(0) AdlibUnRegister("CalcFPS") ;release resources _GDIPlus_FontDispose($hFont_FPS) _GDIPlus_FontFamilyDispose($hFamily_FPS) _GDIPlus_StringFormatDispose($hFormat_FPS) _GDIPlus_BrushDispose($hBrush_Clr) _GDIPlus_BrushDispose($hBrush_FPS) _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hMemDC, $hObj) _WinAPI_DeleteDC($hMemDC) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($hGUI, $hDC) For $i = 0 To UBound($aImages) - 1 _WinAPI_DeleteObject($aImages[$i]) Next GUIDelete($hGUI) EndFunc ;==>GDIPlus_ZoomImage Func MouseZoom() ;https://www.arduino.cc/reference/en/language/functions/math/map/ Local $iInput = MouseGetPos(1), $iInMin = 0, $iInMax = @DesktopHeight, $iOutMin = 1, $iOutMax = -1, $iStep = 0.025 Return (($iInput - $iInMin) * ($iOutMax - $iOutMin) / ($iInMax - $iInMin) + $iOutMin) * $iStep EndFunc ;MouseZoom() Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func CalcFPS() ;display FPS $iShowFPS = $iFPS $iFPS = 0 EndFunc ;==>CalcFPS Func Downloader() Local $i, $A = StringSplit("FUjD9hf gbHhxTR 8YyzJdR xP3aNkR 2Qi4fQr E6pW5Ky zmtWIBF Af7LtYp TuXy30d 3nKGLr2 hNoWscB mSBvv3K f4wJ70e mIt9XmM M4TkAyh P4L4qhd hNM6bTv VoT8JXM jqcGH0B DYVoN8n bOPQkOI NeaTfJ1 18ppMNr FZ3d8Jv HsoX2RP mjv4kzI 6rpJbef pySKauq WjNQYRV Ffooo8y Xei5XfD T5A415r LiV0VNB nGcwiO4 b1Gdjjy GE828iy eSQ7SLe 1mPyGgL GNtwJIr KxBlU7E aKXhms5 9Quu2wu Y07quDf r0yC5Qa 273fCkD 2wMyCUw FUjD9hf", " ", 2) Local $sURL For $i = 0 To UBound($A) - 1 If Not FileExists(@ScriptDir & "\Images\TheZoomquilt" & StringFormat("%02i.jpg", $i)) Then If Not FileExists(@ScriptDir & "\Images") Then DirCreate(@ScriptDir & "\Images") $sURL = "http://imgur.com/" & $A[Mod(20 + $i, 46)] & ".jpg" ConsoleWrite("Downloading " & $sURL & ": " & InetGet($sURL, @ScriptDir & "\Images\TheZoomquilt" & StringFormat("%02i.jpg", $i), 8) & " bytes" & @CRLF) ToolTip("Downloading images...Please wait! -> " & $i + 1 & " / " & UBound($A), MouseGetPos(0), MouseGetPos(1)) EndIf Next ToolTip("") EndFunc ;==>Downloader  
       
      Arkadia:
      ;coded by UEZ build 2018-01-10, idea and images taken from http://arkadia.xyz ;thanks to spudw2k for the MouseZoom function #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit, $iW, $iH Global Const $sTitle = "GDI Image Zoom v2.2.1 coded by UEZ" AutoItSetOption("GUIOnEventMode", 1) Downloader() GDIPlus_ZoomImage() AutoItSetOption("GUIOnEventMode", 0) _GDIPlus_Shutdown() Func GDIPlus_ZoomImage($bMultimonitor = False) $bExit = False Local $i, $aImages[49], $hImage, $hObj ConsoleWrite("Loading images from local disk..." & @CRLF) Local $fTimer = TimerInit() For $i = 0 To UBound($aImages) - 1 $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Arkadia" & $i & ".jpg") $aImages[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) Next ConsoleWrite(UBound($aImages) & " images loaded in " & TimerDiff($fTimer) & " ms" & @CRLF) Local $tDim = DllStructCreate($tagBITMAP) DllCall("GDI32.dll", "int", "GetObject", "int", $aImages[0], "int", DllStructGetSize($tDim), "ptr", DllStructGetPtr($tDim)) $iW = $tDim.bmWidth $iH = $tDim.bmHeight Local $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]"), $aFullScreen[4], $iW_Dt, $iH_Dt $aFullScreen = WinGetPos($hFullScreen) If $bMultimonitor Then $iW_Dt = $aFullScreen[2] $iH_Dt = $aFullScreen[3] Else $iW_Dt = @DesktopWidth $iH_Dt = @DesktopHeight $aFullScreen[0] = "" $aFullScreen[1] = "" EndIf $hGUI = GUICreate($sTitle, $iW_Dt, $iH_Dt, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, $WS_EX_TOPMOST) GUISetState(@SW_SHOW, $hGUI) GUISetCursor(16, 1) ;create canvas elements Local Const $hDC = _WinAPI_GetDC($hGUI) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW_Dt, $iH_Dt) Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC) _WinAPI_SetStretchBltMode($hDC_backbuffer, $STRETCH_DELETESCANS) Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local Const $hBrush_Clr = _GDIPlus_BrushCreateSolid(0xFF000000), _ $hBrush_FPS = _GDIPlus_BrushCreateSolid(0xFFFFFFFF), _ $hFormat_FPS = _GDIPlus_StringFormatCreate(), _ $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial"), _ $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 8), _ $tLayout_FPS = _GDIPlus_RectFCreate(0, 0, 130, 16) $iFPS = 0 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") AdlibRegister("CalcFPS", 1000) Local $a[3], $b = 1, $c, $x, $e, $y, $w, $h, $w2 = $iW_Dt / 2, $h2 = $iH_Dt / 2, $q, $r If $iW_Dt > 1.5 * $iH_Dt Then $q = $iW_Dt $r = 0.75 * $iW_Dt Else $q = 1.5 * $iH_Dt $r = 0.75 * $iH_Dt EndIf Do For $e = 0 To 2 $a[$e] = $aImages[Mod(Floor($b) + $e, UBound($aImages))] Next $c = 2^(Mod($b, 1)) For $e = 0 To 2 $x = $w2 - $q / 2 * $c $y = $h2 - $r / 2 * $c $w = $q * $c $h = $r * $c $hObj = _WinAPI_SelectObject($hMemDC, $a[$e]) _WinAPI_StretchBlt($hDC_backbuffer, $x, $y, $w, $h, $hMemDC, 0, 0, $iW, $iH, $SRCCOPY) $c *= 0.5 Next $b += MouseZoom() IF $b < 0 Then $b = UBound($aImages) - $b _GDIPlus_GraphicsDrawStringEx($hCanvas, "FPS: " & $iShowFPS & " @ " & $iW_Dt & "x" & $iH_Dt & " px", $hFont_FPS, $tLayout_FPS, $hFormat_FPS, $hBrush_FPS) _WinAPI_BitBlt($hDC, 0, 0, $iW_Dt, $iH_Dt, $hDC_backbuffer, 0, 0, $SRCCOPY) $iFPS += 1 If $bExit Then ExitLoop Until Not Sleep(0) AdlibUnRegister("CalcFPS") ;release resources _GDIPlus_FontDispose($hFont_FPS) _GDIPlus_FontFamilyDispose($hFamily_FPS) _GDIPlus_StringFormatDispose($hFormat_FPS) _GDIPlus_BrushDispose($hBrush_Clr) _GDIPlus_BrushDispose($hBrush_FPS) _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hMemDC, $hObj) _WinAPI_DeleteDC($hMemDC) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($hGUI, $hDC) For $i = 0 To UBound($aImages) - 1 _WinAPI_DeleteObject($aImages[$i]) Next GUIDelete($hGUI) EndFunc ;==>GDIPlus_ZoomImage Func MouseZoom() ;https://www.arduino.cc/reference/en/language/functions/math/map/ Local $iInput = MouseGetPos(1), $iInMin = 0, $iInMax = @DesktopHeight, $iOutMin = 1, $iOutMax = -1, $iStep = 0.025 Return (($iInput - $iInMin) * ($iOutMax - $iOutMin) / ($iInMax - $iInMin) + $iOutMin) * $iStep EndFunc ;MouseZoom() Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func CalcFPS() ;display FPS $iShowFPS = $iFPS $iFPS = 0 EndFunc ;==>CalcFPS Func Downloader() Local $sURL, $i For $i = 0 To 48 If Not FileExists(@ScriptDir & "\Images\Arkadia" & $i & ".jpg") Then If Not FileExists(@ScriptDir & "\Images") Then DirCreate(@ScriptDir & "\Images") $sURL = "http://arkadia.xyz/images/arkadia" & $i & ".jpg" ConsoleWrite("Downloading " & $sURL & ": " & InetGet($sURL, @ScriptDir & "\Images\Arkadia" & $i & ".jpg", 8) & " bytes" & @CRLF) ToolTip("Downloading images...Please wait! -> " & $i + 1 & " / " & $i, MouseGetPos(0), MouseGetPos(1)) EndIf Next ToolTip("") EndFunc ;==>Downloader  
      The missing images will be download and saved to script dir in folder images. Due to internal integer format of the GDI functions the screen is little bit wobbling.
       
      Happy watching. 
    • tcurran
      By tcurran
      Here are two functions to provide pixel-accurate height and width dimensions for a given string.
      The more commonly-used _GDIPlus_GraphicsMeasureString built-in UDF is problematic because it returns the width padded by roughly one en-space (for reasons related to the various ways Windows produces anti-aliased fonts).
      These are AutoIt translations of Pierre Arnaud's C# functions, described in his CodeProject article "Bypass Graphics.MeasureString limitations"
      The first is an all-purpose version that takes a window handle, string, font family, font size (in points), style, and (optionally) width of the layout column (in pixels) as parameters.
      The second, more efficient version is intended for applications where GDI+ fonts are already in use, and takes handles to the existing graphics context, string, font, layout and format as parameters.
      Both functions return a two-row array with the exact width [0] and height [1] of the string (in pixels).
      EDIT: (Note that some of the same anti-aliasing measurement issues still apply. I did my best to work around them, but the output of the function may still be off by a pixel or two. Buyer beware.)
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringInPixels ; Description ...: Returns a pixel-accurate height and width for a given string using a given font, style and size. ; Syntax ........: _StringInPixels($hGUI, $sString, $sFontFamily, $fSize, $iStyle[, $iColWidth = 0]) ; Parameters ....: $hGUI - Handle to the window. ; $sString - The string to be measured. ; $sFontFamily - Full name of the font to use. ; $fSize - Font size in points (half-point increments). ; $iStyle - Combination of 0-normal, 1-bold, 2-italic, 4-underline, 8-strikethrough ; $iColWidth - [optional] If word-wrap is desired, column width in pixels ; Return values .: 2-row array. [0] is width in pixels; [1] is height in pixels. ; Author ........: Tim Curran; adapted from Pierre Arnaud's C# function ; Modified ......: ; Remarks .......: This version is longer and less efficient but works for all purposes. ; Related .......: <https://www.codeproject.com/Articles/2118/Bypass-Graphics-MeasureString-limitations> ; Link ..........: ; Example .......: Example-StringInPixels.au3 ; =============================================================================================================================== #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Func _StringInPixels($hGUI, $sString, $sFontFamily, $fSize, $iStyle, $iColWidth = 0) _GDIPlus_Startup() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;Create a graphics object from a window handle Local $aRanges[2][2] = [[1]] $aRanges[1][0] = 0 ;Measure first char (0-based) $aRanges[1][1] = StringLen($sString) ;Region = String length Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFontFamily) Local $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle) _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges) ;Set ranges Local $aWinClient = WinGetClientSize($hGUI) If $iColWidth = 0 Then $iColWidth = $aWinClient[0] Local $tLayout = _GDIPlus_RectFCreate(10, 10, $iColWidth, $aWinClient[1]) Local $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) ;get array of regions Local $aBounds = _GDIPlus_RegionGetBounds($aRegions[1], $hGraphic) Local $aWidthHeight[2] = [$aBounds[2], $aBounds[3]] ; Clean up resources _GDIPlus_FontDispose($hFont) _GDIPlus_RegionDispose($aRegions[1]) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Return $aWidthHeight EndFunc ;==>_StringInPixels ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringInPixels_gdip ; Description ...: Returns a pixel-accurate height and width for a given string using a GDI+ font, layout and format ; Syntax ........: _StringInPixels_gdip($hGraphic, $sString, $hFont, $tLayout, $hFormat) ; Parameters ....: $hGraphic - Handle to a GDI+ graphics object. ; $sString - The string to be measured. ; $hFont - Handle to a GDI+ font. ; $tLayout - A $tagGDIPRECTF structure that bounds the string. ; $hFormat - Handle to a GDI+ string format. ; Return values .: 2-row array. [0] is width in pixels; [1] is height in pixels. ; Author ........: Tim Curran; adapted from Pierre Arnaud's C# function ; Modified ......: ; Remarks .......: This much more efficient version is for use with GDI+ fonts ; Related .......: ; Link ..........: <https://www.codeproject.com/Articles/2118/Bypass-Graphics-MeasureString-limitations> ; Example .......: Example-StringInPixels.au3 ; =============================================================================================================================== #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Func _StringInPixels_gdip($hGraphic, $sString, $hFont, $tLayout, $hFormat) Local $aRanges[2][2] = [[1]] $aRanges[1][0] = 0 ;Measure first char (0-based) $aRanges[1][1] = StringLen($sString) ;Region = String length _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINT_CLEARTYPEGRIDFIT) _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges) ;Set ranges Local $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) ;get array of regions Local $aBounds = _GDIPlus_RegionGetBounds($aRegions[1], $hGraphic) Local $aWidthHeight[2] = [$aBounds[2], $aBounds[3]] _GDIPlus_RegionDispose($aRegions[1]) Return $aWidthHeight EndFunc ;==>_StringInPixels_gdip  
      _StringInPixels.au3
      Example-StringInPixels.au3
    • c.haslam
      By c.haslam
      In the code that follows, it appears that DllStructCreate() is not allocating memory in
      $tag = 'byte val['&$iLength&']' . . Static Local $tvalue = DllStructCreate($tag) Running the code below, the problem does not show, but it does show in a much longer script: there _GDIPlus_ImageSaveToFile only writes about 30K bytes when it should write about 1MB, which it does when the code is
      $tag = 'char val['&$iLength&']' . . Static Local $tvalue = DllStructCreate($tag) It should write about 1 MB.
      I suggest caution in running the code below. On my PC, it caused a second instance of SciTE to appear at the top left of the Desktop, showing only the title bar, with a width of only approximately 200 pixels! Then rebooting the PC showed this at login. Further, double-clicking on the SciTE shortcut on the Desktop showed SciTE in the same way! (After running Regedit, and searching for SciTE, the shortcut behaves normally.)
      I would appreciate help in determining whether or not there is a bug in DLLStructCreate, preferably a way which does not clobber Windows. Of course, It is possible that there is a bug in my code.
      I have made $tvalue Static in the hope that this might make the code run properly. Doing this did not help.
      My code is based on code written by Authenticity and ChrisL.
      #include <GDIPlus.au3> #include <Array.au3> Opt('MustDeclareVars',1) ; Property Item structure Global Const $tagGDIPPROPERTYITEM = _ "uint id;" & _ ; ID of this property "ulong length;" & _ ; Length of the property value, in bytes "word type;" & _ ; Type of the value, as one of TAG_TYPE_XXX constants "ptr pvalue;" ; pointer to property value ; Image property types constants ; Ref: https://www.media.mit.edu/pia/Research/deepview/exif.html Global Const $GDIP_PROPERTYTAGTYPEUBYTE = 1 Global Const $GDIP_PROPERTYTAGTYPEASCII = 2 Global Const $GDIP_PROPERTYTAGTYPEUSHORT = 3 Global Const $GDIP_PROPERTYTAGTYPEULONG = 4 Global Const $GDIP_PROPERTYTAGTYPEURATIONAL = 5 Global Const $GDIP_PROPERTYTAGTYPESBYTE = 6 Global Const $GDIP_PROPERTYTAGTYPEUNDEFINED = 7 Global Const $GDIP_PROPERTYTAGTYPESSHORT = 8 Global Const $GDIP_PROPERTYTAGTYPESLONG = 9 Global Const $GDIP_PROPERTYTAGTYPESRATIONAL = 10 Global Const $GDIP_PROPERTYTAGTYPESFLOAT = 11 Global Const $GDIP_PROPERTYTAGTYPEDFLOAT = 12 main() Func main() _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile('H:\temp\AP test data\DSC00824 - Copy.jpg') Local $ar = _GDIPlus_ImageGetAllPropertyItemsEx($hImage) Local $propsAr[UBound($ar,1)-1][5],$vec,$j=-1 For $i = 1 To $ar[0][0] If $ar[$i][3]<>0 Then ; pValue -- for Sony! $j += 1 $propsAr[$j][0] = $ar[$i][0] ; id $propsAr[$j][1] = $ar[$i][1] ; length $propsAr[$j][2] =$ar[$i][2]; type $vec = _GDIPlus_ImageGetPropertyItemValue($ar[$i][1],$ar[$i][2],$ar[$i][3]) $propsAr[$j][3] = $vec[0] ; val1 Switch $ar[$i][2] Case 5,10 ; $GDIP_PROPERTYTAGTYPEURATIONAL,$GDIP_PROPERTYTAGTYPESRATIONAL $propsAr[$j][4] = $vec[1] Case Else $propsAr[$j][4] = '' EndSwitch EndIf Next ReDim $propsAr[$j+1][5] For $i = 0 To UBound($propsAr,1)-1 Switch $propsAr[$i][2] ; type Case 5,10 ; $GDIP_PROPERTYTAGTYPEURATIONAL,$GDIP_PROPERTYTAGTYPESRATIONAL _GDIPlus_ImageSetPropertyItemEx($hImage,$propsAr[$i][0],$propsAr[$i][1], _ $propsAr[$i][2],$propsAr[$i][3],$propsAr[$i][4]) Case Else _GDIPlus_ImageSetPropertyItemEx($hImage,$propsAr[$i][0],$propsAr[$i][1], _ $propsAr[$i][2],$propsAr[$i][3]) EndSwitch Next _GDIPlus_ImageSaveToFile($hImage,'H:\b\1.jpg') _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc Func _GDIPlus_ImageGetAllPropertyItemsEx($hImage) Local $iI, $iCount, $tBuffer, $pBuffer, $iBuffer, $tPropertyItem, $aSize, $aPropertyItems[1][1], $aResult $aSize = _GDIPlus_ImageGetPropertySize($hImage) If @error Then Return SetError(@error, @extended, -1) $iBuffer = $aSize[0] $tBuffer = DllStructCreate("byte[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) $iCount = $aSize[1] $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetAllPropertyItems", "hwnd", $hImage, "uint", $iBuffer, "uint", $iCount, "ptr", $pBuffer) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], False) ReDim $aPropertyItems[$iCount + 1][4] $aPropertyItems[0][0] = $iCount For $iI = 1 To $iCount $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, $pBuffer) $aPropertyItems[$iI][0] = DllStructGetData($tPropertyItem, "id") $aPropertyItems[$iI][1] = DllStructGetData($tPropertyItem, "length") $aPropertyItems[$iI][2] = DllStructGetData($tPropertyItem, "type") $aPropertyItems[$iI][3] = DllStructGetData($tPropertyItem, "pvalue") $pBuffer += DllStructGetSize($tPropertyItem) Next Return $aPropertyItems EndFunc Func _GDIPlus_ImageGetPropertyItemValue($iLength, $iType, $pValue) Static Local $tvalue Switch $iType Case 1,6 ; $GDIP_PROPERTYTAGTYPEUBYTE,$GDIP_PROPERTYTAGTYPESBYTE $tvalue = DllStructCreate('byte val',$pValue) Case 2 ; $GDIP_PROPERTYTAGTYPEASCII $tvalue = DllStructCreate('char val['&$iLength&']',$pValue) Case 3 ; $GDIP_PROPERTYTAGTYPEUSHORT $tvalue = DllStructCreate('ushort val',$pValue) Case 4 ; $GDIP_PROPERTYTAGTYPEULONG $tvalue = DllStructCreate('ulong val',$pValue) Case 5 ; $GDIP_PROPERTYTAGTYPEURATIONAL $tvalue = DllStructCreate('ulong val1;ulong val2',$pValue) Case 7 ; $GDIP_PROPERTYTAGTYPEUNDEFINED ; undefined, per specification, but may be a long but is sometimes a string $tvalue = DllStructCreate('byte val['&$ilength&']',$pValue) ; see _GDIPlus_ImageSetPropertyItemEx ;~ $tvalue = DllStructCreate('char val['&$ilength&']',$pValue) Case 8 ; $GDIP_PROPERTYTAGTYPESSHORT $tvalue = DllStructCreate('short val',$pValue) Case 9 ; $GDIP_PROPERTYTAGTYPEULONG $tvalue = DllStructCreate('ulong val',$pValue) Case 10 ; $GDIP_PROPERTYTAGTYPESRATIONAL $tvalue = DllStructCreate('ulong val1;ulong val2',$pValue) Case 11 ; $GDIP_PROPERTYTAGTYPESFLOAT $tvalue = DllStructCreate('float val',$pValue) Case 12 ; $GDIP_PROPERTYTAGTYPEDFLOAT $tvalue = DllStructCreate('double val',$pValue) EndSwitch If @error Then Return SetError(@error,0,-1) Switch $iType Case 5,10 ; $GDIP_PROPERTYTAGTYPEURATIONAL,$GDIP_PROPERTYTAGTYPESRATIONAL Local $aRet[2] $aRet[0] = DllStructGetData($tvalue,'val1') $aRet[1] = DllStructGetData($tvalue,'val2') Case Else Local $aRet[1] $aRet[0] = DllStructGetData($tvalue,'val') EndSwitch Return $aRet EndFunc Func _GDIPlus_ImageGetPropertySize($hImage) Local $aSize[2], $aResult $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertySize", "hwnd", $hImage, "uint*", 0, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $aSize[0] = $aResult[2] $aSize[1] = $aResult[3] Return $aSize EndFunc ;==>_GDIPlus_ImageGetPropertySize Func _GDIPlus_ImageSetPropertyItemEx($hImage,$id,$iLength,$iType,$value1,$value2=-1) Local $tProp = DllStructCreate($tagGDIPPROPERTYITEM) DllStructSetData($tProp,'id',$id) DllStructSetData($tProp,'type',$itype) DllStructSetData($tProp,'length',$ilength) Local $tag Switch $iType Case $GDIP_PROPERTYTAGTYPEUBYTE,$GDIP_PROPERTYTAGTYPESBYTE $tag = 'byte val' Case $GDIP_PROPERTYTAGTYPEASCII $tag = 'char val['&$iLength&']' Case $GDIP_PROPERTYTAGTYPEUSHORT $tag = 'ushort val' Case $GDIP_PROPERTYTAGTYPEULONG $tag = 'ulong val' Case $GDIP_PROPERTYTAGTYPEURATIONAL $tag = 'ulong val1;ulong val2' Case $GDIP_PROPERTYTAGTYPEUNDEFINED ; undefined, per specification, but may be a long but is sometimes a string $tag = 'byte val['&$iLength&']' ; causes saving to jpeg to write junk ;~ $tag = 'char val['&$iLength&']' Case $GDIP_PROPERTYTAGTYPESSHORT $tag = 'short val' Case $GDIP_PROPERTYTAGTYPEULONG $tag = 'ulong val' Case $GDIP_PROPERTYTAGTYPESRATIONAL $tag = 'long val1;long val2' Case $GDIP_PROPERTYTAGTYPESFLOAT $tag = 'float val' Case $GDIP_PROPERTYTAGTYPEDFLOAT $tag = 'double val' EndSwitch Static Local $tvalue = DllStructCreate($tag) Switch $iType Case $GDIP_PROPERTYTAGTYPEURATIONAL,$GDIP_PROPERTYTAGTYPESRATIONAL DllStructSetData($tvalue,'val1',$value1) DllStructSetData($tvalue,'val2',$value2) Case Else DllStructSetData($tvalue,1,$value1) EndSwitch DllStructSetData($tProp,'pvalue',DllStructGetPtr($tvalue)) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetPropertyItem", "hwnd", $hImage, "ptr", _ DllStructGetPtr($tProp)) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], -1) Return $aResult[0] = 0 EndFunc I have seen $iLength be as much as 37 KB for $GDIP_PROPERTYTAGTYPEUNDEFINED.
      Is there is a bug, how can this be demonstrated to the developers in a few lines of code (without clobbering Windows)?