Advertisement
Guest User

razerhydra

a guest
May 2nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class RazerHydraController : MonoBehaviour {
  5.  
  6. public Transform leftWand;
  7. public Transform rightWand;
  8. [SerializeField] int[] buttons;
  9. [SerializeField] float[] analogs;
  10. [SerializeField] Vector3[] positions;
  11. [SerializeField] Quaternion[] rotations;
  12. public string hydraAddress = "Tracker0@localhost:3883";
  13.  
  14. void Start () {
  15. // create arrays for input values
  16. analogs = new float[6];
  17. positions = new Vector3[2];
  18. buttons = new int[16];
  19. rotations = new Quaternion[2];
  20. }
  21.  
  22. void LateUpdate () {
  23. float[] pos = new float[3];
  24. float[] quat = new float[4];
  25.  
  26. // loop to collect VRPN input data
  27. for(int i = 0; i < 2; i++)
  28. {
  29. UnityVRPN.getTrackerInfo(hydraAddress,i,pos,quat);
  30. positions[i].Set(pos[0],pos[2],pos[1]);
  31. rotations[i].Set(-quat[0],quat[2],quat[1],quat[3]);
  32. rotations[i] = rotations[i]*Quaternion.Euler (180,0,0);
  33. }
  34.  
  35. UnityVRPN.getButtonInfo(hydraAddress,16,buttons);
  36. UnityVRPN.getAnalogInfo(hydraAddress,6,analogs);
  37.  
  38. if(rightWand != null)
  39. {
  40. rightWand.localPosition = positions[1];
  41. rightWand.localRotation = rotations[1];
  42. }
  43.  
  44. if(leftWand != null)
  45. {
  46. leftWand.localPosition = positions[0];
  47. leftWand.localRotation = rotations[0];
  48. }
  49. }
  50.  
  51. // returns wand position
  52. public Vector3 getHydraPosition(int idx){
  53. return positions[idx];
  54. }
  55.  
  56. // returns specified button
  57. public bool getHydraButton(int idx){
  58. return buttons[idx] > 0;
  59. }
  60.  
  61. // returns rotation of wand
  62. public Quaternion getHydraRotation(int idx){
  63. return rotations[idx];
  64. }
  65.  
  66.  
  67. // returns the analog axis of specified wand
  68. public float getHydraAxis(int idx){
  69. return analogs[idx];
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement