private int GetButtonIndex(SixenseButtons button)
        {
            switch (button)
            {
            case SixenseButtons.ONE:
                return((int)VRInputDevice.VRControl.Action1);

            case SixenseButtons.TWO:
                return((int)VRInputDevice.VRControl.Action2);

            case SixenseButtons.THREE:
                return((int)VRInputDevice.VRControl.Action3);

            case SixenseButtons.FOUR:
                return((int)VRInputDevice.VRControl.Action4);

            case SixenseButtons.BUMPER:
                return((int)VRInputDevice.VRControl.Trigger2);

            case SixenseButtons.START:
                return((int)VRInputDevice.VRControl.Start);

            case SixenseButtons.JOYSTICK:
                return((int)VRInputDevice.VRControl.LeftStickButton);
            }

            // Not all buttons are currently mapped
            return(-1);
        }
 public bool GetButtonUp(SixenseButtons button)
 {
     if (Controller != null)
         return Controller.GetButtonUp(button);
     else
         return false;
 }
		/// <summary>
		/// Returns true if the button parameter was released this frame.
		/// </summary>
		public bool GetButtonUp( SixenseButtons button )
		{
			return ( ( button & m_Buttons ) == 0 ) && ( ( button & m_ButtonsPrevious ) != 0 );
		}
		/// <summary>
		/// Returns true if the button parameter is being pressed.
		/// </summary>
		public bool GetButton( SixenseButtons button )
		{
			return ( ( button & m_Buttons ) != 0 );
		}
 /// <summary>
 /// Returns true if the button parameter was released this frame.
 /// </summary>
 public bool GetButtonUp(SixenseButtons button)
 {
     return(((button & m_Buttons) == 0) && ((button & m_ButtonsPrevious) != 0));
 }
 /// <summary>
 /// Returns true if the button parameter is being pressed.
 /// </summary>
 public bool GetButton(SixenseButtons button)
 {
     return((button & m_Buttons) != 0);
 }
 internal void Update( ref SixensePlugin.sixenseControllerData cd )
 {
     m_Docked = ( cd.is_docked != 0 );
     m_Hand = ( SixenseHands )cd.which_hand;
     m_ButtonsPrevious = m_Buttons;
     m_Buttons = ( SixenseButtons )cd.buttons;
     m_Trigger = cd.trigger;
     m_JoystickX = cd.joystick_x;
     m_JoystickY = cd.joystick_y;
     m_Position.Set( cd.pos[0], cd.pos[1], cd.pos[2] );
     m_Rotation.Set( cd.rot_quat[0], cd.rot_quat[1], cd.rot_quat[2], cd.rot_quat[3] );
     if ( m_Trigger > TriggerButtonThreshold )
     {
         m_Buttons |= SixenseButtons.TRIGGER;
     }
 }
 internal Controller()
 {
     m_Enabled = false;
     m_Docked = false;
     m_Hand = SixenseHands.UNKNOWN;
     m_HandBind = SixenseHands.UNKNOWN;
     m_Buttons = 0;
     m_ButtonsPrevious = 0;
     m_Trigger = 0.0f;
     m_JoystickX = 0.0f;
     m_JoystickY = 0.0f;
     m_Position.Set( 0.0f, 0.0f, 0.0f );
     m_Rotation.Set( 0.0f, 0.0f, 0.0f, 1.0f );
 }
        //ENDOF LUKA CODE
        internal void Update( ref SixensePlugin.sixenseControllerData cd )
        {
            m_Docked = ( cd.is_docked != 0 );
            m_Hand = ( SixenseHands )cd.which_hand;
            m_ButtonsPrevious = m_Buttons;
            m_Buttons = ( SixenseButtons )cd.buttons;
            m_Trigger = cd.trigger;
            m_JoystickX = cd.joystick_x;
            m_JoystickY = cd.joystick_y;

            //LUKA CODE
            if (recording && !startedRec) {
                StartRecording ();
            } else if (recording && startedRec && Time.time>=finishRecTime) {
                StopRecording ();
            }
            Vector3 rawPos = new Vector3(cd.pos[0], cd.pos[1], cd.pos[2] );
            for(int i =0; i<kStates.Length; i++){
                kStates[i].kalman_update(rawPos[i]);
            }

            Vector3 filteredPos = new Vector3 (kStates [0].x, kStates [1].x, kStates [2].x);
            if (recording && startedRec) {
                tw.WriteLine(rawPos.x+" "+rawPos.y+" "+rawPos.z);
                twFiltered.WriteLine(filteredPos.x+" "+filteredPos.y+" "+filteredPos.z);
            }
            if (useKalman) {
                m_Position.Set (filteredPos.x, filteredPos.y, filteredPos.z);
            } else {
                m_Position.Set (rawPos.x, rawPos.y, rawPos.z);
            }

            Quaternion rot = new Quaternion (cd.rot_quat [0], cd.rot_quat [1], cd.rot_quat [2], cd.rot_quat [3]);
            rot = rot * Quaternion.Euler (new Vector3 (225, 0, 0));

            //m_Rotation.Set( rot[0], rot[1], rot[2], rot[3] );
            //ENDOF LUKA CODE

            //m_Position.Set (cd.pos [0], cd.pos [1], cd.pos [2]);
            m_Rotation.Set( cd.rot_quat[0], cd.rot_quat[1], cd.rot_quat[2], cd.rot_quat[3] );
            if ( m_Trigger > TriggerButtonThreshold )
            {
                m_Buttons |= SixenseButtons.TRIGGER;
            }
        }
        internal Controller()
        {
            //LUKA CODE
            processNoise = 0.1f;
            sensorNoise = 1.0f;
            estimatedError = 0.25f;
            kStates = new KalmanState[3];
            for(int i=0; i<kStates.Length; i++){
                kStates[i] = new KalmanState(processNoise,sensorNoise,0.0f,estimatedError,0);
            }
            //ENDOF LUKA CODE

            m_Enabled = false;
            m_Docked = false;
            m_Hand = SixenseHands.UNKNOWN;
            m_HandBind = SixenseHands.UNKNOWN;
            m_Buttons = 0;
            m_ButtonsPrevious = 0;
            m_Trigger = 0.0f;
            m_JoystickX = 0.0f;
            m_JoystickY = 0.0f;
            m_Position.Set( 0.0f, 0.0f, 0.0f );
            m_Rotation.Set( 0.0f, 0.0f, 0.0f, 1.0f );
        }