Ejemplo n.º 1
0
 public override void receivePose(SimplePose newPose)
 {
     lock (thisLock)
     {
         m_pose = UbiMeasurementUtils.ubitrackToUnity(newPose);
     }
 }
Ejemplo n.º 2
0
        void FixedUpdate()
        {
            switch (ubitrackEvent)
            {
            case UbitrackEventType.Pull:
            {
                ulong lastTimestamp = UbiMeasurementUtils.getUbitrackTimeStamp();
                if (m_position3DListPull.getPositionList3D(m_simplePosition3DList, lastTimestamp))
                {
                    m_data = UbiMeasurementUtils.ubitrackToUnity(m_simplePosition3DList);
                }
                break;
            }

            case UbitrackEventType.Push:
            {
                Measurement <List <Vector3> > tmp = m_listReceiver.getData();
                if (tmp != null)
                {
                    m_data = tmp;
                }
                break;
            }

            default:
                break;
            }
        }
 public override void receivePositionList3D(SimplePositionList3D position3dList)
 {
     lock (thisLock)
     {
         m_data = UbiMeasurementUtils.ubitrackToUnity(position3dList);
     }
 }
Ejemplo n.º 4
0
        void Update()
        {
            if (sending)
            {
                switch (ubitrackEvent)
                {
                case UbitrackEventType.Push:
                {
                    SimplePosition2D simplePos2D = new SimplePosition2D();
                    simplePos2D.x         = sendPos2D.x;
                    simplePos2D.y         = sendPos2D.y;
                    simplePos2D.timestamp = UbiMeasurementUtils.getUbitrackTimeStamp();
                    m_poseReciever.receivePosition2D(simplePos2D);
                    if (once)
                    {
                        this.enabled = false;
                    }
                    break;
                }

                case UbitrackEventType.Pull:
                default:
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        void Update()
        {
            if (sending)
            {
                switch (ubitrackEvent)
                {
                case UbitrackEventType.Push:
                {
                    SimplePosition3D simplePos3D = new SimplePosition3D();
                    Vector3          output      = Vector3.zero;
                    UbiMeasurementUtils.coordsysemChange(sendPos, ref output);
                    simplePos3D.x         = output.x;
                    simplePos3D.y         = output.y;
                    simplePos3D.z         = output.z;
                    simplePos3D.timestamp = UbiMeasurementUtils.getUbitrackTimeStamp();
                    m_poseReciever.receivePosition3D(simplePos3D);
                    if (once)
                    {
                        this.enabled = false;
                    }
                    break;
                }

                case UbitrackEventType.Pull:
                default:
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        protected void processData()
        {
            if (m_pose != null)
            {
                UbiUnityUtils.setGameObjectPose(relative, gameObject, m_pose.data());

                if (m_lastData != null)
                {
                    Vector3 posDiff  = m_pose.data().pos - m_lastData.data().pos;
                    ulong   timeDiff = m_pose.time() - m_lastData.time();

                    float timeDiffSeconds = (float)timeDiff * 1E-9f;

                    m_meanPosVelocity = posDiff.magnitude / timeDiffSeconds;
                }

                m_lastData = m_pose;

                triggerPull(m_pose.time());
            }


            if (m_lastData != null)
            {
                ulong timeDiff             = UbiMeasurementUtils.getUbitrackTimeStamp() - m_lastData.time();
                float timeDiffMilliSeconds = (float)timeDiff * 1E-6f;
                m_timeout = timeDiffMilliSeconds > TimeoutInMilliSeconds;
            }
        }
Ejemplo n.º 7
0
        internal static SimplePose getGameObjectPose(UbitrackRelativeToUnity relative, GameObject go)
        {
            SimplePose pose = new SimplePose();
            Vector3    pos  = new Vector3();
            Quaternion rot  = new Quaternion();

            switch (relative)
            {
            case UbitrackRelativeToUnity.Local:
            {
                UbiMeasurementUtils.coordsysemChange(go.transform.localPosition, ref pos);
                UbiMeasurementUtils.coordsysemChange(go.transform.localRotation, ref rot);
                break;
            }

            case UbitrackRelativeToUnity.World:
            {
                UbiMeasurementUtils.coordsysemChange(go.transform.position, ref pos);
                UbiMeasurementUtils.coordsysemChange(go.transform.rotation, ref rot);
                break;
            }

            default:
                break;
            }
            pose.tx = pos.x;
            pose.ty = pos.y;
            pose.tz = pos.z;

            pose.rx = rot.x;
            pose.ry = rot.y;
            pose.rz = rot.z;
            pose.rw = rot.w;
            return(pose);
        }
Ejemplo n.º 8
0
 public override void receiveErrorPosition3D(SimpleErrorPosition3D position3d)
 {
     lock (thisLock)
     {
         m_data = UbiMeasurementUtils.ubitrackToUnity(position3d);
     }
 }
Ejemplo n.º 9
0
        public void applyProjectionMatrix()
        {
            SimpleMatrix3x3 matrix = new SimpleMatrix3x3();

            if (m_matrixPull.getMatrix3x3(matrix, UbiMeasurementUtils.getUbitrackTimeStamp()))
            {
                intrinsics = UbiMeasurementUtils.ubitrackToUnity(matrix);

                projectionMatrix = CameraUtils.constructProjectionMatrix3x3(intrinsics.data(), standardWidth, standardHeight, nearClipping, farClipping);

                if (Flip_X_Y)
                {
                    Matrix4x4 rotMat = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, -90), Vector3.one);
                    projectionMatrix = rotMat * projectionMatrix;
                }

                //Debug.Log(projectionMatrix);
                if (GetComponent <Camera>() != null)
                {
                    GetComponent <Camera>().projectionMatrix = projectionMatrix;
                    //Debug.Log("set projection matrix of camera");
                }
            }
            else
            {
                throw new Exception("unable to get 3x3 matrix");
            }
        }
Ejemplo n.º 10
0
        public void applyProjectionMatrix(ulong givenTimestamp, float screenWidth, float screenHeight)
        {
            Debug.Log("Trying to pull with timestamp " + givenTimestamp);
            SimpleMatrix3x3 matrix = new SimpleMatrix3x3();

            if (m_matrixPull.getMatrix3x3(matrix, givenTimestamp))
            {
                intrinsics = UbiMeasurementUtils.ubitrackToUnity(matrix);

                projectionMatrix = CameraUtils.constructProjectionMatrix3x3(intrinsics.data(), screenWidth, screenHeight, nearClipping, farClipping);

                if (Flip_X_Y)
                {
                    Matrix4x4 rotMat = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, -90), Vector3.one);
                    projectionMatrix = rotMat * projectionMatrix;
                }

                //Debug.Log(projectionMatrix);
                if (GetComponent <Camera>() != null)
                {
                    GetComponent <Camera>().projectionMatrix = projectionMatrix;
                    //Debug.Log("set projection matrix of camera");
                }
            }
            else
            {
                throw new Exception("unable to get 3x3 matrix");
            }
        }
 public override void receiveMatrix3x4(SimpleMatrix3x4 newMatrix)
 {
     lock (thisLock)
     {
         m_matrix = UbiMeasurementUtils.ubitrackToUnity(newMatrix);
     }
 }
Ejemplo n.º 12
0
        void FixedUpdate()
        {
            m_pose = null;

            switch (ubitrackEvent)
            {
            case UbitrackEventType.Pull: {
                ulong lastTimestamp = UbiMeasurementUtils.getUbitrackTimeStamp();
                if (m_posePull.getPose(m_simplePose, lastTimestamp))
                {
                    m_pose = UbiMeasurementUtils.ubitrackToUnity(m_simplePose);
                }
                break;
            }

            case UbitrackEventType.Push: {
                m_pose = m_poseReceiver.getData();
                break;
            }

            default:
                break;
            }

            if (m_pose != null)
            {
                UbiUnityUtils.setGameObjectPose(relative, gameObject, m_pose.data());
            }
        }
Ejemplo n.º 13
0
        void FixedUpdate()
        {
            if (ubitrackEvent == UbitrackEventType.Pull && UseTriggerToPull)
            {
                return;
            }

            m_pose = null;

            switch (ubitrackEvent)
            {
            case UbitrackEventType.Pull: {
                ulong lastTimestamp = UbiMeasurementUtils.getUbitrackTimeStamp();
                if (m_posePull.getPose(m_simplePose, lastTimestamp))
                {
                    m_pose = UbiMeasurementUtils.ubitrackToUnity(m_simplePose);
                }
                break;
            }

            case UbitrackEventType.Push: {
                m_pose = m_poseReceiver.getData();
                break;
            }

            default:
                break;
            }


            //Debug.Log ("m_simplePose: " + m_simplePose);
            processData();
        }
Ejemplo n.º 14
0
 public override void receivePosition3D(SimplePosition3D newPosition)
 {
     lock (thisLock)
     {
         m_position = UbiMeasurementUtils.ubitrackToUnity(newPosition);
     }
 }
Ejemplo n.º 15
0
 public override void pullNow(ulong lastTimestamp)
 {
     if (m_posePull.getPose(m_simplePose, lastTimestamp))
     {
         m_pose = UbiMeasurementUtils.ubitrackToUnity(m_simplePose);
     }
     processData();
 }
Ejemplo n.º 16
0
        public void sendButtonEvent(int eventID)
        {
            SimpleButton b = new SimpleButton();

            b.timestamp = UbiMeasurementUtils.getUbitrackTimeStamp();
            b._event    = eventID;
            m_button.receiveButton(b);
        }
Ejemplo n.º 17
0
        public void send(ulong timestamp)
        {
            SimplePosition3D simplePos3D = new SimplePosition3D();
            Vector3          output      = Vector3.zero;

            UbiMeasurementUtils.coordsysemChange(sendPos, ref output);
            simplePos3D.x         = output.x;
            simplePos3D.y         = output.y;
            simplePos3D.z         = output.z;
            simplePos3D.timestamp = timestamp;
            m_poseReciever.receivePosition3D(simplePos3D);
            if (once)
            {
                this.enabled = false;
            }
        }
Ejemplo n.º 18
0
        private void ReceiveData()
        {
            client = new UdpClient(port);
            while (m_keepRunning)
            {
                try
                {
                    IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);

                    byte[] data = client.Receive(ref anyIP);



                    // Bytes mit der UTF8-Kodierung in das Textformat kodieren.

                    string text = Encoding.UTF8.GetString(data);

                    Debug.Log(text);

                    string[] words = text.Split(' ');


                    Quaternion q = new Quaternion(float.Parse(words[12]),
                                                  float.Parse(words[13]),
                                                  float.Parse(words[14]),
                                                  float.Parse(words[15]));
                    Vector3 t = new Vector3(float.Parse(words[18]),
                                            float.Parse(words[19]),
                                            float.Parse(words[20]));

                    m_newData = new Pose();
                    UbiMeasurementUtils.coordsysemChange(t, ref m_newData.pos);
                    UbiMeasurementUtils.coordsysemChange(q, ref m_newData.rot);
                }

                catch (Exception err)

                {
                    Debug.Log(err.ToString());
                }
            }
            client.Close();
        }
Ejemplo n.º 19
0
        public static Pose readErrorPoseAsPoseFromString(string input)
        {
            char[] splitter = { ' ' };

            NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;

            nfi.NumberDecimalSeparator = ".";



            string[] strList = input.Split(splitter);
            Pose     result  = new Pose();

            Vector3    pos = new Vector3(float.Parse(strList[0 + 16], nfi), float.Parse(strList[1 + 16], nfi), float.Parse(strList[2 + 16], nfi));
            Quaternion rot = new Quaternion(float.Parse(strList[0 + 10], nfi), float.Parse(strList[1 + 10], nfi), float.Parse(strList[2 + 10], nfi), float.Parse(strList[3 + 10], nfi));

            UbiMeasurementUtils.coordsysemChange(pos, ref result.pos);
            UbiMeasurementUtils.coordsysemChange(rot, ref result.rot);
            return(result);
        }
        void FixedUpdate()
        {
            m_pose = null;

            switch (ubitrackEvent)
            {
            case UbitrackEventType.Pull:
            {
                ulong lastTimestamp = UbiMeasurementUtils.getUbitrackTimeStamp();

                if (m_posePull.getErrorPosition3D(m_simplePose, lastTimestamp))
                {
                    m_pose = UbiMeasurementUtils.ubitrackToUnity(m_simplePose);
                }
                break;
            }

            case UbitrackEventType.Push:
            {
                m_pose = m_poseReceiver.getData();
                break;
            }

            default:
                break;
            }

            if (m_pose != null)
            {
                if (relative == UbitrackRelativeToUnity.Local)
                {
                    gameObject.transform.localPosition = m_pose.data().position;
                }
                else
                {
                    gameObject.transform.position = m_pose.data().position;
                }
                m_lastpose = m_pose;
            }
        }
Ejemplo n.º 21
0
        void FixedUpdate()
        {
            m_position = null;

            switch (ubitrackEvent)
            {
            case UbitrackEventType.Pull: {
                ulong lastTimestamp = UbiMeasurementUtils.getUbitrackTimeStamp();
                if (m_positionPull.getPosition3D(m_simplePosition, lastTimestamp))
                {
                    m_position = UbiMeasurementUtils.ubitrackToUnity(m_simplePosition);
                }
                break;
            }

            case UbitrackEventType.Push: {
                m_position = m_positionReceiver.getData();
                break;
            }

            default:
                break;
            }

            if (m_position != null)
            {
                UbiUnityUtils.setGameObjectPosition(relative, gameObject, m_position.data());
                m_lastData = m_position;
            }

            if (m_lastData != null)
            {
                ulong timeDiff             = UbiMeasurementUtils.getUbitrackTimeStamp() - m_lastData.time();
                float timeDiffMilliSeconds = (float)timeDiff * 1E-6f;
                m_timeout = timeDiffMilliSeconds > TimeoutInMilliSeconds;
            }
        }