I am trying to work that FACEAPI integration for headtracking via streaming position and orientation data from a socket and can't quite get it to work.
Could you look over my code and let me know what I may be doing wrong? The socket works and I can access the data, but I can't seem to get it to apply to my viewpoint.
Thanks,
-Adam
Code:
# Import Modules
import viz
from socket import *
import string
import math
# Set Global Variables
global host
global port
global buf
global addr
global HeadPos
global HeadRot
global pos
global euler
global view
# Run Vizard in Fullscreen
viz.go()
view = viz.MainView
viz.mouse(viz.OFF)
viz.mouse.setVisible(False)
# Load vrml and locate objects
viz.add('tut_ground.wrl')
pole = viz.add('pole.wrl')
pole.setPosition(0,0,4)
# Set the socket parameters
host = "localhost"
port = 29129
buf = 1024
addr = (host,port)
# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
# Receive messages
while 1:
data,addr = UDPSock.recvfrom(buf)
if not data:
print "Client has exited!"
break
else:
#print "\nReceived message '", data,"'"
cp = str(data).split(' ')
headposx = cp[0]
headposx = float(headposx)
headposy = cp[1]
headposy = float(headposy)
headposz = cp[2]
headposz = float(headposz)
headrotx = cp[3]
headrotx = float(headrotx)
headroty = cp[4]
headroty = float(headroty)
headrotz = cp[5]
headrotz = float(headrotz)
HeadPos = [headposx , headposy , headposz]
print "\nHeadPos = ", HeadPos,"'"
HeadRot = [headrotx , headroty , headrotz]
print "\nHeadRot = ", HeadRot,"'"
updateview()
# Close socket
UDPSock.close()
def updateview():
viz.reset(viz.HEAD_ORI|viz.BODY_ORI|viz.HEAD_POS)
#update orientation
euler = view.getEuler(viz.Head_ORI)
euler[0] += HeadRot[0]
euler[1] += HeadRot[1]
euler[2] += HeadRot[2]
print "\nEuler = ", euler
view.setEuler(euler,viz.Head_ORI)
#update position
pos = view.getPosition(viz.Head_POS)
pos[0] += HeadPos[0]
pos[1] += HeadPos[1]
pos[2] += HeadPos[2]
print "\nPosition = ", pos
view.setPosition(pos[0],pos[1],pos[2])
vizact.ontimer(0,updateview)