-
Notifications
You must be signed in to change notification settings - Fork 26
Wand Quick Start Guide
Arthur Nishimoto edited this page Aug 28, 2013
·
5 revisions
Last revision: ver. 4.2 - 28 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.
Also see Wand Service and Event Reference
-
sourceId
: Unique identifier for the Wand. - As of v4.2-a5 Wand IDs now match the mocap ID instead of the controller ID.
- If the controllers are not activated order according to their Wand ID, the button and trackable mapping may be swapped.
- i.e. Controllers should be activated as: Batman (mocap ID 1), Robin (mocap ID 2), then Xbox360 (mocap ID 3)
-
position
: Mocap position as a Vector3 -
orientation
: Mocap orientation as a Quaternion
Not all Event class functions are accessible in Python. The following are accessible by omegaPythonApi.cpp.
-
isKeyDown(char)
: Returns the status of a key command -
isKeyUp(char)
: Returns the status of a key command -
isButtonDown(flag)
Returns the down status of a button (see controller flags below) -
isButtonUp(flag)
Returns the up status of a button (see controller flags below) -
getAxis(int)
: Take in an integer corresponding to ExtraDataFloat IDs below -
getSourceId()
: The ID assigned by the service that created the event -
getServiceType()
: The service that created the event (Wand, Controller, Mocap, Pointer, etc.) getPosition()
getOrientation()
-
ExtraDataFloat 0
: Left Analog Stick (-left, +right) -
ExtraDataFloat 1
: Left Analog Stick (-up, +down) -
ExtraDataFloat 4
: Analog Trigger L2 (0.0 to 1.0)
-
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)
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")
# Check if some buttons are also released
if(e.isButtonUp( EventFlags.Button3 )): # Cross
print("Wand ", sourceID, "Left button released")
if(e.isButtonUp( EventFlags.Button2 )): # Circle
print("Wand ", sourceID, "Right button released")
# 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 horizontal axis
analogLR = e.getAxis(0)
# Grab the analog stick vertical axis
analogUD = 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)