示例#1
0
        public void DpnupGetDeviceInfo()
        {
            if (_device == IntPtr.Zero)
            {
                return;
            }
            peripheralInfo                  = new PeripheralInfo();
            peripheralInfo.pose_count       = DpnupGetDevicePoseCount();
            peripheralInfo.position_count   = DpnupGetDevicePositionCount();
            peripheralInfo.time_count       = DpnupGetDeviceTimeCount();
            peripheralInfo.quaternion_count = DpnupGetDeviceQuaternionCount();
            peripheralInfo.vector_count     = DpnupGetDeviceVectorCount();
            peripheralInfo.axis_count       = DpnupGetDeviceAxisCount();
            peripheralInfo.button_count     = DpnupGetDeviceButtonCount();

            peripheralstatus = new Peripheralstatus();
            peripheralstatus.device_status = 0;
            if (peripheralInfo.pose_count != 0)
            {
                peripheralstatus.pose_state = new float[peripheralInfo.pose_count][];
                for (int i = 0; i < peripheralInfo.pose_count; i++)
                {
                    peripheralstatus.pose_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_POSE];
                }
            }
            else
            {
                peripheralstatus.pose_state = null;
            }

            if (peripheralInfo.position_count != 0)
            {
                peripheralstatus.position_state = new float[peripheralInfo.position_count][];
                for (int i = 0; i < peripheralInfo.position_count; i++)
                {
                    peripheralstatus.position_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_POSITION];
                }
            }
            else
            {
                peripheralstatus.position_state = null;
            }

            if (peripheralInfo.time_count != 0)
            {
                peripheralstatus.time_state = new double[peripheralInfo.time_count][];
                for (int i = 0; i < peripheralInfo.time_count; i++)
                {
                    peripheralstatus.time_state[i] = new double[DpnpUnity.DPNP_VALUE_TYPE_SIZE_TIME];
                }
            }
            else
            {
                peripheralstatus.time_state = null;
            }

            if (peripheralInfo.quaternion_count != 0)
            {
                peripheralstatus.quaternion_state = new float[peripheralInfo.quaternion_count][];
                for (int i = 0; i < peripheralInfo.quaternion_count; i++)
                {
                    peripheralstatus.quaternion_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_QUATERNION];
                }
            }
            else
            {
                peripheralstatus.quaternion_state = null;
            }

            if (peripheralInfo.vector_count != 0)
            {
                peripheralstatus.vector_state = new float[peripheralInfo.vector_count][];
                for (int i = 0; i < peripheralInfo.vector_count; i++)
                {
                    peripheralstatus.vector_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_VECTOR];
                }
            }
            else
            {
                peripheralstatus.vector_state = null;
            }

            if (peripheralInfo.axis_count != 0)
            {
                peripheralstatus.axis_state = new float[peripheralInfo.axis_count][];
                for (int i = 0; i < peripheralInfo.axis_count; i++)
                {
                    peripheralstatus.axis_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_AXIS];
                }
            }
            else
            {
                peripheralstatus.axis_state = null;
            }

            if (peripheralInfo.button_count != 0)
            {
                Debug.Log("button number " + peripheralInfo.button_count);
                peripheralstatus.button_state = new int[peripheralInfo.button_count][];
                for (int i = 0; i < peripheralInfo.button_count; i++)
                {
                    peripheralstatus.button_state[i] = new int[DpnpUnity.DPNP_VALUE_TYPE_SIZE_BUTTON];
                }
            }
            else
            {
                peripheralstatus.button_state = null;
            }
            prevperipheralstatus = new Peripheralstatus();
            prevperipheralstatus.CopyFrom(peripheralstatus);
        }
