Skip to content

Wand Quick Start Guide

Arthur Nishimoto edited this page Aug 23, 2013 · 5 revisions

Last revision: ver. 1.0 - 23 August 2013

This page will provide a quick overview of programming the Wand interface for Omegalib applications. The Wand, like the other interaction devices uses Omicron's event structure. The Wand is a combination of two input services - a Mocap service and a Controller service. Typically these are the VRPNService for motion tracker data and the XInputService for controller input.

Wand Event Structure

Also see Wand Service and Event Reference

Selected general event fields

  • sourceId: Unique identifier for the Wand.
  • The first activated wand will be ID 0, second wand ID 1, etc.
  • The MocapID for the 'Batman' wand is 1, 'Robin' is 2, Head tracker is 0
  • Note: The Wand's sourceID will match it's assigned controller sourceID
  • i.e. The 'Batman' mocap ID is 1, but the Wand ID is 0.
  • If the controllers are not activated in order, the IDs may be off
  • position: Mocap position as a Vector3
  • orientation: Mocap orientation as a Quaternion

PS3 Navigation controller fields

  • ExtraDataFloat 0: Left Analog Stick (-left, +right)
  • ExtraDataFloat 1: Left Analog Stick (-up, +down)
  • ExtraDataFloat 4: Analog Trigger L2 (0.0 to 1.0)

PS3 Navigation controller flags

  • ButtonUp: D-pad Up
  • ButtonRight: D-pad Right
  • ButtonDown: D-pad Down
  • ButtonLeft: D-pad Left
  • Button 2: Circle (Right button)
  • Button 3: Cross (Left button)
  • Button 5: Left Shoulder Button (L1)
  • Button 6: Left Analog Stick Button (L3)
  • Button 7: Left Analog Trigger ( Value > 0.5 ) (L2)

Python example

from math import *
from euclid import *
from omega import *
from cyclops import *

def onEvent():

	# Get an event
	e = getEvent()
	
	# If we want to check multiple controllers or other tracked objects,
	# we could also check the sourceID of the event
	sourceID = e.getSourceId()
	
	# Check to make sure the event we're checking is a Wand event
	if(e.getServiceType() == ServiceType.Wand):

		# If a button is pressed down do something
		if(e.isButtonDown( EventFlags.Button3 )): # Cross
			print("Wand ", sourceID, "Left button pressed")
		if(e.isButtonDown( EventFlags.Button2 )): # Circle
			print("Wand ", sourceID, "Right button pressed")
		if(e.isButtonDown( EventFlags.ButtonUp )): # D-Pad up
			print("Wand ", sourceID, "D-Pad up pressed")
		if(e.isButtonDown( EventFlags.ButtonDown )): # D-Pad down
			print("Wand ", sourceID, "D-Pad down pressed")
		if(e.isButtonDown( EventFlags.ButtonLeft )): # D-Pad left
			print("Wand ", sourceID, "D-Pad left pressed")
		if(e.isButtonDown( EventFlags.ButtonRight )): # D-Pad right
			print("Wand ", sourceID, "D-Pad right pressed")
		if(e.isButtonDown( EventFlags.Button6 )): # Analog stick button (L3)
			print("Wand ", sourceID, "L3 button pressed")
			
		# If L1 is pressed print mocap data
		if(e.isButtonDown( EventFlags.Button5 )): # L1 button
			print("Wand ", sourceID, " position: ", e.getPosition() )
			print("Wand ", sourceID, " orientation: ", e.getOrientation() )
			
		# Button7 is a special case, L2 is an analog trigger whose values
		# are accessed below.
		# As a shortcut Button7 will be triggered if L2 has a value greater than 0.5
		if(e.isButtonDown( EventFlags.Button7 )): # Analog Trigger (L2)
			print("Wand ", sourceID, "L2 button pressed")
			
		# Grab the analog stick vertical axis
		analogUD = e.getAxis(0)

		# Grab the analog stick horizontal axis
		analogLR = e.getAxis(1)

		if( (analogUD + analogLR) > 0.001 or  (analogUD + analogLR) < -0.001 ):
			print("Wand ", sourceID, "Analog stick: ", analogUD, " ", analogLR)
			
		## Grab the analog trgger
		analogL2 = e.getAxis(4)
		
		if( analogL2 > 0.001 ):
			print("Wand ", sourceID, "Analog trigger L2: ", analogL2 )
			
	elif(e.getServiceType() == ServiceType.Mocap):
		print("Trackable ", sourceID, " position: ", e.getPosition() )
		print("Trackable ", sourceID, " orientation: ", e.getOrientation() )
#--------------------------------------------------------------------------------------------------
# Register our onEvent function with Omegalib
setEventFunction(onEvent)
Clone this wiki locally