Guest User

Untitled

a guest
Mar 22nd, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using SixenseWrapper;
  4. using System.Threading;
  5. using System;
  6.  
  7. public class SixenseBehavior : MonoBehaviour {
  8.  
  9.     // Use this for initialization
  10.     void Start () {
  11.          int r = Sixense.Init();
  12.          if (r == Sixense.SUCCESS) {
  13.             int attempts = 0;
  14.             int base_found = 0;
  15.             while (base_found == 0 && attempts < 2) {
  16.                Thread.Sleep(1000);
  17.                base_found = Sixense.IsBaseConnected(0);
  18.             }
  19.  
  20.             if (base_found == 0) {
  21.                Sixense.Exit();
  22.                throw new Exception("Hydra not attached");
  23.             }
  24.             r = Sixense.SetActiveBase(0);
  25.          }
  26.          else
  27.             throw new Exception("Failed to initialize Hydra");
  28.     }
  29.    
  30.     // Update is called once per frame
  31.     void Update () {
  32.         Sixense.ControllerData data;
  33.         if (Sixense.GetNewestData(1, out data) == Sixense.SUCCESS)
  34.         {
  35.             float q0 = data.rot_quat0;
  36.             float q1 = data.rot_quat1;
  37.             float q2 = data.rot_quat2;
  38.             float q3 = data.rot_quat3;
  39.        
  40.             Camera.current.transform.rotation = new Quaternion(q0, q1, q2, q3);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment