View Single Post
  #2  
Old 10-03-2011, 03:30 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Hello Steve,

Here is an example showing how to create 2 GrabHand objects. You'll see from the GrabHand constructor, it has 2 dependencies:
-- a list of 3D nodes with physics shapes to grab
-- A hand object
---- Hand objects depend on having a InputSensor object that detects user input

The first half of the code sets up a local GrabHand controlled by the mouse. The second half is a code outline for setting up a remotely controlled hand.

Code:
import viz
viz.go()
viz.phys.enable() #must enable physics for grab to work
viz.add('lab.osgb')
viz.MainView.setPosition([0, 1.8, -2])

#objects to grab
grabObjects = []
for i in range(10):
	box = viz.add('box.wrl', pos=[i/2.0, 1.7, i])
	box.collideBox() #must have physics shape to grab
	box.disable(viz.DYNAMICS) #no need for gravity
	box.grabbed = 0
	grabObjects.append(box)

#LOCAL HAND
#hand object that supplies user input: grabbing or not
import hand
mouseButtonControl = hand.MultiInputSensor(pinchButtons=[viz.MOUSEBUTTON_LEFT,viz.MOUSEBUTTON_RIGHT], fistButtons=[viz.MOUSEBUTTON_MIDDLE])
localHand = hand.add(mouseButtonControl)

#move hand position
import vizuniverse
handTracker = vizuniverse.VUTrackerMouse2D() #just a 3D node to supply position and orientation for hand.
viz.link(handTracker, localHand)

import GrabHand
GrabHand.GrabHand(grabObjects, localHand, springs=False) #springs only work on dynamics enabled physics shapes


#TODO FOR REMOTE HAND CONTROLLED VIA NETWORK
# Create local hand input object:
networkHandInput = hand.MultiInputSensor()
def onStartGrabFromNetworkEvent(): #called via network event callback, say viz.NETWORK_EVENT
	networkHandInput.startPinch()
def onEndGrabFromNetworkEvent(): #called via network event callback, say viz.NETWORK_EVENT
	networkHandInput.endPinch()
	
#create hand object
remoteHand = hand.add(networkHandInput)

# Get 3D position of remote hand
vrpn = viz.add('vrpn7.dle')
remoteHandTracker = vrpn.addTracker('Tracker0@localhost', 0)
viz.link(remoteHandTracker, remoteHand)

#create grabhand object
import GrabHand
GrabHand.GrabHand(grabObjects, remoteHand, springs=False) #springs only work on dynamics enabled physics shapes

WorldViz is still working to officially fold-in the two modules you mentioned so docs/examples are still sparse. Happy to provide more explanation if needed.

On the networking architecture side, I think your project is simple enough to just use a 'peer to peer' design where all clients hold the same representation of the world. The Tutorial:Networking in the Vizard help is an example of this. When world behavior is not deterministic, like with dynamic physics, then you should setup a client/server architecture. The viznet library in the install will help with this and I attached a zip with examples.
Attached Files
File Type: zip networking examples.zip (7.4 KB, 741 views)
__________________
Paul Elliott
WorldViz LLC
Reply With Quote