Jump to content
Sign in to follow this  
keen

Playing Using Your Body (Proof Of Concept)

Recommended Posts

keen

Here is just a proof of concept, moving objects using your body.

This program using a camera to find a black dot and tracks it as you move to control a pong game. This system is called LPT (Live Pixel Tracking) and the LPT software is copyrighted, so don't steal it.

UPDATE:

Now runs much faster!

Thanks to some autoit forums guys for the webcam script and the pong game. Also thanks to APPLEEATER for the tracking base.

CODE 1 (GAME)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <misc.au3>

$Main = GUICreate("Camera",700,270)
guisetbkcolor(0x000000)
GUISetState(@SW_SHOW)

;PONG SETUP
$xball = 0
$yball = 0
$direction = true;if true, going twords paddle, if false, going towards computer player
$boundaries = true;make ball bounce off walls
$xp1 = 0
$xcomp = 0
$vDll = 'user32.dll'
dim $points[2] = [0, 0]
$pointscore = guictrlcreatelabel("P1: " & $points[0] & " Computer: " & $points[1], 5, -1, 180, 12)
guictrlsetbkcolor($pointscore, 0xFFFFFF)
$p1 = guictrlcreategraphic(0, 0, 70, 5)
guictrlsetgraphic(-1, $GUI_GR_COLOR, 0x0000FF, 0x0000FF)
guictrlsetgraphic(-1, $GUI_GR_RECT, 80, 260, 55, 5)
guictrlsetgraphic(-1, $GUI_GR_REFRESH)
guictrlsetgraphic(-1, $GUI_GR_CLOSE)
$ball = guictrlcreategraphic(0, 0, 50, 50)
guictrlsetgraphic(-1, $GUI_GR_COLOR, 0xFFFF00, 0xFFFF00)
guictrlsetgraphic(-1, $GUI_GR_PIE, 10, 10, 5, 0, 360)
guictrlsetgraphic(-1, $GUI_GR_REFRESH)
guictrlsetgraphic(-1, $GUI_GR_CLOSE)
$computer = guictrlcreategraphic(0, 5, 70, 5)
guictrlsetgraphic(-1, $GUI_GR_COLOR, 0xFF0000, 0xFF0000)
guictrlsetgraphic(-1, $GUI_GR_RECT, 20, 10, 55, 5)
guictrlsetgraphic(-1, $GUI_GR_REFRESH)
guictrlsetgraphic(-1, $GUI_GR_CLOSE)
$easy = guictrlcreatebutton("Easy", 5, 5, 190, 50)
$medium = guictrlcreatebutton("Medium", 5, 55, 190, 50)
$hard = guictrlcreatebutton("Hard", 5, 105, 190, 50)
$impossible = guictrlcreatebutton("Impossible", 5, 155, 190, 50)
$game = 0
Do
    $msg = guigetmsg()
        if ($msg = $easy) Then
            $game = 0
        ElseIf ($msg = $medium) then
            $game = 1
        ElseIf ($msg = $hard) then
            $game = 2
        ElseIf ($msg = $impossible) Then
            $game = 3
        EndIf
Until (($msg = $easy) or ($msg = $medium) or ($msg = $hard) or ($msg = $impossible))
guictrldelete($easy)
guictrldelete($medium)
guictrldelete($hard)
guictrldelete($impossible)
if ($game = 0) Then
    $gf = 1
ElseIf ($game = 1) Then
    $gf = 1.4
ElseIf ($game = 2) Then
    $gf = 2
Else
    $gf = 4
EndIf
$g = $gf

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf

    
  $gf += .001
    guictrlsetgraphic($ball, $GUI_GR_REFRESH)
    $x = IniRead(@TempDir & "x.ini","x","x","10")
        guictrlsetpos($p1, $x, 0)
    if ($direction) Then
        $yball += $gf * 2
        guictrlsetpos($ball, $xball, $yball)
       ;guictrlsetgraphic(-1, $GUI_GR_REFRESH)
    Else
        $yball -= $gf * 2
        guictrlsetpos($ball, $xball, $yball)
       ;guictrlsetgraphic(-1, $GUI_GR_REFRESH)
        $aipos = $xball - 50
        if (($aipos > -15) and ($aipos < 120)) Then
            guictrlsetpos($computer,$aipos , 5)
           ;guictrlsetgraphic(-1, $GUI_GR_REFRESH)
        EndIf
    EndIf
    if ($boundaries) Then
        $xball += $gf * 3
        guictrlsetpos($ball, $xball, $yball)
       ;guictrlsetgraphic(-1, $GUI_GR_REFRESH)
    Else
        $xball -=  $gf * 3
        guictrlsetpos($ball, $xball, $yball)
       ;guictrlsetgraphic(-1, $GUI_GR_REFRESH)
    EndIf
    if ($xball > 180) Then $boundaries = False
    if ($xball < 0) then $boundaries = True
    if (($yball >= 244) and ($direction)) Then
       ;xball = 0, xp1 = -68
        $contact = Execute($xball - $xp1)
        if (($contact > 68) and ($contact < 123)) then 
            $direction = False
        Else
            $points[1] += 1
            $gf = $g
            guictrlsetdata($pointscore, "P1: " & $points[0] & " Computer: " & $points[1])
            $yball = 50
            $direction = False
        EndIf
    EndIf
    if (($yball <= 17) and (not($direction))) Then
        $contact = Execute($xball - $aipos)
        if (($contact < 60) and ($contact > 0)) Then
            $direction = True
        Else
            $points[0] += 1
            $gf = $g
            guictrlsetdata($pointscore, "P1: " & $points[0] & " Computer: " & $points[1])
            $yball = 50
            $direction = true
        EndIf
    EndIf
