Face detect and UDP

Blitz3D Forums/Blitz3D Userlibs/Face detect and UDP

i made a pong game you control with your face :)

here is the code.. very basic and messy tho :( I am trying to make a callibrator for each kind of camera. you may have to tweak this code to make it work for your camera..

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Graphics 640,480,0,1
AppTitle "Face UDP Detect 3D "
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Face UDP (c) zjp+++++++++++++++++++++++++++++++++++++++++
Global recu$
Global UDP_Serveur
Global VX=160
Global VY=120
Global VR=50
Global TX#
Global TY#
Global RX#,RY#,RR#,OX#,OY#
Global chng
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; UDP read face detect
Function recu_UDP()
	;recu$=""
	IP_Client = RecvUDPMsg(UDP_Serveur)
	If IP_Client Then 
		chng = 1
		recu$ = ReadLine(UDP_Serveur)
		; parce
		; found X
		i=Instr(recu$,"X(",1)+2
		C$=Mid$(recu$,i,4)
		VX=C$
		; found Y
		i=Instr(recu$,"Y(",1)+2
		C$=Mid$(recu$,i,4)
		VY=C$
		; found R
		i=Instr(recu$,"R(",1)+2
		C$=Mid$(recu$,i,4)
		VR=C$
	End If 
	If chng = 1 Then
    ox# = rx#
    oy# = ry#
    EndIf
	rx# = -vx + 353
	ry# = -vy + 223
	rr# = vr
	If chng = 1 Then
		tx# = rx#
		ty# = ry#
	Else
;		tx# = tx# + (rx#-ox#)/80
	;	ty# = ty# + (ry#-oy#)/80
	EndIf
	chng = 0
End Function
UDP_Serveur = CreateUDPStream(26000) ; <<<<<<< Quake UDP PORT ;-)
If UDP_Serveur <>0 Then 
	Print "Server Start."
Else
	Print "Can't start Server"
	End
End If
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SetBuffer BackBuffer()
Global px = 720
Global bx,by,bdx,bdy
bx = 320
by = 240
bdx = Rnd(-2,2)
bdy = Rnd(-3,-1)
;
;
Repeat
  Cls
	If tx > 50 Then
	px = px + (tx-50)/50+2
	EndIf
	If tx < -50 Then
	px = px + (tx+50)/50-2
	EndIf
	If px < 0 Then px = 0
	If px > 560 Then px = 560
	
	bx = bx + bdx
	by = by + bdy
	
	If by < 0 Then bdy = -bdy
	If bx < 0 Then bdx = -bdx
	If by > 480 Then bdy = -bdy
	If bx > 640 Then bdx = -bdx
	If by > 449 And by < 453 And bx > px And bx < px+80 Then bdy = -bdy
	
	Rect px,450,80,10
	Oval bx-5,by-5,10,10,1
	

	Text 10,10,"Face x "+Int(tX)+", Face Y "+Int(tY)+", Face Radius "+VR
	Flip
	recu_UDP
Until KeyHit(1)=1

CloseUDPStream(UDP_Serveur)
End


can someone test this to see if it works the same on every computer. Just move your face left and right and it moves the pong paddle :)

Need some help to build a "fantastic" demo with Blitz3D. I'm not a ... Blitz3D guru ;-)



@ZJP - i will help if you want me to... wow i have made at least 3 of my previous games head controlled :) this is fun