Augen folgen Maus (Beispiel)

  • Hey, hab letztens in der SB gelesen das jmd versucht etwas darzustellen was immer in Richtung Maus guckt. Hab mich kurz drangesetzt und was geschrieben, ist nur ein Beispiel vllt kann trotzdem jmd was mit anfangen ^^

    Spoiler anzeigen
    [autoit]

    #region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_outfile=..\..\..\Desktop\Eyes.exe
    #AutoIt3Wrapper_UseX64=n
    #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GDIPlus.au3>
    #include <WinApi.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $nWidth = 700, $nHeight = 700

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

    #region Auge

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

    ;; Array/Eyes
    Dim $aEyes[5][5][3]
    ;; Variablen/Eyes
    Global $nEyeWidth = $nWidth / UBound($aEyes, 1)
    Global $nEyeHeight = $nHeight / UBound($aEyes, 2)

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

    For $y = 0 To UBound($aEyes, 2) - 1 ;; Y
    For $x = 0 To UBound($aEyes, 1) - 1 ;; X
    $aEyes[$x][$y][0] = $nEyeWidth / 2 * (2 * ($x)) ;; X
    $aEyes[$x][$y][1] = $nEyeHeight / 2 * (2 * ($y)) ;; Y
    $aEyes[$x][$y][2] = 0 ; Zwinkern True/False
    Next
    Next

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

    ;~ (0.0)|(0.1)...
    ;~ (1.0)|(1.1)...
    ;~ ...

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

    ;; Array/Iris
    Dim $aIris[UBound($aEyes, 1)][UBound($aEyes, 2)][2]

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

    For $y = 0 To UBound($aEyes, 2) - 1
    For $x = 0 To UBound($aEyes, 1) - 1
    $aIris[$x][$y][0] = ($x * ($nEyeWidth)) + ($nEyeWidth / 2) ;; X
    $aIris[$x][$y][1] = ($y * ($nEyeHeight)) + ($nEyeHeight / 2) ;; Y
    Next
    Next

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

    #endregion Auge

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

    $hWnd = GUICreate("Test", $nWidth, $nHeight, -1, -1, 0x80000000)
    GUISetOnEvent(-3, "_Exit")

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

    GUISetState()

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

    $hDC = _WinAPI_GetDC($hWnd)
    $hDC_Buffer = _WinAPI_CreateCompatibleDC($hDC)
    $hGDI_Bitmap = _WinAPI_CreateCompatibleBitmap($hDC, $nWidth, $nHeight)
    _WinAPI_SelectObject($hDC_Buffer, $hGDI_Bitmap)

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

    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)

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

    $hBrush_Eye = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hBrush_Iris = _GDIPlus_BrushCreateSolid(0xFFAAAAFF)

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

    $hPen_Klick = _GDIPlus_PenCreate(0xFF000000, 4)

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

    $FPSTimer = TimerInit()

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

    While Sleep(20)
    _GDIPlus_GraphicsClear($hGraphics, 0xFFAAAAAA)
    $aMouse = GUIGetCursorInfo($hWnd);

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

    For $y = 0 To UBound($aEyes, 2) - 1
    For $x = 0 To UBound($aEyes, 1) - 1
    If $aEyes[$x][$y][2] = 0 Then
    $aNewPos = _IrisGetNewPos($aMouse[0], $aMouse[1], $aIris[$x][$y][0], $aIris[$x][$y][1], $nEyeWidth, $nEyeHeight, $aEyes, $x, $y, $aMouse[2])
    _GDIPlus_GraphicsFillEllipse($hGraphics, $aEyes[$x][$y][0], $aEyes[$x][$y][1], $nEyeWidth, $nEyeHeight, $hBrush_Eye)
    _GDIPlus_GraphicsFillEllipseMiddle($hGraphics, $aNewPos[0], $aNewPos[1], $nEyeWidth / 2, $nEyeHeight / 2, $hBrush_Iris)
    _GDIPlus_GraphicsFillEllipseMiddle($hGraphics, $aNewPos[0], $aNewPos[1], $nEyeWidth / 4.5, $nEyeHeight / 4.5)
    Else
    _GDIPlus_GraphicsFillEllipse($hGraphics, $aEyes[$x][$y][0], $aEyes[$x][$y][1], $nEyeWidth, $nEyeHeight, $hBrush_Eye)
    _GDIPlus_GraphicsDrawArc($hGraphics, $aEyes[$x][$y][0], $aEyes[$x][$y][1] - $nEyeHeight / 3, $nEyeWidth / 1, $nEyeHeight / 1, 50, 80, $hPen_Klick)
    EndIf
    Next
    Next

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

    _GDIPlus_GraphicsDrawString($hGraphics, "FPS:" & 1000 / TimerDiff($FPSTimer), $nWidth - 47, 3)
    $FPSTimer = TimerInit()

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

    _WinAPI_BitBlt($hDC, 0, 0, $nWidth, $nHeight, $hDC_Buffer, 0, 0, 0x00CC0020)
    WEnd

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

    Func _IrisGetNewPos($_MouseX, $_MouseY, $_IrisX, $_IrisY, $_Width, $_Height, ByRef $_Eyes, $_x, $_y, $_MouseClick)
    Local $fSteigung_X, $fSteigung_Y, $fLength;

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

    $fLength = Sqrt(($_IrisX - $_MouseX) ^ 2 + ($_IrisY - $_MouseY) ^ 2)

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

    If $fLength <= $_Width / 4 And $fLength <= $nHeight / 4 Then
    If $_MouseClick = 1 Then
    $aEyes[$_x][$_y][2] = 1;
    EndIf

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

    Dim $aNewPos[2] = [$_MouseX, $_MouseY]
    Return $aNewPos
    EndIf

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

    $fSteigung_X = ($_IrisX - $_MouseX) / $fLength
    $fSteigung_Y = ($_IrisY - $_MouseY) / $fLength

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

    $NewPos_X = $_IrisX - $fSteigung_X * $_Width / 4
    $NewPos_Y = $_IrisY - $fSteigung_Y * $_Height / 4

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

    Dim $NewPos[2] = [$NewPos_X, $NewPos_Y]

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

    Return $NewPos
    EndFunc ;==>_IrisGetNewPos

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

    Func _GDIPlus_GraphicsFillEllipseMiddle($_Graphic, $_x, $_y, $_Width, $_Height, $_Brush = 0)
    _GDIPlus_GraphicsFillEllipse($_Graphic, $_x - $_Width / 2, $_y - $_Height / 2, $_Width, $_Height, $_Brush)
    EndFunc ;==>_GDIPlus_GraphicsFillEllipseMiddle

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

    Func _Exit()
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hDC_Buffer)
    _WinAPI_DeleteObject($hGDI_Bitmap)

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

    _GDIPlus_BrushDispose($hBrush_Eye)
    _GDIPlus_BrushDispose($hBrush_Iris)
    _GDIPlus_PenDispose($hPen_Klick)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

  • Sowas ist möglich... aber ohne die superbrille wird es nicht funktionieren!
    Man könnte eine brielle zusammen bateln und die augenfarbe eines menschen auslesen bzw. sowas wie einen "GetPixelColor" machen.
    dein Projekt ist echt super!!!! :thumbup:

    Einmal editiert, zuletzt von Lupar (20. November 2011 um 13:16)