Example #1
0
 static void Main(string[] args)
 {
     Thread.Sleep(500); //Let the server start first
     try
     {
         Console.WriteLine("Program started. Trying to get connected...");
         Client client = new Client();
         if (client.IsInitialized)
         {
             Console.WriteLine("Connected to server\n");
             client.Send(new Client.Message() { CustomMessage = Client.Message.MessageType.ProtocolVersion, Argument = Client.Message.ProtocolVersion });
             Console.WriteLine("Sent message with protocol version\n");
             var message = client.Receive();
             if (message != null)
             {
                 Console.WriteLine("Got message from server");
                 Console.WriteLine("Message type: " + Enum.GetName(typeof(Client.Message.MessageType), message.Argument));
                 Console.WriteLine("Message arg:  {0}", message.Argument);
                 Console.WriteLine("Message string: {0}\n", message.StringMessage);
             }
         }
         else
         {
             Console.WriteLine("Unable to get connected\n");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Unexpected exception occured  (Main): {0}\n", e.Message);
     }
     Console.WriteLine("Execution finished. Press any key");
     Console.ReadKey();
 }
        /*
            Sends any unlabled markers out over OSC.
            Address Pattern: \unlabledMarker
            Format: String[4]
                MarkerID
                GlobalMarkerPosition.x
                GlobalMarkerPosition.y
                GlobalMarkerPosition.z
        */
        private static void sendUnlabeledMarkers(Client MyClient, UDPSender sender)
        {
            // Get the unlabeled markers
            uint UnlabeledMarkerCount = MyClient.GetUnlabeledMarkerCount().MarkerCount;
            Console.WriteLine("    Unlabeled Markers ({0}):", UnlabeledMarkerCount);
            for (uint UnlabeledMarkerIndex = 0; UnlabeledMarkerIndex < UnlabeledMarkerCount; ++UnlabeledMarkerIndex)
            {
                // Get the global marker translation
                Output_GetUnlabeledMarkerGlobalTranslation _Output_GetUnlabeledMarkerGlobalTranslation
                  = MyClient.GetUnlabeledMarkerGlobalTranslation(UnlabeledMarkerIndex);

                String[] msg = new String[4];
                msg[0] = "UnlabledMarkerID: " + UnlabeledMarkerIndex + "";
                msg[1] = "pos.x: " + _Output_GetUnlabeledMarkerGlobalTranslation.Translation[0].ToString();
                msg[2] = "pos.y: " + _Output_GetUnlabeledMarkerGlobalTranslation.Translation[1].ToString();
                msg[3] = "pos.z: " + _Output_GetUnlabeledMarkerGlobalTranslation.Translation[2].ToString();

                var message = new SharpOSC.OscMessage("/unlabledMarker", msg);
                sender.Send(message);

                Console.WriteLine("      Marker #{0}: ({1}, {2}, {3})",
                                   UnlabeledMarkerIndex,
                                   _Output_GetUnlabeledMarkerGlobalTranslation.Translation[0],
                                   _Output_GetUnlabeledMarkerGlobalTranslation.Translation[1],
                                   _Output_GetUnlabeledMarkerGlobalTranslation.Translation[2]);
            }
        }
        private static void sendLocalRotationQuaternion(Client MyClient, UDPSender sender)
        {
            // Count the number of subjects
            uint SubjectCount = MyClient.GetSubjectCount().SubjectCount;
            for (uint SubjectIndex = 0; SubjectIndex < SubjectCount; ++SubjectIndex)
            {

                // Get the subject name
                string SubjectName = MyClient.GetSubjectName(SubjectIndex).SubjectName;
                Console.WriteLine("    Name: {0}", SubjectName);

                // Get the root segment
                string RootSegment = MyClient.GetSubjectRootSegmentName(SubjectName).SegmentName;
                Console.WriteLine("    Root Segment: {0}", RootSegment);

                //Get the static segment translation
                Output_GetSegmentLocalRotationQuaternion Output =
                MyClient.GetSegmentLocalRotationQuaternion(SubjectName, RootSegment);

                Console.WriteLine("        LOCAL Rotation Quaternion: ({0},{1},{2},{3})",
                                   Output.Rotation[0],
                                   Output.Rotation[1],
                                   Output.Rotation[2],
                                   Output.Rotation[3]);

                String[] msg = new String[5];
                msg[0] = "RigidBody Name: " + SubjectName;
                msg[1] = "q.x: " + Output.Rotation[0].ToString();
                msg[2] = "q.y: " + Output.Rotation[1].ToString();
                msg[3] = "q.z: " + Output.Rotation[2].ToString();
                msg[4] = "q.w: " + Output.Rotation[3].ToString();

                var message = new SharpOSC.OscMessage("/localQuat", msg);
                sender.Send(message);

            }
        }
        /*
            Sends rigid body data out over OSC.
            Address Pattern: \rigidBody
            Format: String[4]
                RigidBodyName
                GlobalPosition.x
                GlobalPosition.y
                GlobalPosition.z
                GlobalOrientation.qx
                GlobalOrientation.qy
                GlobalOrientation.qz
                GlobalOrientation.qw
        */
        private static void sendRigidBodies(Client MyClient, UDPSender sender)
        {
            // Count the number of subjects
            uint SubjectCount = MyClient.GetSubjectCount().SubjectCount;
            for (uint SubjectIndex = 0; SubjectIndex < SubjectCount; ++SubjectIndex)
            {

                // Get the subject name
                string SubjectName = MyClient.GetSubjectName(SubjectIndex).SubjectName;
                Console.WriteLine("    Name: {0}", SubjectName);

                // Get the root segment
                string RootSegment = MyClient.GetSubjectRootSegmentName(SubjectName).SegmentName;
                Console.WriteLine("    Root Segment: {0}", RootSegment);

                //Get the static segment translation
                Output_GetSegmentGlobalTranslation _Output_GetSegmentGlobalTranslation =
                MyClient.GetSegmentGlobalTranslation(SubjectName, RootSegment);
                Console.WriteLine("        Global Translation: ({0},{1},{2}) {3}",
                                   _Output_GetSegmentGlobalTranslation.Translation[0],
                                   _Output_GetSegmentGlobalTranslation.Translation[1],
                                   _Output_GetSegmentGlobalTranslation.Translation[2],
                                   _Output_GetSegmentGlobalTranslation.Occluded);

                // Get the global segment rotation in quaternion co-ordinates
                Output_GetSegmentGlobalRotationQuaternion _Output_GetSegmentGlobalRotationQuaternion =
                MyClient.GetSegmentGlobalRotationQuaternion(SubjectName, RootSegment);
                Console.WriteLine("        Global Rotation Quaternion: ({0},{1},{2},{3}) {4}",
                                   _Output_GetSegmentGlobalRotationQuaternion.Rotation[0],
                                   _Output_GetSegmentGlobalRotationQuaternion.Rotation[1],
                                   _Output_GetSegmentGlobalRotationQuaternion.Rotation[2],
                                   _Output_GetSegmentGlobalRotationQuaternion.Rotation[3],
                                   _Output_GetSegmentGlobalRotationQuaternion.Occluded);

                String[] msg = new String[8];
                msg[0] = "RigidBody Name: "+ SubjectName;
                msg[1] = "pos.x: " + _Output_GetSegmentGlobalTranslation.Translation[0].ToString();
                msg[2] = "pos.y: " + _Output_GetSegmentGlobalTranslation.Translation[1].ToString();
                msg[3] = "pos.z: " + _Output_GetSegmentGlobalTranslation.Translation[2].ToString();
                msg[4] = "q.x: " + _Output_GetSegmentGlobalRotationQuaternion.Rotation[0].ToString();
                msg[5] = "q.y: " + _Output_GetSegmentGlobalRotationQuaternion.Rotation[1].ToString();
                msg[6] = "q.z: " + _Output_GetSegmentGlobalRotationQuaternion.Rotation[2].ToString();
                msg[7] = "q.w: " + _Output_GetSegmentGlobalRotationQuaternion.Rotation[3].ToString();

                // ignore dropped tracking frames
                if (_Output_GetSegmentGlobalTranslation.Translation[0] != 0 &&
                    _Output_GetSegmentGlobalTranslation.Translation[1] != 0 &&
                    _Output_GetSegmentGlobalTranslation.Translation[2] != 0 ) {
                    var message = new SharpOSC.OscMessage("/rigidBody", msg);
                    sender.Send(message);
                }

            }
        }
        /*
            Sends any labled markers out over OSC.
            Address Pattern: \labledMarker
            Format: String[5]
                MarkerID
                MarkerName
                GlobalMarkerPosition.x
                GlobalMarkerPosition.y
                GlobalMarkerPosition.z
        */
        private static void sendLabledMarkers(Client MyClient, UDPSender sender)
        {
            // For each subject in the scene
            uint SubjectCount = MyClient.GetSubjectCount().SubjectCount;
            for (uint SubjectIndex = 0; SubjectIndex < SubjectCount; ++SubjectIndex)
            {
                // Get the subject name
                string SubjectName = MyClient.GetSubjectName(SubjectIndex).SubjectName;

                // Count the number of markers
                uint MarkerCount = MyClient.GetMarkerCount(SubjectName).MarkerCount;

                // for each marker in subject
                for (uint MarkerIndex = 0; MarkerIndex < MarkerCount; ++MarkerIndex)
                {
                    // Get the marker name
                    string MarkerName = MyClient.GetMarkerName(SubjectName, MarkerIndex).MarkerName;

                    // Get the global marker translation
                    Output_GetMarkerGlobalTranslation _Output_GetMarkerGlobalTranslation =
                      MyClient.GetMarkerGlobalTranslation(SubjectName, MarkerName);

                    String[] msg = new String[5];
                    msg[0] = "RigidBody Name: "+MarkerName;
                    msg[1] = "MarkerID: " + MarkerIndex;
                    msg[2] = "pos.x: " + _Output_GetMarkerGlobalTranslation.Translation[0].ToString();
                    msg[3] = "pos.y: " + _Output_GetMarkerGlobalTranslation.Translation[1].ToString();
                    msg[4] = "pos.z: " + _Output_GetMarkerGlobalTranslation.Translation[2].ToString();

                    // ignore dropped tracking locations
                    if (_Output_GetMarkerGlobalTranslation.Translation[0] != 0 &&
                        _Output_GetMarkerGlobalTranslation.Translation[1] != 0 &&
                        _Output_GetMarkerGlobalTranslation.Translation[2] != 0)
                    {
                        var message = new SharpOSC.OscMessage("/labledMarker", msg);
                        sender.Send(message);
                    }

                    Console.WriteLine("      Marker #{0}: {1} ({2}, {3}, {4}) {5}",
                                       MarkerIndex,
                                       MarkerName,
                                       _Output_GetMarkerGlobalTranslation.Translation[0],
                                       _Output_GetMarkerGlobalTranslation.Translation[1],
                                       _Output_GetMarkerGlobalTranslation.Translation[2],
                                       _Output_GetMarkerGlobalTranslation.Occluded);
               }
            }
        }