예제 #1
0
        void Start()
        {
            print("Starting...");

            // Make a new client
            Output_GetVersion OGV = MyClient.GetVersion();

            print("GetVersion Major: " + OGV.Major);


            // Connect to a server
            string HostName   = "192.168.1.119:801";
            int    noAttempts = 0;

            print("Connecting to " + HostName + "...");
            while (!MyClient.IsConnected().Connected)
            {
                // Direct connection
                Output_Connect OC = MyClient.Connect(HostName);
                print("Connect result: " + OC.Result);

                noAttempts += 1;
                if (noAttempts == 3)
                {
                    break;
                }
                System.Threading.Thread.Sleep(200);
            }

            MyClient.EnableSegmentData();
            MyClient.EnableMarkerData();
            MyClient.EnableUnlabeledMarkerData();


            // get a frame from the data stream so we can inspect the list of subjects
            MyClient.GetFrame();

            Output_GetSubjectCount OGSC = MyClient.GetSubjectCount();

            print("GetSubjectCount: " + OGSC.Result + "|" + OGSC.SubjectCount);

            // the first subjects in the data stream will be the original subjects unmodified by pegasus
            Output_GetSubjectName OGSN = MyClient.GetSubjectName(OGSC.SubjectCount - 1);

            print("GetSubjectName: " + OGSN.Result + "|" + OGSN.SubjectName);

            SubjectName = OGSN.SubjectName;

            // get the position of the root and point the camera at it
            Output_GetSubjectRootSegmentName   OGSRSN  = MyClient.GetSubjectRootSegmentName(SubjectName);
            Output_GetSegmentGlobalTranslation RootPos = MyClient.GetSegmentGlobalTranslation(SubjectName, OGSRSN.SegmentName);
            Output_GetMarkerCount mcount = MyClient.GetMarkerCount(SubjectName);

            Output_GetUnlabeledMarkerGlobalTranslation OGSGT = MyClient.GetUnlabeledMarkerGlobalTranslation(0);

            Vector3 Target = new Vector3(-(float)OGSGT.Translation[0] / 1000f, (float)OGSGT.Translation[1] / 1000f, (float)OGSGT.Translation[2] / 1000f);

            Camera.main.transform.LookAt(Target);
        }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (!mConnected)
        {
            return;
        }

        Output_GetFrame frame_result = pClient.GetFrame();

        if (frame_result.Result != Result.Success)
        {
            return;
        }

        Output_GetSubjectCount subjectCountResult = pClient.GetSubjectCount();
        uint count = subjectCountResult.SubjectCount;

        if (count == 0)
        {
            return;
        }

        bool subjectSet    = false;
        uint oculusSubject = 0;

        for (uint i = 0; i < count; i++)
        {
            Output_GetSubjectName name = pClient.GetSubjectName(i);
            Debug.Log(name.SubjectName);

            if (name.SubjectName.Equals("OCULUS"))
            {
                oculusSubject = i;
                subjectSet    = true;
            }
        }

        if (!subjectSet)
        {
            return;
        }


        Output_GetSubjectRootSegmentName rsn = pClient.GetSubjectRootSegmentName("OCULUS");
        Output_GetSegmentCount           sg  = pClient.GetSegmentCount("OCULUS");

        Output_GetSegmentGlobalTranslation grans = pClient.GetSegmentGlobalTranslation("OCULUS", rsn.SegmentName);
        Vector3 ret;

        ret.x = (float)grans.Translation [0];
        ret.y = (float)grans.Translation [1];
        ret.z = (float)grans.Translation [2];

        outTransform.localPosition = ret;
    }