Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

FreePIE Reference

polygraphene edited this page Jul 1, 2018 · 4 revisions

You can get/set various parameter from/to ALVR. All parameters are accessed via global variable "alvr".

Related sources: ALVRFreePIEPlugin.cs FreePIE.h

alvr.input_buttons: boolean array

Get input button state in array of boolean values. You can get current button state of controller. Please use alvr.InputId function to get button index.

alvr.input_buttons[alvr.InputId("trigger")] # True if trigger is pressed.
alvr.input_buttons[alvr.InputId("back")] # True if back is pressed.

Available buttons: "trackpad_click", "trackpad_touch", "trigger", "back"

alvr.two_controllers: boolean

Set True if you use second controller. You can't remove second controller after setting True.

if starting:
  alvr.two_controllers = True

alvr.buttons[controller][button index]: boolean 2-dimension array

Set button state in array of boolean values. You can send button state to games by this variable. Please use alvr.Id function to get button index. Specify controller id to first dimension.

# Click first controller trackpad by keyboard.
controller = 0 # first controller
alvr.buttons[controller][alvr.Id("trackpad_click")] = keyboard.getKeyDown(Key.C)
alvr.buttons[controller][alvr.Id("trackpad_touch")] = keyboard.getKeyDown(Key.C)
alvr.buttons[controller][alvr.Id("application_menu")] = keyboard.getKeyDown(Key.X)
# Note that "trigger" event is not detected unless set alvr.trigger value.
alvr.buttons[0][alvr.Id("trigger")] = alvr.buttons[0][alvr.Id("trigger")] or alvr.input_buttons[alvr.InputId("trigger")]
# You need to set trigger value correctly to get trigger click work
alvr.trigger[0] = 1.0 if alvr.buttons[0][alvr.Id("trigger")] else 0.0

Available buttons: "system", "application_menu", "grip" , "dpad_left", "dpad_up", "dpad_right", "dpad_down" , "a", "b", "x", "y" , "trackpad_click", "trackpad_touch", "trigger", "shoulder_left", "shoulder_right" , "joystick_left", "joystick_right", "back", "guide", "start"

alvr.input_trackpad: float array (2-elements)

Get trackpad x,y position. Each coordinates are from -1.0 to 1.0.

  if alvr.input_buttons[alvr.InputId("trackpad_click")]:
    if alvr.input_trackpad[0] + alvr.input_trackpad[1] > 0.0:
      if alvr.input_trackpad[0] - alvr.input_trackpad[1] > 0.0:
        # left
        alvr.buttons[alvr.Id("trigger")] = True
        alvr.trigger = 1.0
      else:
        # top
        alvr.controller_position[0] += 0.3
    else:
      if alvr.input_trackpad[0] - alvr.input_trackpad[1] > 0.0:
        # bottom
        alvr.controller_position[0] += -0.3
      else:
        # right
        alvr.buttons[alvr.Id("application_menu")] = True

alvr.trackpad[controller][axis]: float 2-dimension array (2-elements)

Set trackpad x,y position. Each coordinates are from -1.0 to 1.0. First dimension is controller id.

# Press "Left" on trackpad
if keyboard.getKeyDown(Key.LeftArrow):
  alvr.buttons[0][alvr.Id("trackpad_click")] = keyboard.getKeyDown(Key.C)
  alvr.buttons[0][alvr.Id("trackpad_touch")] = keyboard.getKeyDown(Key.C)
  alvr.trackpad[0][0] = -1.0
  alvr.trackpad[0][1] = 0.0
# Passthrough
alvr.trackpad[0][0] = alvr.input_trackpad[0]
alvr.trackpad[0][1] = alvr.input_trackpad[1]

alvr.trigger[controller]: float array

Set the trigger value in float. from 0.0 to 1.0.

# You need to set trigger value correctly to get trigger click work
alvr.trigger[0] = 1.0 if alvr.buttons[0][alvr.Id("trigger")] else 0.0
alvr.trigger[1] = 1.0 if alvr.buttons[1][alvr.Id("trigger")] else 0.0

Tracking data

alvr.input_head_orientation: float array (yaw,pitch,roll)

Get head orientation in yaw,pitch,roll. The unit is radian.

alvr.input_controller_orientation: float array (yaw,pitch,roll)

Get controller orientation in yaw,pitch,roll. The unit is radian.

alvr.input_head_position: float array (x,y,z)

Get head position in x,y,z. The unit is meters.

alvr.input_controller_position: float array (x,y,z)

Get controller position in x,y,z. The unit is meters.

alvr.override_head_orientation, override_controller_orientation, override_head_position, override_controller_position: boolean

Set if you pass tracking data to games.

alvr.head_orientation[axis]: float array (yaw,pitch,roll)

Send head orientation to games. The unit is radian. It is used only if alvr.override_head_orientation is True. You may lose smooth head tracking by setting this variable.

alvr.controller_orientation[controller][axis]: float array (yaw,pitch,roll)

Send head orientation to games. The unit is radian. It is used only if alvr.override_controller_orientation is True for first controller. The values for second controller is always used. First dimension is controller id.

alvr.head_position[axis]: float array (x,y,z)

Send head position to games. The unit is meters. It is used only if alvr.override_head_position is True.

alvr.controller_position[controller][axis]: float 2-dimension array (x,y,z)

Send controller position to games. The unit is meters. It is used only if alvr.override_controller_position is True for first controller. The values for second controller is always used. First dimension is controller id.

global offset
if starting:
  prev_back = False
  mode = 0
  offset = [0.0, 0.0, 0.0]

# buggy.
# press upper half of trackpad to forward. bottom half to back
if alvr.input_buttons[alvr.InputId("trackpad_click")]:
  theta = alvr.input_controller_orientation[1]
  theta2 = alvr.input_controller_orientation[2]
  speed = 0.01
  offset[0] += speed * -math.sin(theta) * sign(alvr.input_trackpad[1])
  offset[1] += speed * math.sin(theta2)
  offset[2] += speed * -math.cos(theta) * sign(alvr.input_trackpad[1])

alvr.override_head_position = True

alvr.head_position[0] = alvr.input_head_position[0] + offset[0]
alvr.head_position[1] = alvr.input_head_position[1] + offset[1]
alvr.head_position[2] = alvr.input_head_position[2] + offset[2]

# This is needed only for first controller
alvr.override_controller_position = True

alvr.controller_position[0][0] = alvr.input_controller_position[0] + offset[0]
alvr.controller_position[0][1] = alvr.input_controller_position[1] + offset[1]
alvr.controller_position[0][2] = alvr.input_controller_position[2] + offset[2]

alvr.message: string

Set on screen message in string. You must set empty string ("") to hide message.

import math, time

global prev_back, mode, message_time

if starting:
  prev_back = False
  mode = 0
  message_time = 0.0

if prev_back != alvr.input_buttons[alvr.InputId("back")]:
  prev_back = alvr.input_buttons[alvr.InputId("back")]
  if alvr.input_buttons[alvr.InputId("back")]:
    mode = (mode + 1) % 3
    # show messageo on display
    alvr.message = "mode " + str(mode)
    message_time = time.time()

if time.time() - message_time > 2:
  # hide message after 2 seconds
  alvr.message = ""

No meaning variables

alvr.trigger_left, alvr.trigger_right: float

Set the left or right trigger value in float. from 0.0 to 1.0. I think alvr.trigger_left, alvr.trigger_right are for gamepad controller, so they have no meaning on ALVR.

alvr.joystick_left, alvr.joystick_right: float array (2-elements)

Set the joystick x,y axes value. from -1.0 to 1.0. No meaning on ALVR.