Skip to content

cameron-rowe/unity-vrpn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

VRPN on Unity

To enable VRPN functionality in your Unity3D application, simply add all of the assets in this repository to your application, including streaming assets and plugins.

Once the assets have been added, simply create an empty game object in your scene, and add the CaVR script to it. To configure input, the ConfigureInputs() function of the VRPNInputManager class must contain the mapped values to be used. For example:

private void ConfigureInputs() {
    ButtonMap.Add("home", "WiiMote0[0]");
    ButtonMap.Add("a", "WiiMote0[3]");
    ButtonMap.Add("nunchuck-z", "WiiMote0[16]");

    AnalogMap.Add("x", "WiiMote0[21]");
    AnalogMap.Add("z", "WiiMote0[22]");

    SixdofMap.Add("wand", "WiiMote0[0]");
}

Button and analog bindings for the WiiMote controller for VRPN can be found at https://github.com/vrpn/vrpn/blob/master/vrpn_WiiMote.h

To access SixDOF information as well as button and analog values, see the ExampleInputScript. The code for this class is pasted below.

using UnityEngine;

public class ExampleInputScript : MonoBehaviour {
    private VRPNInputManager inputManager;

    // Use this for initialization
    void Start () {
        var cavr = FindObjectOfType<CaVR>();
        inputManager = cavr.InputManger;
    }

    // Update is called once per frame
    void Update () {
        var wand = inputManager.GetSixdofValue("wand");

        // do something with wand SixDOF
        transform.localPosition = wand.Position;

        var homeButtonPressed = inputManager.GetButtonValue("home");

        // do something on button press
        if(homeButtonPressed) {
            Debug.Log("Pressed Home Button!");
        }

        var xAxis = inputManager.GetAnalogValue("x");

        // do something with axis information
        transform.Rotate(Vector3.up, xAxis);
    }
}

The script example.lua located in the StreamingAssets folder is necessary for configuring VRPN. The buttons, analogs, and sixdofs configuration URLs must be added to use the appropriate VRPN device. The ability to configure several machines is provided, however currently only the master machine is supported.

Note that this VRPN example currently only works on 64-bit Windows.

About

Assets required to get VRPN to work with Unity3D

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages