コード例 #1
0
 public void Start()
 {
     if (configuration)
     {
         // get value from file if exists, else use above value
         serverAddress = configuration.GetProperty("owl_address");
     }
     state = OwlState.Disconnected;
     UpdateOwl();         // start
 }
コード例 #2
0
 private void Stop(OwlState exitState = OwlState.Disconnected)
 {
     if (state == OwlState.Connected)
     {
         Debug.Log("Stop owl");
         Owl.Done();
         if (exitState == OwlState.Error)
         {
             Debug.LogError("Owl was stopped due to an error!");
         }
         state = exitState;
     }
 }
コード例 #3
0
    private void UpdateOwl()
    {
        if (state == OwlState.Disconnected)
        {
            Debug.Log("Start owl");

            try {
                // clear any current connection
                // also check if dll is present
                Owl.Done();
            } catch (DllNotFoundException e) {
                Debug.LogError("Owl DLL not found!");
                Debug.LogError(e);
                state = OwlState.Error;
                return;
            }

            uint flags = (uint)Phasespace.InitFlags.Slave;

            Debug.Log("Initializing server");
            if (Owl.Init(serverAddress, flags) < 0)
            {
                Debug.LogError("Owl init fail!");
                state = OwlState.Error;
                return;
            }

            Owl.SetFloat((int)Phasespace.Set.Frequency, serverFrequency);

            if (ErrorOccurred())
            {
                Stop(exitState: OwlState.Error);
                return;
            }

            Owl.SetInteger((int)Phasespace.Set.Streaming, (int)Phasespace.CommonFlags.Enable);

            if (ErrorOccurred())
            {
                Stop(exitState: OwlState.Error);
                return;
            }

            Debug.Log("Running server!");

            state = OwlState.Connected;
        }
        else if (state == OwlState.Connected)
        {
            bool gotData = false;
            if (getMarkers)
            {
                // get markers
                int n = 0;
                do
                {
                    n = Owl.GetMarkers(ref markers);
                    if (n > 0)
                    {
                        gotData = true;
                        for (int i = 0; i < n; i++)
                        {
                            markers[i].x *= spaceScalar;
                            markers[i].y *= spaceScalar;
                            markers[i].z *= spaceScalar;
                        }
                    }
                    if (ErrorOccurred())
                    {
                        Stop(exitState: OwlState.Error);
                        return;
                    }
                } while (n > 0);
            }

            if (getRigids)
            {
                // get rigid bodies
                int n = 0;
                do
                {
                    n = Owl.GetRigids(ref rigids);
                    if (n > 0)
                    {
                        gotData = true;
                        for (int i = 0; i < n; i++)
                        {
                            rigids[i].pose.px *= spaceScalar;
                            rigids[i].pose.py *= spaceScalar;
                            rigids[i].pose.pz *= spaceScalar;
                        }
                    }
                    if (ErrorOccurred())
                    {
                        Stop(exitState: OwlState.Error);
                        return;
                    }
                } while (n > 0);
            }

            if (getCameras)
            {
                // get cameras
                int n = Owl.GetCameras(ref cameras);
                if (n > 0)
                {
                    gotData = true;
                    for (int i = 0; i < n; i++)
                    {
                        cameras[i].pose.px *= spaceScalar;
                        cameras[i].pose.py *= spaceScalar;
                        cameras[i].pose.pz *= spaceScalar;
                    }
                }
                if (ErrorOccurred())
                {
                    Stop(exitState: OwlState.Error);
                    return;
                }
            }

            if (gotData)
            {
                if (onOwlUpdate != null)
                {
                    onOwlUpdate();
                }
            }
        }
        serverRunning = (state == OwlState.Connected);
    }