import string, urllib2, urllib from math import * from pyglet.gl import * from wfobject import * dbserver = 'http://gamera.caset.buffalo.edu/~depape/' myDatabaseID = urllib2.urlopen(dbserver + 'newcow.php','data=pos+0+0+0+head+0').read() window = pyglet.window.Window() keys = pyglet.window.key.KeyStateHandler() window.push_handlers(keys) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) myPos = [ -50, 0, 0 ] myHeading = 0 otherPos = [ 50, 0, 0 ] otherHeading = 0 cow1 = WFObject('cow.obj') cow2 = WFObject('cow.obj') @window.event def on_draw(): glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60.0, 1, 0.1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotatef(90, 1, 0, 0) glTranslatef(0, -100, 0) glPushMatrix() glTranslatef(myPos[0], myPos[1], myPos[2]) glRotatef(myHeading, 0, 1, 0) cow1.draw() glPopMatrix() glPushMatrix() glTranslatef(otherPos[0], otherPos[1], otherPos[2]) glRotatef(otherHeading, 0, 1, 0) cow2.draw() glPopMatrix() def update(dt): global myHeading, myPos, otherHeading, otherPos changed = False if keys[pyglet.window.key.LEFT]: myHeading += 90 * dt changed = True if keys[pyglet.window.key.RIGHT]: myHeading -= 90 * dt changed = True if keys[pyglet.window.key.UP]: myPos[0] += 10 * dt * cos(radians(myHeading)) myPos[2] -= 10 * dt * sin(radians(myHeading)) changed = True if keys[pyglet.window.key.DOWN]: myPos[0] -= 10 * dt * cos(radians(myHeading)) myPos[2] += 10 * dt * sin(radians(myHeading)) changed = True if changed: data = 'pos %f %f %f head %f' % (myPos[0], myPos[1], myPos[2], myHeading) urllib2.urlopen(dbserver + 'cowpost.php',urllib.urlencode({'id':myDatabaseID, 'data':data})).read() indata = urllib2.urlopen(dbserver + 'cowget.php?myid=' + myDatabaseID).read() for d in indata.splitlines(): val = string.split(d) otherPos[0] = float(val[2]) otherPos[1] = float(val[3]) otherPos[2] = float(val[4]) otherHeading = float(val[6]) pyglet.clock.schedule_interval(update,1/30.0) pyglet.app.run()