/*
            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);
                }

            }
        }
        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);

            }
        }