draw the stickman agk
// Project: fata grab
// Created: 2020-02-05
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "kenect game empty" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
SetPrintSize(30)
SetPrintColor(100,0,0,200)
Create3DPhysicsWorld(10)
dim points[20]
dim a$[2000]
global tim
global string$
global dosock
global scale
SCALE=10
string$=GetDeviceIP()
runapp("\media\kinect stick man\kinect.exe","")
CreateSocketListener(1,string$,27015)
//runapp("\media\kinect stick man\kinect.exe","")
//runapp("kinect just data\kinect.exe","")
repeat
print(string$)
print("hello")
temp=GetSocketListenerConnection(1)
if temp<>0
dosock= ConnectSocket( string$ ,27015, 21500 )
a=GetSocketConnected(dosock)
endif
print(temp)
print(dosock)
sync()
until dosock<>0
dec dosock,1
for t=1 to 20
points[t]=CreateObjectCylinder(1,2,32)
RotateObjectLocalX(points[t],90)
FixObjectPivot(points[t])
SetObjectColor(points[t],0,200,0,200)
SetObjectCollisionMode(points[t],0)
Create3DPhysicsKinematicBody(points[t])
next
deleteobject(points[4])
points[4]=CreateObjectSphere(5,32,32)
SetObjectColor(points[4],0,200,0,200)
SetObjectCollisionMode(points[4],0)
Create3DPhysicsKinematicBody(points[4])
dim pos_y[20] as float
dim pos_z[20] as float
dim pos_x[20] as float
global Kinect_head as integer
global Kinect_spine as integer
global Kinect_shoulder_center as integer
global Kinect_shoulder_left as integer
global Kinect_shoulder_right as integer
global Kinect_left_elbow as integer
global Kinect_right_elbow as integer
global Kinect_left_wrist as integer
global Kinect_right_wrist as integer
global Kinect_lh as integer
global Kinect_rh as integer
global Kinect_hip_centre as integer
global Kinect_hip_left as integer
global Kinect_hip_right as integer
global Kinect_left_knee as integer
global Kinect_right_knee as integer
global Kinect_left_ankel as integer
global Kinect_right_ankel as integer
global Kinect_left_foot as integer
global Kinect_right_foot as integer
global cx#=0
global cz#=0
global firstrun=0
global c
global lenth
dis=0
global dot
dot=CreateObjectSphere(0.1,32,32)
AddVirtualButton(1,70,70,140)
SetVirtualButtonText(1,"disconect")
piv=CreateObjectSphere(0.1,32,32)
LoadImage(5,"FloatingIsland_Small.png")
LoadObject(5,"FloatingIsland_Small.x")
SetObjectImage(5,1,0)
SetObjectScale(5,0.1,0.1,0.1)
FixObjectToObject(5,piv)
MoveObjectLocalY(5,0.2)
SetPrintSize(80)
SetPrintColor(255,255,255)
dim ox[20] as float
dim oy[20] as float
dim oz[20] as float
dim old[20] as float
do
if dis=0
Kinect()
endif
if GetVirtualButtonPressed(1)
SendSocketByte(dosock,asc("h"))
SendSocketByte(dosock,asc("e"))
SendSocketByte(dosock,asc("l"))
SendSocketByte(dosock,asc("l"))
SendSocketByte(dosock,asc("o"))
FlushSocket(dosock)
dis=1
endif
if cx#<pos_x[3] then cx#=cx#+0.1
if cx#>pos_x[3] then cx#=cx#-0.1
if cz#<pos_z[3] then cz#=cz#+0.1
if cz#>pos_z[3] then cz#=cz#-0.1
print(c)
print(lenth)
if firstrun=0
cz#=pos_z[3]
firstrun=1
endif
SetCameraPosition(1,0,pos_y[3],-cz#-30)
SetCameraLookAt(1,cx#,pos_y[3],cz#,0)
Sync()
loop
function Kinect()
for t=1 to 20
a$[t]=""
next
lenth=GetSocketBytesAvailable(dosock)
if lenth>2
oldc=c
for t=1 to lenth
tem=GetSocketByte(dosock)
ll$=chr(tem)
t9$=ll$
if t9$="a" // Hip_Center
c=1
Kinect_hip_centre=1
g$=t9$
endif
if t9$="b" //Spine
c=2
g$=t9$
Kinect_spine=2
endif
if t9$="c" // Shoulder_Center
c=3
g$=t9$
Kinect_shoulder_center=3
endif
if t9$="d" // Head
c=4
g$=t9$
Kinect_head=4
endif
if t9$="e" //Shoulder_Left
c=5
g$=t9$
Kinect_shoulder_left=5
endif
if t9$="f" // Elbow_Left
c=6
g$=t9$
Kinect_left_elbow=6
endif
if t9$="g" //Wrist_Left
c=7
g$=t9$
Kinect_left_wrist=7
endif
if t9$="h" //Hand_Left
c=8
g$=t9$
Kinect_lh=8
endif
if t9$="i" //Shoulder_Right Shoulder_Right
c=9
g$=t9$
Kinect_shoulder_right=9
endif
if t9$="j" // Elbow_Right
c=10
g$=t9$
Kinect_right_elbow=10
endif
if t9$="k" //Wrist_Right
c=11
g$=t9$
Kinect_right_wrist=11
endif
if t9$="l" //Hand_Right
Kinect_rh=12
c=12
g$=t9$
endif
if t9$="m" //Hip_Left
c=13
g$=t9$
Kinect_hip_left=13
endif
if t9$="n" // Knee_Left
c=14
g$=t9$
Kinect_left_knee=14
endif
if t9$="o" // Ankle_Left
c=15
g$=t9$
Kinect_left_ankel=15
endif
if t9$="p" // Foot_Left
c=16
g$=t9$
Kinect_left_foot=16
endif
if t9$="q" //Hip_Right
c=17
g$=t9$
Kinect_hip_right=17
endif
if t9$="r" // Knee_Right
c=18
g$=t9$
Kinect_right_knee=18
endif
if t9$="s" // Ankle_Right
c=19
g$=t9$
Kinect_right_ankel=19
endif
if t9$="t" // Foot_Right
c=20
g$=t9$
Kinect_right_foot=20
endif
A$[c]=A$[c]+chr(tem)
if T9$="E"
FlushSocket(dosock)
temp1$=ReplaceString(a$[c],g$,"",1)
temp$=ReplaceString(temp1$,"e","",1)
f=FindString(temp$,"Y")
t$=left(temp$,f-1)
b$=ReplaceString(t$,"X","",1)
f1=FindString(temp$,"Z")
t1$=right(temp$,len(temp$)-f1+1)
b1$=ReplaceString(t1$,"Z","",1)
f=FindString(temp$,"Y")
c1$=ReplaceString(temp$,t$,"",1)
c2$=ReplaceString(c1$,t1$,"",1)
c3$=ReplaceString(c2$,"Y","",1)
x#=ValFloat(b$)
y#=ValFloat(c3$)
z#=ValFloat(b1$)
ox[c]=pos_x[c]
oy[c]=pos_y[c]
oz[c]=pos_z[c]
pos_x[c]=ValFloat(b$)*scale
pos_y[c]=ValFloat(c3$)*scale
pos_z[c]=ValFloat(b1$)*scale
ENDIF
next
endif
FOR Q=1 TO 20
//if oy[q]<>pos_y[q]
SetObjectPosition(points[Q],pos_x[Q],pos_y[Q],-pos_z[Q])
//endif
NEXT
draw_line()
FlushSocket(dosock)
endfunction
function draw_line()
x#=pos_x[Kinect_head]
y#=pos_y[Kinect_head]
z#=-pos_z[Kinect_head]
x1#=pos_x[Kinect_shoulder_center]
y1#=pos_y[Kinect_shoulder_center]
z1#=-pos_z[Kinect_shoulder_center]
SetObjectPosition(dot,x1#,y1#,z1#)
hit=ObjectRayCast(0,x#,y#,z#,x1#,y1#,z1#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
//SetObjectPosition(points[Kinect_head],pos_x[Kinect_head],pos_y[Kinect_head],-pos_z[Kinect_head])
SetObjectLookAt(points[Kinect_head],x1#,y1#,z1#,0)
//SetObjectScale(points[Kinect_head],1,1,dis#)
MoveObjectLocalZ(points[Kinect_head],-2)
endif
//#######################################################################
x#=pos_x[Kinect_shoulder_center]
y#=pos_y[Kinect_shoulder_center]
z#=-pos_z[Kinect_shoulder_center]
x1#=pos_x[Kinect_shoulder_right]
y1#=pos_y[Kinect_shoulder_right]
z1#=-pos_z[Kinect_shoulder_right]
SetObjectPosition(dot,x#,y#,z#)
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
SetObjectLookAt(points[Kinect_shoulder_right],x#,y#,z#,0)
SetObjectScale(points[Kinect_shoulder_right],1,1,dis#)
MoveObjectLocalZ(points[Kinect_shoulder_right],dis#/2)
endif
//#######################################################################
x#=pos_x[Kinect_shoulder_right]
y#=pos_y[Kinect_shoulder_right]
z#=-pos_z[Kinect_shoulder_right]
x1#=pos_x[Kinect_right_elbow]
y1#=pos_y[Kinect_right_elbow]
z1#=-pos_z[Kinect_right_elbow]
SetObjectPosition(dot,x#,y#,z#)
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
SetObjectLookAt(points[Kinect_right_elbow],x#,y#,z#,0)
SetObjectScale(points[Kinect_right_elbow],1,1,dis#)
MoveObjectLocalZ(points[Kinect_right_elbow],dis#/2)
endif
//#######################################################################
x#=pos_x[Kinect_right_elbow]
y#=pos_y[Kinect_right_elbow]
z#=-pos_z[Kinect_right_elbow]
x1#=pos_x[Kinect_right_wrist]
y1#=pos_y[Kinect_right_wrist]
z1#=-pos_z[Kinect_right_wrist]
SetObjectPosition(dot,x#,y#,z#)
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
SetObjectLookAt(points[Kinect_right_wrist],x#,y#,z#,0)
SetObjectScale(points[Kinect_right_wrist],1,1,dis#)
MoveObjectLocalZ(points[Kinect_right_wrist],dis#/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
x#=pos_x[Kinect_shoulder_center]
y#=pos_y[Kinect_shoulder_center]
z#=-pos_z[Kinect_shoulder_center]
x1#=pos_x[Kinect_shoulder_left]
y1#=pos_y[Kinect_shoulder_left]
z1#=-pos_z[Kinect_shoulder_left]
SetObjectPosition(dot,x#,y#,z#)
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
SetObjectLookAt(points[Kinect_shoulder_left],x#,y#,z#,0)
SetObjectScale(points[Kinect_shoulder_left],1,1,dis#)
MoveObjectLocalZ(points[Kinect_shoulder_left],dis#/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
x#=pos_x[Kinect_shoulder_left]
y#=pos_y[Kinect_shoulder_left]
z#=-pos_z[Kinect_shoulder_left]
x1#=pos_x[Kinect_left_elbow]
y1#=pos_y[Kinect_left_elbow]
z1#=-pos_z[Kinect_left_elbow]
SetObjectPosition(dot,x#,y#,z#)
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
SetObjectLookAt(points[Kinect_left_elbow],x#,y#,z#,0)
SetObjectScale(points[Kinect_left_elbow],1,1,dis#)
MoveObjectLocalZ(points[Kinect_left_elbow],dis#/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_left_elbow
b=Kinect_left_wrist
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
SetObjectLookAt(points[b],x#,y#,z#,0)
SetObjectScale(points[b],1,1,dis#)
MoveObjectLocalZ(points[b],dis#/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_hip_centre
b=Kinect_hip_right
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if dis#>0 and dis#<100
SetObjectLookAt(points[b],x#,y#,z#,0)
SetObjectScale(points[b],1,1,dis#)
MoveObjectLocalZ(points[b],dis#/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_hip_right
b=Kinect_right_knee
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if hit<>0
if dis#>0 and dis#<100
old[b]=dis#
SetObjectLookAt(points[b],x#,y#,z#,0)
endif
endif
if GetObjectExists(points[b])
SetObjectScale(points[b],1,1,old[b])
MoveObjectLocalZ(points[b],old[b]/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_right_knee
b=Kinect_right_ankel
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if hit<>0
if dis#>0 and dis#<100
old[b]=dis#
SetObjectLookAt(points[b],x#,y#,z#,0)
endif
endif
if GetObjectExists(points[b])
SetObjectScale(points[b],1,1,old[b])
MoveObjectLocalZ(points[b],old[b]/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_hip_centre
b=Kinect_hip_left
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if hit<>0
if dis#>0 and dis#<100
old[b]=dis#
SetObjectLookAt(points[b],x#,y#,z#,0)
endif
endif
if GetObjectExists(points[b])
SetObjectScale(points[b],1,1,old[b])
MoveObjectLocalZ(points[b],old[b]/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_hip_left
b=Kinect_left_knee
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if hit<>0
if dis#>0 and dis#<100
old[b]=dis#
SetObjectLookAt(points[b],x#,y#,z#,0)
endif
endif
if GetObjectExists(points[b])
SetObjectScale(points[b],1,1,old[b])
MoveObjectLocalZ(points[b],old[b]/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_left_knee
b=Kinect_left_ankel
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if hit<>0
if dis#>0 and dis#<100
old[b]=dis#
SetObjectLookAt(points[b],x#,y#,z#,0)
endif
endif
if GetObjectExists(points[b])
SetObjectScale(points[b],1,1,old[b])
MoveObjectLocalZ(points[b],old[b]/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_left_ankel
b=Kinect_left_foot
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if hit<>0
if dis#>0 and dis#<100
old[b]=dis#
SetObjectLookAt(points[b],x#,y#,z#,0)
endif
endif
if GetObjectExists(points[b])
//SetObjectScale(points[b],1,1,old[b])
MoveObjectLocalZ(points[b],-old[b]/2)
endif
//##################################################################################
//##################################################################################
//##################################################################################
a=Kinect_right_ankel
b=Kinect_right_foot
x#=pos_x[a]
y#=pos_y[a]
z#=-pos_z[a]
SetObjectPosition(dot,x#,y#,z#)
x1#=pos_x[b]
y1#=pos_y[b]
z1#=-pos_z[b]
hit=ObjectRayCast(0,x1#,y1#,z1#,x#,y#,z#)
dis#=GetObjectRayCastDistance(0)
if hit<>0
if dis#>0 and dis#<100
old[b]=dis#
SetObjectLookAt(points[b],x#,y#,z#,0)
endif
endif
if GetObjectExists(points[b])
//SetObjectScale(points[b],1,1,old[b])
MoveObjectLocalZ(points[b],-old[b]/2)
endif
SetObjectPosition(dot,0,-1000,0)
endfunction