using windows xp, panda 1.8.0
Im using PhaseSpace to capture motion and import to “virtual reality” set up. The capture freq of the MoCap is about 150 Hz while the game updates at a much slower rate. However, this is causing the framerate to lag.
I NEED to store the MoCap at the high frequency for post-game data analysis, so I cant slow the server down.
Preface: Im very new to python programming. if you reference certain calls, please include what their function is briefly, it would be much appreciated.
Ive tried threading, but cant quite get it working. I feel I need to have the collection function threaded versus the game, but dont know how to thread the entire game? if i even need to? just the task manager? just the one task that updates the frame?
Any ideas would be great, but keep in mind I need to keep data collection as high as possible, which I think should be kept outside of the main game, so it doesnt slow it down too much.
Thanks!
here is the code without any threading built in. is there a better way of handing the server information being brought in and the game updating?
import sys,os
from OWL import *
from math import pi, sin, cos, acos, atan, tan
from random import *
import time
from direct.task import Task
from direct.stdpy import thread
from direct.actor.Actor import Actor
from direct.gui.DirectGui import OnscreenText
from direct.showbase.ShowBase import ShowBase
from direct.showbase.DirectObject import DirectObject
from direct.interval.IntervalGlobal import *
from panda3d.core import *
from pandac.PandaModules import *
#-----------------------------------------
os.system('cls')
print Thread.isThreadingSupported()
MARKER_COUNT = 5
print "MARKER_COUNT: " , MARKER_COUNT
SERVER_NAME = "192.168.2.7"
print "Server: ", SERVER_NAME
INIT_FLAGS = 0
#quits if cant access the server
if(owlInit(SERVER_NAME, INIT_FLAGS) < 0):
print "init error: ", owlGetError()
sys.exit(0)
# create tracker 0
tracker = 0
owlTrackeri(tracker, OWL_CREATE, OWL_POINT_TRACKER)
# set markers
for i in range(MARKER_COUNT):
owlMarkeri(MARKER(tracker, i), OWL_SET_LED, i)
# activate tracker
owlTracker(tracker, OWL_ENABLE)
# flush requests and check for errors
if(owlGetStatus() == 0):
owl_print_error("error in point tracker setup", owlGetError())
sys.exit(0)
# set define frequency
owlSetFloat(OWL_FREQUENCY, OWL_MAX_FREQUENCY)
# start streaming
owlSetInteger(OWL_STREAMING, OWL_ENABLE)
global markers, streaming, n, xCal, yCal, zCal, dtext
markers = []
digits={}
streaming=0
n=[]
xCal=0
yCal=0
zCal=0
camMove=1
updateTrackers=0
updateText=0
DO=DirectObject()
#---------------------------
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.dtext={'digitNumber':'text'}
base.disableMouse()
for i in range(MARKER_COUNT):
self.dtext[i]=self.genLabelText("Digit_"+str(i+1)+": ",3+i)
self.calText=self.genLabelText("xCal:" + str(xCal)+ ", yCal: " + str(yCal) +", zCal: " + str(zCal),2)
self.genLabelText("Press 'esc' to quit",0)
self.genLabelText("q: streamPS, w:updateText e:loadFingers, r:calibrate, t:fixCamera",1)
self.fpstext=self.genLabelText("FPS: ",10)
DO.accept("escape", self.endProgram)
DO.acceptOnce("q", self.startstreamPS)
DO.accept("w", self.startupdateText)
DO.accept("e", self.loadFingers,[MARKER_COUNT])
DO.accept("r", self.calibrate)
DO.accept("t", self.fixCamera)
self.timeS=time.time()
def genLabelText(self, text, i):
return OnscreenText(text = text, pos = (-1.2, .95-.05*i), fg=(1,1,0,1), align = TextNode.ALeft, scale = .05)
def startstreamPS(self):
print("stream started")
self.taskMgr.add(self.streamPS,"streamPS")
def startupdateText(self):
global updateText
updateText=1
def loadFingers(self, MARKER_COUNT):
global updateTrackers, digits
tip = loader.loadModel("models/ball.egg.pz")
for i in range(MARKER_COUNT):
tipN=NodePath('tipN')
tipN.reparentTo(render)
digits[i]=tip.copyTo(tipN)
digits[i].setPos(i,0,0)
digits[i].setScale(.5,.5,.5)
updateTrackers=1
def calibrate(self):
global markers, xCal, yCal, zCal, n
if n >0:
xCal=markers[1].x
yCal=-markers[1].z
zCal=markers[1].y
self.calText.setText("xCal:" + str(xCal)+ ", yCal: " + str(yCal) +", zCal: " + str(zCal))
def fixCamera(self):
global camMove
camMove=0
self.camera.setPos(0,-15,10)
self.camera.lookAt(0,0,0)
def streamPS(self, task):
global xCal, yCal, zCal, markers, n, MARKER_COUNT, updateTrackers, updateText, camMove
markers = []
n=owlGetMarkers(markers, 32)
if n==MARKER_COUNT:
color=(0,255,0)
if updateTrackers>0:
for i in range(n):
if markers[i].cond>0:
digits[i].setPos((markers[i].x-xCal)/50,(-markers[i].z-yCal)/50,(markers[i].y-zCal)/50)
if camMove>0:
self.camera.setPos(digits[1].getX(),-digits[1].getZ()-50,digits[1].getY()+50)
self.camera.lookAt(digits[1].getPos())
if updateText>0:
for i in range(n):
self.dtext[i].setText("Digit_"+str(i+1)+": "+str(['%.2f' % markers[i].x]) + ' ' + str(['%.2f' % markers[i].y]) + ' ' + str(['%.2f' % markers[i].z]) )
fps=1/(time.time()-self.timeS+0.000000001)
self.timeS=time.time()
self.fpstext.setText("FPS: " + str(fps))
return Task.cont
def endProgram(self):
print("end")
owlDone()
sys.exit()
app = MyApp()
app.run()