From c378d236bbda3771310477c5e1965c4ba725a27f Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 26 Dec 2016 22:31:41 -0800 Subject: [PATCH] make the event fields understandable --- examples/pybullet/vrEvent.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/examples/pybullet/vrEvent.py b/examples/pybullet/vrEvent.py index 4112defd9..df80e461b 100644 --- a/examples/pybullet/vrEvent.py +++ b/examples/pybullet/vrEvent.py @@ -1,10 +1,14 @@ -#See pybullet quickstart guide here: -#https://docs.google.com/document/d/10sXEhzFRSnvFcl3XxNGhnD4N2SedqwdAvK3dsihxVUA/edit# - +# See pybullet quickstart guide here: +# https://docs.google.com/document/d/10sXEhzFRSnvFcl3XxNGhnD4N2SedqwdAvK3dsihxVUA/edit# # Create a Tiltbrush-like app, drawing lines using any controller # Line width can be changed import pybullet as p + +CONTROLLER_ID = 0 +POSITION=1 +BUTTONS=6 + #assume that the VR physics server is already started before p.connect(p.SHARED_MEMORY) p.setInternalSimFlags(0)#don't load default robot assets etc @@ -27,27 +31,27 @@ while True: events = p.getVREvents() for e in (events): - if (e[6][33]&2): - prev[e[0]] = e[1] - if (e[6][32]&2): - widths[e[0]]=widths[e[0]]+1 - if (widths[e[0]]>20): - widths[e[0]] = 1 - if (e[6][1]&2): + if (e[BUTTONS][33]&2): + prev[e[CONTROLLER_ID]] = e[POSITION] + if (e[BUTTONS][32]&2): + widths[e[CONTROLLER_ID]]=widths[e[0]]+1 + if (widths[e[CONTROLLER_ID]]>20): + widths[e[CONTROLLER_ID]] = 1 + if (e[BUTTONS][1]&2): p.resetSimulation() #p.setGravity(0,0,-10) p.removeAllUserDebugItems() p.loadURDF("plane.urdf") - if (e[6][33]==1): - pt = prev[e[0]] + if (e[BUTTONS][33]==1): + pt = prev[e[CONTROLLER_ID]] #print(prev[e[0]]) #print(e[1]) - diff = [pt[0]-e[1][0],pt[1]-e[1][1],pt[2]-e[1][2]] + diff = [pt[0]-e[POSITION][0],pt[1]-e[POSITION][1],pt[2]-e[POSITION][2]] lenSqr = diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2] ptDistThreshold = 0.01 if (lenSqr>(ptDistThreshold*ptDistThreshold)): - p.addUserDebugLine(e[1],prev[e[0]],colors[e[0]],widths[e[0]]) + p.addUserDebugLine(e[POSITION],prev[e[CONTROLLER_ID]],colors[e[CONTROLLER_ID]],widths[e[CONTROLLER_ID]]) #p.loadURDF("cube_small.urdf",e[1]) - colors[e[0]] = [1-colors[e[0]][0],1-colors[e[0]][1],1-colors[e[0]][2]] - prev[e[0]] = e[1] \ No newline at end of file + colors[e[CONTROLLER_ID]] = [1-colors[e[CONTROLLER_ID]][0],1-colors[e[CONTROLLER_ID]][1],1-colors[e[CONTROLLER_ID]][2]] + prev[e[CONTROLLER_ID]] = e[POSITION] \ No newline at end of file