Exemple #1
0
 public int GetFrequency()
 {
     if (mProtocol.GeneralSettings == null)
     {
         mProtocol.GetGeneralSettings();
     }
     return(mProtocol.GeneralSettings.CaptureFrequency);
 }
        static bool GetGeneralSettings(RTState state, RTProtocol mProtocol)
        {
            bool getStatus = mProtocol.GetGeneralSettings();

            if (!getStatus)
            {
                return(false);
            }

            state.frequency = mProtocol.GeneralSettings.CaptureFrequency;
            return(true);
        }
    void StartStreaming(string ipAddress)
    {
        Debug.LogFormat("Starting stream from {0}...", ipAddress);

        // Init protocol
        rtProtocol = new RTProtocol();

        if (!rtProtocol.IsConnected())
        {
            // Check if connection to QTM is possible
            if (!rtProtocol.IsConnected())
            {
                if (!rtProtocol.Connect(ipAddress))
                {
                    Debug.Log("QTM: Trying to connect...");
                    return;
                }
                Debug.Log("QTM: Connected!");
            }

            // Get settings and start stream
            if (rtProtocol.GeneralSettings == null)
            {
                if (!rtProtocol.GetGeneralSettings())
                {
                    Debug.Log("QTM: Trying to get General settings...");
                    return;
                }
                Debug.Log("QTM: General settings available.");

                // Print camera settings to console
                Debug.LogFormat("QTM: Frequency: {0}", rtProtocol.GeneralSettings.CaptureFrequency);
                Debug.Log("QTM: Cameras:");
                foreach (var camera in rtProtocol.GeneralSettings.CameraSettings)
                {
                    Debug.LogFormat("\t{0}", camera.Model);
                }

                // Reset mocap gameobject
                foreach (Transform child in mocapGameObject.transform)
                {
                    GameObject.Destroy(child.gameObject);
                }

                // Init components to stream
                List <QTMRealTimeSDK.Data.ComponentType> componentsToStream = new List <QTMRealTimeSDK.Data.ComponentType>();

                // Start 2D data stream and print to console
                if (print2DToConsole)
                {
                    Debug.Log("QTM: Starting to stream 2D data, printing to console.");
                    componentsToStream.Add(QTMRealTimeSDK.Data.ComponentType.Component2d);
                }

                // Start 3D data stream...
                if (print3DToConsole || render3D)
                {
                    Debug.Log("QTM: Starting to stream 3D data.");
                    componentsToStream.Add(QTMRealTimeSDK.Data.ComponentType.Component3dResidual);
                    // ...and print to console...
                    if (print3DToConsole)
                    {
                        Debug.Log("QTM: 3D data stream will print to console.");
                    }
                    // ...and/or render as balls
                    if (render3D)
                    {
                        Debug.Log("QTM: 3D data stream will render in world.");
                        rtProtocol.Get3dSettings();
                        balls = new GameObject[rtProtocol.Settings3D.Labels.Count];
                        for (int i = 0; i < balls.Length; i++)
                        {
                            balls[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                            balls[i].transform.parent     = mocapGameObject.transform;
                            balls[i].transform.localScale = new Vector3(0.03f, 0.03f, 0.03f);
                        }
                    }
                }

                // Start 6D data stream and render
                if (render6D)
                {
                    rtProtocol.Get6dSettings();
                    List <QTMRealTimeSDK.Settings.Settings6DOF> qtmBodies = rtProtocol.Settings6DOF.Bodies;
                    foreach (QTMRealTimeSDK.Settings.Settings6DOF body in qtmBodies)
                    {
                        Debug.LogFormat("QTM: Found 6DOF body: {0}", body.Name);
                    }
                    cubes = new GameObject[qtmBodies.Count];
                    for (int i = 0; i < cubes.Length; i++)
                    {
                        cubes[i] = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        cubes[i].transform.parent     = mocapGameObject.transform;
                        cubes[i].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                    }
                    Debug.LogFormat("QTM: Starting to stream 6D data, rendering in world.");
                    componentsToStream.Add(QTMRealTimeSDK.Data.ComponentType.Component6dResidual);
                }
                rtProtocol.StreamFrames(StreamRate.RateFrequency, streamFrequency, componentsToStream);
            }
        }
    }