Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class RazerHydraController : MonoBehaviour {
- public Transform leftWand;
- public Transform rightWand;
- [SerializeField] int[] buttons;
- [SerializeField] float[] analogs;
- [SerializeField] Vector3[] positions;
- [SerializeField] Quaternion[] rotations;
- public string hydraAddress = "Tracker0@localhost:3883";
- void Start () {
- // create arrays for input values
- analogs = new float[6];
- positions = new Vector3[2];
- buttons = new int[16];
- rotations = new Quaternion[2];
- }
- void LateUpdate () {
- float[] pos = new float[3];
- float[] quat = new float[4];
- // loop to collect VRPN input data
- for(int i = 0; i < 2; i++)
- {
- UnityVRPN.getTrackerInfo(hydraAddress,i,pos,quat);
- positions[i].Set(pos[0],pos[2],pos[1]);
- rotations[i].Set(-quat[0],quat[2],quat[1],quat[3]);
- rotations[i] = rotations[i]*Quaternion.Euler (180,0,0);
- }
- UnityVRPN.getButtonInfo(hydraAddress,16,buttons);
- UnityVRPN.getAnalogInfo(hydraAddress,6,analogs);
- if(rightWand != null)
- {
- rightWand.localPosition = positions[1];
- rightWand.localRotation = rotations[1];
- }
- if(leftWand != null)
- {
- leftWand.localPosition = positions[0];
- leftWand.localRotation = rotations[0];
- }
- }
- // returns wand position
- public Vector3 getHydraPosition(int idx){
- return positions[idx];
- }
- // returns specified button
- public bool getHydraButton(int idx){
- return buttons[idx] > 0;
- }
- // returns rotation of wand
- public Quaternion getHydraRotation(int idx){
- return rotations[idx];
- }
- // returns the analog axis of specified wand
- public float getHydraAxis(int idx){
- return analogs[idx];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement