Exemple #1
0
        public MessageBuffer readMessageBuffer()
        {
            readTypeInfo(Types.TbTB);
            int           l     = readInt();
            MessageBuffer newMb = new MessageBuffer();

            readTypeInfo(Types.TbBinary);
            newMb.buf = new byte[l];
            if (l > buf.Length - currentPos)
            {
                throw new IndexOutOfRangeException();
            }
            for (int i = 0; i < l; i++)
            {
                newMb.buf[i] = buf[currentPos + i];
            }
            if (newMb.buf[0] == 1)
            {
                newMb.typeInfo = true;
            }
            return(newMb);
        }
Exemple #2
0
        //public MessageBuffer readMessageBuffer(byte[] objectInBytes)
        //{
        //    readTypeInfo(Types.TbTB);

        //    MessageBuffer mb = new MessageBuffer();
        //    //mb.buf = readByteArray(objectInBytes.Length);

        //    using (MemoryStream ms = new MemoryStream(objectInBytes))
        //    {
        //        IFormatter br = new BinaryFormatter();
        //        mb = (br.Deserialize(ms) as MessageBuffer);
        //    }

        //    return mb;
        //}

        public void add(MessageBuffer mb2)
        {
            addTypeInfo(Types.TbTB);
            add(buf.Length);
            add(mb2.buf);
        }
        private async void ParseTrackingFrame()
        {
            try
            {
                for (uint id = 0; id < OpenVR.k_unMaxTrackedDeviceCount; id++)
                {
                    if (vr_pointer != null)
                    {
                        TrackedDevicePose_t[] trackedDevicePose = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];

                        if (!vr_pointer.IsTrackedDeviceConnected(id))
                        {
                            continue;
                        }

                        VRControllerState_t controllState = new VRControllerState_t();

                        ETrackedDeviceClass trackedDeviceClass = vr_pointer.GetTrackedDeviceClass(id);

                        switch (trackedDeviceClass)
                        {
                        case ETrackedDeviceClass.Controller:

                            vr_pointer.GetControllerStateWithPose(ETrackingUniverseOrigin.TrackingUniverseStanding, id, ref controllState, OpenVR.k_unMaxTrackedDeviceCount, ref trackedDevicePose[id]);

                            HmdVector3_t position = GetPosition(trackedDevicePose[id].mDeviceToAbsoluteTracking);    // devicePose->mDeviceToAbsoluteTracking);
                            HmdVector3_t rotation = GetRotationEuler(trackedDevicePose[id].mDeviceToAbsoluteTracking);


                            int positionControllerX = (int)position.v0;
                            int positionControllerY = (int)position.v1;
                            int positionControllerZ = (int)position.v2 * (-1);

                            int rotationControllerX = (int)rotation.v0 + 180;
                            int rotationControllerY = (int)rotation.v1;
                            int rotationControllerZ = (int)rotation.v2;

                            if (ControlViewModel.teleporOffset[0] != -1)
                            {
                                ControlViewModel.transOffSetControllerX = ControlViewModel.teleporOffset[0];
                                ControlViewModel.transOffSetControllerY = ControlViewModel.teleporOffset[1];
                                ControlViewModel.transOffSetControllerZ = ControlViewModel.teleporOffset[2];
                                ControlViewModel.rotOffSetControllerZ   = ControlViewModel.teleporOffset[3];
                            }

                            ETrackedControllerRole result = vr_pointer.GetControllerRoleForTrackedDeviceIndex(id);

                            if (result != ETrackedControllerRole.LeftHand && lastController != ETrackedControllerRole.LeftHand)
                            {
                                RaiseControllerEvent(new TrackingChangedEventArgs(false), Tracker.LeftController);
                            }

                            if (result != ETrackedControllerRole.RightHand && lastController != ETrackedControllerRole.RightHand)
                            {
                                RaiseControllerEvent(new TrackingChangedEventArgs(false), Tracker.RightController);
                            }

                            switch (result)
                            {
                            case ETrackedControllerRole.Invalid:
                                break;

                            case ETrackedControllerRole.LeftHand:

                                if (communicationProtocolUdp == false)
                                {
                                    MessageBuffer mb2 = new MessageBuffer();
                                    someThingTracked = true;
                                    int type = 101;
                                    mb2.add(type);
                                    mb2.add(userId);
                                    int handid = 1;
                                    mb2.add(handid);
                                    mb2.add(positionControllerX + ControlViewModel.transOffSetControllerX);
                                    mb2.add(positionControllerY + ControlViewModel.transOffSetControllerY);
                                    mb2.add(positionControllerZ + ControlViewModel.transOffSetControllerZ);
                                    mb2.add(rotationControllerX);
                                    mb2.add(rotationControllerY);
                                    mb2.add(rotationControllerZ);
                                    mb2.add(ControlViewModel.rotOffSetControllerZ);
                                    RaiseControllerEvent(new TrackingChangedEventArgs(true), Tracker.LeftController);
                                    Message msg = new Message(mb2, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                                    lock (tcpSocketManager.send_msg(msg))
                                    {
                                        tcpSocketManager.send_msg(msg);
                                    }
                                    Thread.Sleep(20);
                                    break;
                                }
                                break;

                            case ETrackedControllerRole.RightHand:

                                if (communicationProtocolUdp == false)
                                {
                                    MessageBuffer mb2 = new MessageBuffer();
                                    someThingTracked = true;
                                    int type = 101;
                                    mb2.add(type);
                                    mb2.add(userId);
                                    int handid = 2;
                                    mb2.add(handid);
                                    mb2.add(positionControllerX + ControlViewModel.transOffSetControllerX);
                                    mb2.add(positionControllerY + ControlViewModel.transOffSetControllerY);
                                    mb2.add(positionControllerZ + ControlViewModel.transOffSetControllerZ);
                                    mb2.add(rotationControllerX);
                                    mb2.add(rotationControllerY);
                                    mb2.add(rotationControllerZ);
                                    mb2.add(ControlViewModel.rotOffSetControllerZ);
                                    Message msg = new Message(mb2, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                                    RaiseControllerEvent(new TrackingChangedEventArgs(true), Tracker.RightController);
                                    lock (tcpSocketManager.send_msg(msg))
                                    {
                                        tcpSocketManager.send_msg(msg);
                                    }
                                    Thread.Sleep(20);
                                    break;
                                }
                                break;
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Warn("ParseTrackingFrame in Controller Tracking wurde beendet!" + e);
                RaiseControllerEvent(new TrackingChangedEventArgs(false), Tracker.LeftController);
                RaiseControllerEvent(new TrackingChangedEventArgs(false), Tracker.RightController);
            }
        }
        private bool ProcessVREvent(VREvent_t event_T)
        {
            switch (event_T.eventType)
            {
            case (uint)EVREventType.VREvent_Quit:
                Shutdown();
                return(false);

            case (uint)EVREventType.VREvent_QuitAborted_UserPrompt:
                return(false);

            case (uint)EVREventType.VREvent_QuitAcknowledged:
                return(false);

            case (uint)EVREventType.VREvent_ButtonPress:

                int msgIdentifyer = 102;

                switch (event_T.data.controller.button)
                {
                case (uint)EVRButtonId.k_EButton_SteamVR_Touchpad:
                    Console.WriteLine("Touchpad");

                    ETrackedControllerRole result = vr_pointer.GetControllerRoleForTrackedDeviceIndex(event_T.trackedDeviceIndex);
                    if (result == ETrackedControllerRole.LeftHand)
                    {
                        int           handid = 1;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_SteamVR_Touchpad);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    else
                    {
                        int           handid = 2;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_SteamVR_Touchpad);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    return(false);

                case (uint)EVRButtonId.k_EButton_ApplicationMenu:
                    Console.WriteLine("ButttonAplication");

                    ETrackedControllerRole result2 = vr_pointer.GetControllerRoleForTrackedDeviceIndex(event_T.trackedDeviceIndex);
                    if (result2 == ETrackedControllerRole.LeftHand)
                    {
                        int           handid = 1;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_ApplicationMenu);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    else
                    {
                        int           handid = 2;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_ApplicationMenu);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    return(false);

                case (uint)EVRButtonId.k_EButton_System:
                    Console.WriteLine("ButtonSystem");

                    ETrackedControllerRole result3 = vr_pointer.GetControllerRoleForTrackedDeviceIndex(event_T.trackedDeviceIndex);
                    if (result3 == ETrackedControllerRole.LeftHand)
                    {
                        int           handid = 1;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_System);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    else
                    {
                        int           handid = 2;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_System);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    return(false);

                case (uint)EVRButtonId.k_EButton_SteamVR_Trigger:
                    Console.WriteLine("Trigger");

                    ETrackedControllerRole result4 = vr_pointer.GetControllerRoleForTrackedDeviceIndex(event_T.trackedDeviceIndex);
                    if (result4 == ETrackedControllerRole.LeftHand)
                    {
                        int           handid = 1;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_SteamVR_Trigger);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    else
                    {
                        int           handid = 2;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_SteamVR_Trigger);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    return(false);

                case (uint)EVRButtonId.k_EButton_Grip:
                    Console.WriteLine("Grip");
                    ETrackedControllerRole result5 = vr_pointer.GetControllerRoleForTrackedDeviceIndex(event_T.trackedDeviceIndex);
                    if (result5 == ETrackedControllerRole.LeftHand)
                    {
                        int           handid = 1;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_Grip);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    else
                    {
                        int           handid = 2;
                        MessageBuffer mb     = new MessageBuffer();
                        mb.add(msgIdentifyer);
                        mb.add((int)EVRButtonId.k_EButton_Grip);
                        mb.add(userId);
                        mb.add(handid);
                        Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                        lock (tcpSocketManager.send_msg(msg))
                        {
                            tcpSocketManager.send_msg(msg);
                        }
                    }
                    return(false);
                }
                return(false);

            default:
                return(false);
            }
        }
 public override void deserializeValue(MessageBuffer mb)
 {
     SharedStateSerializer.deserializeWithType <T>(ref mb, ref m_value);
 }
 public abstract void deserializeValue(MessageBuffer mb);
 protected void subscribe(MessageBuffer val)
 {
     SharedStateManager.Instance.subscribeVar(sessionID, m_className, variableName, val);
 }
 protected void setVar(MessageBuffer val)
 {
     m_valueData = val;
     SharedStateManager.Instance.setVar(sessionID, m_className, variableName, val, muted);
 }
Exemple #9
0
 void ISerializer <T> .serialize(ref MessageBuffer mb, T value)
 {
     throw new NotSupportedException();
 }
 private void serialize(ref MessageBuffer mb, SessionID sid)
 {
     mb.add(sid.m_owner);
     mb.add(sid.m_name);
     mb.add(sid.m_isPrivate);
 }
Exemple #11
0
        public static void deserializeWithType <T>(ref MessageBuffer mb, ref T value)
        {
            int type = mb.readInt(); //typeInfo

            deserialize(ref mb, ref value);
        }
Exemple #12
0
 public static void deserialize <T>(ref MessageBuffer mb, ref T value)
 {
     Serializer <T> .P.deserialize(ref mb, ref value);
 }
Exemple #13
0
 public static void serialize <T>(ref MessageBuffer mb, T value)
 {
     Serializer <T> .P.serialize(ref mb, value);
 }
 public Message(MessageBuffer mb, Message.MessagesType mt)
 {
     message = mb;
     Type    = mt;
 }
        private async Task ParseTrackingFrameAsync(CancellationToken token)
        {
            try
            {
                for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
                {
                    if (!token.IsCancellationRequested)
                    {
                        TrackedDevicePose_t[] trackedDevicePose = new TrackedDevicePose_t[10];

                        if (!m_pHMD.IsTrackedDeviceConnected(i))
                        {
                            continue;
                        }

                        ETrackedDeviceClass trackedDeviceClass = m_pHMD.GetTrackedDeviceClass(i);

                        switch (trackedDeviceClass)
                        {
                        case ETrackedDeviceClass.HMD:

                            m_pHMD.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 0, trackedDevicePose);

                            HmdVector3_t position = GetPosition(trackedDevicePose[0].mDeviceToAbsoluteTracking);    // devicePose->mDeviceToAbsoluteTracking);
                            HmdVector3_t rotation = GetRotationEuler(trackedDevicePose[0].mDeviceToAbsoluteTracking);

                            int positionX = (int)position.v0;
                            int positionY = (int)position.v1;
                            int positionZ = (int)position.v2 * (-1);

                            int rotationX = (int)rotation.v0 + 360;
                            int rotationY = (int)rotation.v1 + 90;
                            int rotationZ = (int)rotation.v2 * (-1);

                            if (ControlViewModel.teleporOffset[0] != -1)
                            {
                                lock (ControlViewModel.teleporOffset)
                                {
                                    ControlViewModel.transOffSetHeadX = ControlViewModel.teleporOffset[0];
                                    ControlViewModel.transOffSetHeadY = ControlViewModel.teleporOffset[1];
                                    ControlViewModel.transOffSetHeadZ = ControlViewModel.teleporOffset[2];
                                    ControlViewModel.rotOffSetHeadZ   = ControlViewModel.teleporOffset[3];
                                }
                            }

                            if (communicationProtocolUdp == false)
                            {
                                MessageBuffer mb       = new MessageBuffer();
                                int           type     = 100;
                                string        ipAdress = ServerManager.clientIpAddressForTracking;
                                mb.add(type);
                                mb.add(userId);
                                mb.add(ipAdress);
                                mb.add(positionX + ControlViewModel.transOffSetHeadX);
                                mb.add(positionY + ControlViewModel.transOffSetHeadY);
                                mb.add(positionZ + ControlViewModel.transOffSetHeadZ);
                                mb.add(rotationX - ControlViewModel.rotOffSetHeadZ);
                                mb.add(rotationY);
                                mb.add(rotationZ);
                                Message msg = new Message(mb, Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE);
                                lock (tcpSocketManager.send_msg(msg))
                                {
                                    tcpSocketManager.send_msg(msg);
                                }

                                Thread.Sleep(20);
                                break;
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Warn("ParseTrackingFrameAsync in Hmd Tracking wurde beendet!");

                RaiseSampleEvent(new TrackingChangedEventArgs(e));
            }
        }