dragan Posted July 29, 2011 Posted July 29, 2011 (edited) I'm not sorry to bring this up because this is totally awesome. And I'm surprised more people didn't pay attention to this I guess it's 'cause of code complexity, and lack of object programming skills in generally for all of us other mortals. I'm just wondering if it's possible to make moving animation with .CreateStoryboard or is it only for trans. between colors. If I can't use CreateStoryboard, then I have to draw object manually, changing it's X and Y coords, pixel by pixel in order for object to move (like I would with GDI), but for this I have to use function SetTransform, so can you write an example for SetTransform as well? Edited July 30, 2011 by dragan
trancexx Posted July 31, 2011 Author Posted July 31, 2011 (edited) I'm not sorry to bring this up because this is totally awesome. And I'm surprised more people didn't pay attention to this I guess it's 'cause of code complexity, and lack of object programming skills in generally for all of us other mortals. I'm just wondering if it's possible to make moving animation with .CreateStoryboard or is it only for trans. between colors. If I can't use CreateStoryboard, then I have to draw object manually, changing it's X and Y coords, pixel by pixel in order for object to move (like I would with GDI), but for this I have to use function SetTransform, so can you write an example for SetTransform as well? Yes, with CreateStoryboard you can animate whatever you want. Do you have any code yet? I don't see anything terribly complicated about SetTransform. It takes pointer to structure of six floats defining the behavior. In example No5: it would be (find "; Render rectangle" line and replace with this): ;... ; Render rectangle $oRenderTarget.FillRoundedRectangle($tD2D1_ROUNDED_RECT(), $oBrushAnimated.__ptr__) ;================================> Local Static $D2D_MATRIX_3X2_F = _AutoItObject_DllStructCreate("float _11;float _12;float _21;float _22;float _31;float _32;") ; Translation $D2D_MATRIX_3X2_F._11 = 1 $D2D_MATRIX_3X2_F._12 = 0 $D2D_MATRIX_3X2_F._21 = 0 $D2D_MATRIX_3X2_F._22 = 1 $D2D_MATRIX_3X2_F._31 = -$nRed * 140 ; animated $D2D_MATRIX_3X2_F._32 = $nGreen * 120 ; animated $oRenderTarget.SetTransform($D2D_MATRIX_3X2_F()) $oRenderTarget.FillRoundedRectangle($tD2D1_ROUNDED_RECT(), $oBrushAnimated.__ptr__) ;<================================ ;... ...Try clicking now. Edited July 31, 2011 by trancexx ♡♡♡ . eMyvnE
dragan Posted July 31, 2011 Posted July 31, 2011 I've been playing with this for few hours, and I can't stop playing. It's perfect for making 2D game engine in autoit. I see you used matrix to move object, and I can see how you can scew, scale and move object, but I can't figure out how to use rotate. In MSDN it says that I can use matrix to rotate In this matrix, the M11, M12, M21, and M22 members define a linear transformation that can scale, rotate, or skew an objecthowever rotation requires 3 variables, centerX, centerY and rotation angle. I've been able to make rotation by using scew, example: ;================================> Local Static $D2D_MATRIX_3X2_F = _AutoItObject_DllStructCreate("float _11;float _12;float _21;float _22;float _31;float _32;") ; Translation $D2D_MATRIX_3X2_F._11 = 1 $D2D_MATRIX_3X2_F._12 = 0.5 $D2D_MATRIX_3X2_F._21 = -0.5 $D2D_MATRIX_3X2_F._22 = 1 $D2D_MATRIX_3X2_F._31 = -$nRed*140+150 $D2D_MATRIX_3X2_F._32 = $nGreen*120-150 $oRenderTarget.SetTransform($D2D_MATRIX_3X2_F()) $oRenderTarget.FillRoundedRectangle($tD2D1_ROUNDED_RECT(), $oBrushAnimated.__ptr__) ;<================================ but any value different than 0 on M12 and M21 increase or decrease entire object.
trancexx Posted July 31, 2011 Author Posted July 31, 2011 You should find file called D2D1Helper.h and study it. Convenient link.That's where you can see how to rotate matrix. Call D2D1MakeRotateMatrix function on $D2D_MATRIX_3X2_F. That's how it's done. ♡♡♡ . eMyvnE
dragan Posted July 31, 2011 Posted July 31, 2011 I thought I got it, however I dunno what type is matrix (or I'm doing it completely wrong) Local $iAngle = 30 Local $iCenter = DllStructCreate("float[2];") DllStructSetData($itData, 1, $aSize[0]/2, 1) DllStructSetData($itData, 1, $aSize[1]/2, 2) DllCall('d2d1.dll', 'none', 'D2D1MakeRotateMatrix', 'float', $iAngle, 'ptr', DllStructGetPtr($iCenter), 'type?', $D2D_MATRIX_3X2_F) ;-----------------------------------------------------------------------------------------------------------^
trancexx Posted July 31, 2011 Author Posted July 31, 2011 That function accepts 4 parameters for 32 bit AutoIt. It should be: float, float, float, ptr. ...teMatrix', 'float', angle, 'float', x, 'float', y, 'ptr', pointertostruct) ...sorry for the funny code, I'm at a beach. ♡♡♡ . eMyvnE
monoscout999 Posted August 1, 2011 Posted August 1, 2011 (edited) Hi trancexx my autoit script crashes when i try to run any object, the problem ocurrs when the line _AutoItObject_StartUp() is executed in the part that do the dllcall.. i check the dllopens lines from the include and no one gives me an error. i use Win7 64x but also i run the script with the directive #AutoIt3Wrapper_UseX64=n. Edited August 1, 2011 by monoscout999
trancexx Posted August 1, 2011 Author Posted August 1, 2011 Hi trancexx my autoit script crashes when i try to run any object, the problem ocurrs when the line _AutoItObject_StartUp() is executed in the part that do the dllcall.. i check the dllopens lines from the include and no one gives me an error. i use Win7 64x but also i run the script with the directive #AutoIt3Wrapper_UseX64=n.Can you post the shortest (exact) code that crashes. Run through the SciTE. And output from SciTE console too. ♡♡♡ . eMyvnE
monoscout999 Posted August 1, 2011 Posted August 1, 2011 (edited) Can you post the shortest (exact) code that crashes. Run through the SciTE. And output from SciTE console too. Your example. D2D_Example1.au3 expandcollapse popup; Direct2D BASIC EXAMPLE ;.......script written by trancexx (trancexx at yahoo dot com) #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64 = n Opt("MustDeclareVars", 1) #include <AutoitObject.au3> #include "Direct2D.intfc" ; This is file with interface definition #include <WindowsConstants.au3> HotKeySet("{ESC}", "_Quit") ; Esc to exit ; Error monitoring Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") ; Initialize AutoItObject _AutoItObject_StartUp() ; DLLs to use with DllCall Global Const $hD2D1DLL = DllOpen("d2d1.dll") ; GUI Global $hGUI = GUICreate("D2D Circle", 500, 500, -1, -1, $WS_OVERLAPPEDWINDOW) ; D2D1Factory object Global $oD2D1Factory = _D2D1CreateFactoryObject() If Not IsObj($oD2D1Factory) Then MsgBox(48 + 262144, "Ehh... Win7 wanted!", "Your system is not supported." & @CRLF & "Maybe you live in the past. Try not to.") Exit 2 EndIf ; Additional message processing GUIRegisterMsg($WM_PAINT, "_Direct2D_PAINT") GUIRegisterMsg($WM_ERASEBKGND, "_WM_ERASEBKGND") ; Show it GUISetState() While 1 If GUIGetMsg() = -3 Then Exit WEnd Func _WM_ERASEBKGND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Return 0 EndFunc ;==>_WM_ERASEBKGND Func _Direct2D_PAINT($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $tD2D1_RENDER_TARGET_PROPERTIES = _AutoItObject_DllStructCreate("dword type;dword format;dword alphaMode;float dpiX;float dpiY;dword usage;dword minLevel;") ; Using all default values ;~ $tD2D1_RENDER_TARGET_PROPERTIES.type = 0 ; D2D1_RENDER_TARGET_TYPE_DEFAULT ;~ $tD2D1_RENDER_TARGET_PROPERTIES.format = 0 ; DXGI_FORMAT_UNKNOWN ;~ $tD2D1_RENDER_TARGET_PROPERTIES.alphaMode = 0 ; D2D1_ALPHA_MODE_UNKNOWN ;~ $tD2D1_RENDER_TARGET_PROPERTIES.dpiX = 0 ;~ $tD2D1_RENDER_TARGET_PROPERTIES.dpiY = 0 ;~ $tD2D1_RENDER_TARGET_PROPERTIES.usage = 0 ; D2D1_RENDER_TARGET_USAGE_NONE ;~ $tD2D1_RENDER_TARGET_PROPERTIES.minLevel = 0 ; D2D1_FEATURE_LEVEL_DEFAULT Local $tD2D1_HWND_RENDER_TARGET_PROPERTIES = _AutoItObject_DllStructCreate("hwnd HWND;dword pixelSizeX;dword pixelSizeY;dword presentOptions") $tD2D1_HWND_RENDER_TARGET_PROPERTIES.HWND = Number($hGUI) Local $aSize[2] Local $aGUISize = WinGetClientSize($hGUI) If Not @error Then $aSize = $aGUISize $tD2D1_HWND_RENDER_TARGET_PROPERTIES.pixelSizeX = $aSize[0] $tD2D1_HWND_RENDER_TARGET_PROPERTIES.pixelSizeY = $aSize[1] $tD2D1_HWND_RENDER_TARGET_PROPERTIES.presentOptions = 0 ; D2D1_PRESENT_OPTIONS_NONE Local $aCall = $oD2D1Factory.CreateHwndRenderTarget($tD2D1_RENDER_TARGET_PROPERTIES(), $tD2D1_HWND_RENDER_TARGET_PROPERTIES(), 0) Local $pRenderTarget = $aCall[3] Local $oRenderTarget = _AutoItObject_WrapperCreate($pRenderTarget, $dtagID2D1RenderTarget) Local $tD2D1_COLOR_F = _AutoItObject_DllStructCreate("float r;float g; float b;float a;") $tD2D1_COLOR_F.r = 1 $tD2D1_COLOR_F.g = 1 $tD2D1_COLOR_F.b = 0 $tD2D1_COLOR_F.a = 1 ; I will pass NULL under D2D1_BRUSH_PROPERTIES, but still here's the definition ;~ Local $tD2D1_BRUSH_PROPERTIES = _AutoItObject_DllStructCreate("float opacity;float _11; float _12;float _21; float _22;float _31;float _32") $aCall = $oRenderTarget.CreateSolidColorBrush($tD2D1_COLOR_F(), 0, 0) ; Get brush Local $pBrush = $aCall[3] ; Call BeginDraw method first $oRenderTarget.BeginDraw() ; Define backgroung color Local $tD2D1_COLOR_F1 = _AutoItObject_DllStructCreate("float r;float g; float b;float a;") $tD2D1_COLOR_F1.r = 0 $tD2D1_COLOR_F1.g = 0 $tD2D1_COLOR_F1.b = 1 $tD2D1_COLOR_F1.a = 0 ; Render background $oRenderTarget.Clear($tD2D1_COLOR_F1()) ; Draw line (I won't) ;~ $oRenderTarget.DrawLine(0, 0, $aSize[0], $aSize[1], $pBrush, 1, 0) ; Define ellipse Local $tD2D1_ELLIPSE = _AutoItObject_DllStructCreate("float centerX;float centerY; float radiusX;float radiusY;") $tD2D1_ELLIPSE.centerX = $aSize[0] / 2 $tD2D1_ELLIPSE.centerY = $aSize[1] / 2 ; This is finding the min value of two If $aSize[0] > $aSize[1] Then $aSize[0] = $aSize[1] If $aSize[1] > $aSize[0] Then $aSize[1] = $aSize[0] ; Set radius $tD2D1_ELLIPSE.radiusX = $aSize[0] / 2 $tD2D1_ELLIPSE.radiusY = $aSize[1] / 2 ; Fill ellipse with color ;~ $oRenderTarget.FillEllipse($tD2D1_ELLIPSE(), $pBrush) ; Or maybe to draw ellipse $oRenderTarget.DrawEllipse($tD2D1_ELLIPSE(), $pBrush, 10, 0) ; End it $oRenderTarget.EndDraw(0, 0) _AutoItObject_IUnknownRelease($pBrush) EndFunc ;==>_Direct2D_PAINT Func _D2D1CreateFactoryObject() ; Needed identifier Local $tIID_ID2D1Factory = _AutoItObject_CLSIDFromString($sIID_ID2D1Factory) Local $aCall = DllCall($hD2D1DLL, "long", "D2D1CreateFactory", _ "dword", 0, _ ; D2D1_FACTORY_TYPE_SINGLE_THREADED "ptr", DllStructGetPtr($tIID_ID2D1Factory), _ "dword*", 0, _ ; D2D1_DEBUG_LEVEL_NONE "ptr*", 0) If @error Or $aCall[0] Then Return SetError(1, 0, 0) Local $pD2D1Factory = $aCall[4] ; Wrapp ID2D1Factory interface Return _AutoItObject_WrapperCreate($pD2D1Factory, $dtagID2D1Factory) EndFunc ;==>_D2D1CreateFactoryObject Func _Quit() Exit EndFunc ;==>_Quit Func _ErrFunc() ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF) EndFunc ;==>_ErrFunc Console Output >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "G:\Agustin\autoit\Direct2D\D2D_Example1.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3" /UserParams +>15:30:20 Starting AutoIt3Wrapper v.2.0.3.0 Environment(Language:0C0A Keyboard:0000040A OS:WIN_7/ CPU:X64 OS:X64) >Running AU3Check (1.54.19.0) params:-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 from:C:\Program Files (x86)\AutoIt3 +>15:30:20 AU3Check ended.rc:0 >Running:(3.3.6.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "G:\Agustin\autoit\Direct2D\D2D_Example1.au3" !>15:30:48 AutoIT3.exe ended.rc:-1073741819 Screen capture from the crash Edited August 1, 2011 by monoscout999
trancexx Posted August 1, 2011 Author Posted August 1, 2011 The shortest. Can you post the shortest? ♡♡♡ . eMyvnE
monoscout999 Posted August 1, 2011 Posted August 1, 2011 (edited) All the tests crash, the problem is when this line is executed _AutoItObject_StartUp() if i comment this line out i get a msgbox error(something about an old OS) but no crash. Edited August 1, 2011 by monoscout999
trancexx Posted August 1, 2011 Author Posted August 1, 2011 All the tests chash, the problem is when this line is executed _AutoItObject_StartUp() if i comment this line out i get a msgbox error(something about an old OS) but no crash. And if you change: #include <AutoitObject.au3> to:#include "AutoitObject.au3" ♡♡♡ . eMyvnE
monoscout999 Posted August 1, 2011 Posted August 1, 2011 And if you change: #include <AutoitObject.au3> to:#include "AutoitObject.au3" I fell like an i didn`t check that thanks for your time
trancexx Posted August 1, 2011 Author Posted August 1, 2011 I fell like an i didn`t check that thanks for your timeStill, I don't know why the examples have <> include. That wasn't my intention. ♡♡♡ . eMyvnE
snoopie Posted December 17, 2013 Posted December 17, 2013 Has anyone been able to rotate an object with D2D1MakeRotateMatrix? I seem to do it completely wrong and my script always freezes every time.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now