示例#2
0
 public void CopyFrom(Peripheralstatus other)
 {
     if (other == null || this == null)
     {
         return;
     }
     other.cacheLock.EnterReadLock();
     this.cacheLock.EnterWriteLock();
     try
     {
         device_status = other.device_status;
         if (other.pose_state != null)
         {
             if (pose_state == null)
             {
                 pose_state = new float[other.pose_state.Length][];
                 for (int i = 0; i < other.pose_state.Length; i++)
                 {
                     pose_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_POSE];
                 }
             }
             for (int i = 0; i < other.pose_state.Length; i++)
             {
                 other.pose_state[i].CopyTo(pose_state[i], 0);
             }
         }
         else
         {
             pose_state = null;
         }
         if (other.position_state != null)
         {
             if (position_state == null)
             {
                 position_state = new float[other.position_state.Length][];
                 for (int i = 0; i < other.position_state.Length; i++)
                 {
                     position_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_POSITION];
                 }
             }
             for (int i = 0; i < other.position_state.Length; i++)
             {
                 other.position_state[i].CopyTo(position_state[i], 0);
             }
         }
         else
         {
             position_state = null;
         }
         if (other.time_state != null)
         {
             if (time_state == null)
             {
                 time_state = new double[other.time_state.Length][];
                 for (int i = 0; i < other.time_state.Length; i++)
                 {
                     time_state[i] = new double[DpnpUnity.DPNP_VALUE_TYPE_SIZE_TIME];
                 }
             }
             for (int i = 0; i < other.time_state.Length; i++)
             {
                 other.time_state[i].CopyTo(time_state[i], 0);
             }
         }
         else
         {
             time_state = null;
         }
         if (other.quaternion_state != null)
         {
             if (quaternion_state == null)
             {
                 quaternion_state = new float[other.quaternion_state.Length][];
                 for (int i = 0; i < other.quaternion_state.Length; i++)
                 {
                     quaternion_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_QUATERNION];
                 }
             }
             for (int i = 0; i < other.quaternion_state.Length; i++)
             {
                 other.quaternion_state[i].CopyTo(quaternion_state[i], 0);
             }
         }
         else
         {
             quaternion_state = null;
         }
         if (other.vector_state != null)
         {
             if (vector_state == null)
             {
                 vector_state = new float[other.vector_state.Length][];
                 for (int i = 0; i < other.vector_state.Length; i++)
                 {
                     vector_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_VECTOR];
                 }
             }
             for (int i = 0; i < other.vector_state.Length; i++)
             {
                 other.vector_state[i].CopyTo(vector_state[i], 0);
             }
         }
         else
         {
             vector_state = null;
         }
         if (other.axis_state != null)
         {
             if (axis_state == null)
             {
                 axis_state = new float[other.axis_state.Length][];
                 for (int i = 0; i < other.axis_state.Length; i++)
                 {
                     axis_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_AXIS];
                 }
             }
             for (int i = 0; i < other.axis_state.Length; i++)
             {
                 other.axis_state[i].CopyTo(axis_state[i], 0);
             }
         }
         else
         {
             axis_state = null;
         }
         if (other.button_state != null)
         {
             if (button_state == null)
             {
                 button_state = new int[other.button_state.Length][];
                 for (int i = 0; i < other.button_state.Length; i++)
                 {
                     button_state[i] = new int[DpnpUnity.DPNP_VALUE_TYPE_SIZE_BUTTON];
                 }
             }
             for (int i = 0; i < other.button_state.Length; i++)
             {
                 other.button_state[i].CopyTo(button_state[i], 0);
             }
         }
         else
         {
             button_state = null;
         }
     }
     finally
     {
         other.cacheLock.ExitReadLock();
         this.cacheLock.ExitWriteLock();
     }
 }
示例#3
0
        // Update is called once per frame
        public void Update()
        {
            Peripheralstatus status = trackedObject.DpnpGetDeviceCurrentStatus();

            if (trackedObject.DpnpGetDeviceCurrentStatus() == null)
            {
                return;
            }
            bool bbutton = ((status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0] & (int)DPNP_POLARIS_BUTTONMASK.DPNP_POLARIS_BUTTONMASK_B) != 0);

            if (bbutton && !BPressed)
            {
                BPressed = true;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnBButtonClicked(e);
            }
            else if (!bbutton && BPressed)
            {
                BPressed = false;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnBButtonUnclicked(e);
            }

            bool abutton = ((status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0] & (int)DPNP_POLARIS_BUTTONMASK.DPNP_POLARIS_BUTTONMASK_A) != 0);

            if (abutton && !APressed)
            {
                APressed = true;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnAButtonClicked(e);
            }
            else if (!abutton && APressed)
            {
                APressed = false;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnAButtonUnclicked(e);
            }

            bool trigger = ((status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0] & (int)DPNP_POLARIS_BUTTONMASK.DPNP_POLARIS_BUTTONMASK_TRIGER) != 0);

            if (trigger && !TrigerPressed)
            {
                TrigerPressed = true;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnTriggerClicked(e);
            }
            else if (!trigger && TrigerPressed)
            {
                TrigerPressed = false;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnTriggerUnclicked(e);
            }

            bool grip = ((status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0] & (int)DPNP_POLARIS_BUTTONMASK.DPNP_POLARIS_BUTTONMASK_GRIP) != 0);

            if (grip && !GripPressed)
            {
                GripPressed = true;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnGripped(e);
            }
            else if (!grip && GripPressed)
            {
                GripPressed = false;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnUngripped(e);
            }

            bool home = ((status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0] & (int)DPNP_POLARIS_BUTTONMASK.DPNP_POLARIS_BUTTONMASK_HOME) != 0);

            if (home && !HomePressed)
            {
                HomePressed = true;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnHomeButtonClicked(e);
            }
            else if (!home && HomePressed)
            {
                HomePressed = false;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnHomeButtonUnclicked(e);
            }

            bool axis = (Mathf.Abs(status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0]) > 150) || (Mathf.Abs(status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0]) > 150);

            if (axis && !AxisPressed)
            {
                AxisPressed = true;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnAxisClicked(e);
            }
            else if (!axis && AxisPressed)
            {
                AxisPressed = false;
                DPVRClickedEventArgs e;
                e.DeviceType = trackedObject.device_type;
                e.flags      = (uint)status.button_state[(int)DPNP_POLARIS_BUTTONS.DPNP_POLARIS_BUTTONS_YB][0];
                e.padX       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_X][0] / 1000;
                e.padY       = status.axis_state[(int)DPNP_POLARIS_AXES.DPNP_POLARIS_AXIS_Y][0] / 1000;
                OnAxisUnclicked(e);
            }
        }