Wend

CODE 2 (WEBCAM)

$WM_CAP_START = 0x400
$WM_CAP_UNICODE_START = $WM_CAP_START +100
$WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
$WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
$WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
$WM_CAP_ABORT = $WM_CAP_START + 69
$WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
$WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
$WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
$WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
$WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
$WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
$WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
$WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
$WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
$WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
$WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
$WM_CAP_EDIT_COPY = $WM_CAP_START + 30
$WM_CAP_END = $WM_CAP_UNICODE_END
$WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
$WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
$WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
$WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
$WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
$WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
$WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
$WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
$WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
$WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
$WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
$WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
$WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
$WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
$WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
$WM_CAP_GET_STATUS = $WM_CAP_START + 54
$WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
$WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
$WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
$WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
$WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
$WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
$WM_CAP_PAL_OPENA = $WM_CAP_START + 80
$WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
$WM_CAP_PAL_PASTE = $WM_CAP_START + 82
$WM_CAP_SEQUENCE = $WM_CAP_START + 62
$WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
$WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
$WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
$WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
$WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
$WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
$WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
$WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
$WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
$WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
$WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
$WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
$WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
$WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
$WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
$WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
$WM_CAP_SET_SCALE = $WM_CAP_START + 53
$WM_CAP_SET_SCROLL = $WM_CAP_START + 55
$WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
$WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
$WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
$WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
$WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
$WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
$WM_CAP_STOP = $WM_CAP_START + 68

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#Include <Color.au3>

AutoItSetOption("PixelCoordMode", 2)
AutoItSetOption("MouseCoordMode", 2)

$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")

$Main = GUICreate("Camera",350,270)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 0, "int", 0, "int", 350, "int", 270, "hwnd", $Main, "int", 1)

DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)

GUISetState(@SW_SHOW)

While 1
        $temp = PixelSearch(1, 1, 349, 269, "0x000000", 50, 3, $main)
    If IsArray($temp) Then
        ToolTip("X=" & $temp[0] & " Y=" & $temp[1], 0, 0)
        $x = IniWrite(@TempDir & "x.ini","x","x", $temp[0]-100)
    Else
        ToolTip("NULL", 0, 0)
    EndIf
WEnd

Feel free to edit it to make it faster.

HOW TO PLAY:

Playing is simple, just download and print the attached image. Cut the image out and tape it to a white shirt. You will need a webcam to play, now is a good time to hook that up (assuming its not already). Now set your camera to a good zoom in so that the black dot is right in the center of the screen and all that is visible is the black dot and the white shirt.

Now start the program, remember that your motions are reverse of what you will see. To move your pattle, simply move your body left or right.

post-14679-1225679877_thumb.gif

Edited by keen

[center]Kesne's Bar & Grill[/center]

Share this post


Link to post
Share on other sites
torels

It's fantastic :mellow:

congratulations


Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites
keen

Lol, thanks, I'm working on a much faster version that keeps the webcam feed in a seperate program to keep the pong game running fast.

Hopefully I can get this more logical. I made a better version today using a different method, this new method works a little better and can find pixels better.


[center]Kesne's Bar & Grill[/center]

Share this post


Link to post
Share on other sites
crzftx

I don't get it, the webcam turned on, the ball started moving, but the paddle wouldnt move. I took a sharpie to a piece of white paper, so I don't know...

Share this post


Link to post
Share on other sites
keen

make sure that the webcam is zoomed in so that all that appears is the black on white, that is imprortant.

Also, try slow movments to see if it is working.


[center]Kesne's Bar & Grill[/center]

Share this post


Link to post
Share on other sites
keen

UPDATED:

Now uses two scripts to run faster. Control the games over twice as fast.


[center]Kesne's Bar & Grill[/center]

Share this post


Link to post
Share on other sites
keen

No other Comments?


[center]Kesne's Bar & Grill[/center]

Share this post


Link to post
Share on other sites
7h331337

u can cut down the amount of code and make it easer to read

im sure that their is a great webcam udf

p.s.

and how did you get this copyrighted anyone that has done a ping pong game using a webcam can just use pmc to prove that thy have a right to distribute that software

and..

i dnt mean to sound offensive if i do then im sorry:)

Edited by 7h331337

Share this post


Link to post
Share on other sites
keen

Im not sure that I understand your post.

The webcam script I used is the best I could find, there is no need to make it easier to read or smaller, it runs fine now.

I copyrighted the actual source code for LPT, not this game, and not the idea.

Hope that I understood your post correctly.

-Keen


[center]Kesne's Bar & Grill[/center]

Share this post


Link to post
Share on other sites
7h331337

Im not sure that I understand your post.

The webcam script I used is the best I could find, there is no need to make it easier to read or smaller, it runs fine now.

I copyrighted the actual source code for LPT, not this game, and not the idea.

Hope that I understood your post correctly.

-Keen

ye u understood perfectly i thought that u copyrighted the game lol it is a great script tho well done :)

Share this post


Link to post
Share on other sites
keen

Thank you. I should have some other small toys like this and hopefully I will have a full game using this coming out soon.


[center]Kesne's Bar & Grill[/center]

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  

×