Inheritance: OscPacket
Ejemplo n.º 1
0
        private void UpdateUI(Bitmap bitmap) //Выводим рожу
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                if (bitmap != null)
                {
                    imageBase.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
                    ScaleTransform mainTransform    = new ScaleTransform();
                    mainTransform.ScaleX            = -1;
                    mainTransform.ScaleY            = 1;
                    imageBase.RenderTransform       = mainTransform;


                    headRollResult.Text = headRoll.ToString();
                    var headRollMessage = new SharpOSC.OscMessage("/rotation/roll", headRoll);
                    Sender.Send(headRollMessage);
                    headYawResult.Text = headYaw.ToString();
                    var headYawMessage = new SharpOSC.OscMessage("/rotation/yaw", headYaw);
                    Sender.Send(headYawMessage);
                    headPitchResult.Text = headPitch.ToString();
                    var headPitchMessage = new SharpOSC.OscMessage("/rotation/pitch", headPitch);
                    Sender.Send(headPitchMessage);


                    Graphics graphics = Graphics.FromImage(bitmap); //Херачим прямоугольник

                    System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.DeepSkyBlue);
                    graphics.DrawRectangle(pen, faceRectangleX, faceRectangleY, faceRectangleWidth, faceRectangleHeight);

                    imageBase.Source = BitmapToBitmapSource(bitmap);
                }
            }));
        }
Ejemplo n.º 2
0
        public string update_leave(Dictionary <string, object> parameters)
        {
            try
            {
                double dur    = (double)parameters["dur"];
                int    state  = (int)parameters["state"];
                string label  = (string)parameters["label"];
                string scheme = (string)parameters["scheme"];
                double time   = (double)parameters["time"];


                if (library == OSCLibrary.SharpOSC)
                {
                    var message = new SharpOSC.OscMessage("/evnt", scheme, label, (Int32)(time * 1000), (Int32)(dur * 1000), (Int32)state, (Int32)0);
                    sharposcclient.Send(message);
                }
                else
                {
                    OscElement message = new OscElement("/evnt", scheme, label, (Int32)(time * 1000), (Int32)(dur * 1000), (Int32)state, (Int32)0);
                    ventuzclient.Send(message);
                }
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }

            return(null);
        }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        var message = new SharpOSC.OscMessage("/note", 60, 100, 1000);
        var sender  = new SharpOSC.UDPSender("127.0.0.1", 9000);

        sender.Send(message);
    }
Ejemplo n.º 4
0
    public void Test()
    {
        var message = new SharpOSC.OscMessage(Address, Msg);
        var sender  = new SharpOSC.UDPSender("127.0.0.1", 53001);

        sender.Send(message);
    }
Ejemplo n.º 5
0
    // Function to send Msg to Linux
    void sendPos_polar(GameObject sound_sphere)
    {
        // x and z for plane, y is height
        float pos_x = sound_sphere.GetComponent <Transform> ().position.x;
        float pos_y = sound_sphere.GetComponent <Transform> ().position.y;
        float pos_z = sound_sphere.GetComponent <Transform> ().position.z;

        float vol = sound_sphere.GetComponent <Transform>().localScale.x;

        float rad = Mathf.Sqrt(pos_x * pos_x + pos_z * pos_z + (pos_y - 1.6f) * (pos_y - 1.6f));
        float azi = Mathf.Atan2(pos_x, pos_z) * 180 / Mathf.PI;
        float ele = Mathf.Atan2(pos_y - 1.6f, Mathf.Sqrt(pos_x * pos_x + pos_z * pos_z)) * 180 / Mathf.PI;

        if (rad != 0f)
        {
            vol = vol / rad;
        }


        //Debug.Log(pos_x);
        //Debug.Log(pos_y);
        //Debug.Log(pos_z);
        //Debug.Log(vol);

        var msg_azi = new SharpOSC.OscMessage("/0x00/azi", azi);
        var msg_ele = new SharpOSC.OscMessage("/0x00/ele", ele);
        var msg_vol = new SharpOSC.OscMessage("/0x00/gain", vol);

        sender.Send(msg_azi);
        sender.Send(msg_ele);
        sender.Send(msg_vol);
    }
Ejemplo n.º 6
0
    public static void SendGenerateFromScratch()
    {
        string dummy   = "dummy";
        var    message = new SharpOSC.OscMessage("/something/generate_from_scratch", dummy);

        sender.Send(message);
    }
Ejemplo n.º 7
0
    private void Awake()
    {
        gameObject.SetActive(!bool.Parse(Config.Read(CONFIG_KEYS.audiodisable)));
        _appStateBroker = AppStateBroker.Instance;

        if (DEVELOPER_MODE)
        {
            AudioSourceOutputDevice[] channels =
                transform.GetComponentsInChildren <AudioSourceOutputDevice>();

            foreach (AudioSourceOutputDevice c in channels)
            {
                c.enabled = false;
            }
        }

        SFX_Volume        = float.Parse(Config.Read(CONFIG_KEYS.lanevolume));
        Ambient_Volume    = int.Parse(Config.Read(CONFIG_KEYS.ambientvolume));
        refVolumeOffset   = float.Parse(Config.Read(CONFIG_KEYS.refvolumeoffset));
        CrowdVoluemOffset = float.Parse(Config.Read(CONFIG_KEYS.crowdvolumeoffset));

        var message_vol = new SharpOSC.OscMessage("/maxVol", Ambient_Volume);

        _UdpSender.Send(message_vol);
    }
Ejemplo n.º 8
0
    public void sendOscMessage(string mess)
    {
        Debug.Log("sendOscMessage");
        var message = new SharpOSC.OscMessage(mess);
        var sender  = new SharpOSC.UDPSender("127.0.0.1", 9000);

        sender.Send(message);
    }
Ejemplo n.º 9
0
    private void Start()
    {
        //for each lanes
        AudioSequenceObservable
        .Subscribe(sq => PlaySound(sq.Item1, sq.Item2, SFX_Volume))
        .AddTo(gameObject);


        //for Ambient Sound
        _appStateBroker
        .CurrentRound
        .Subscribe(round =>
        {
            switch (round)
            {
            case Rounds.Idle:
                var message_idle = new SharpOSC.OscMessage("/idle");
                _UdpSender.Send(message_idle);
                break;

            case Rounds.R1:
                var message_r1_lineup = new SharpOSC.OscMessage("/p1", "lineup");
                _UdpSender.Send(message_r1_lineup);
                break;

            case Rounds.R1_Hike:
                var message_r1_hike = new SharpOSC.OscMessage("/p1", "hike");
                _UdpSender.Send(message_r1_hike);
                break;

            case Rounds.R2:
                var message_r2_lineup = new SharpOSC.OscMessage("/p2", "lineup");
                _UdpSender.Send(message_r2_lineup);
                break;

            case Rounds.R2_Hike:
                var message_r2_hike = new SharpOSC.OscMessage("/p2", "hike");
                _UdpSender.Send(message_r2_hike);
                break;

            case Rounds.R3:
                var message_r3_lineup = new SharpOSC.OscMessage("/p3", "lineup");
                _UdpSender.Send(message_r3_lineup);
                break;

            case Rounds.R3_Hike:
                var message_r3_hike = new SharpOSC.OscMessage("/p3", "hike");
                _UdpSender.Send(message_r3_hike);
                break;

            case Rounds.Finish:
                var message_finish = new SharpOSC.OscMessage("/idle");
                _UdpSender.Send(message_finish);
                break;
            }
        })
        .AddTo(gameObject);
    }
Ejemplo n.º 10
0
        public override void OnFrame(Controller controller)
        {
            Frame currentFrame = controller.Frame();

            currentTime = currentFrame.Timestamp;
            timeChanged = currentTime - previousTime;

            if (timeChanged > 1000)
            {
                if (!currentFrame.Hands.IsEmpty)
                {
                    Finger finger = currentFrame.Fingers[0];

                    Screen screen = controller.LocatedScreens.ClosestScreenHit(finger);

                    if (screen != null && screen.IsValid)
                    {
                        var tipVelocity = ( int )finger.TipVelocity.Magnitude;

                        //if ( tipVelocity > 25 )
                        //{
                        var xScreenIntersect = screen.Intersect(finger, true).x;
                        var yScreenIntersect = screen.Intersect(finger, true).y;

                        if (xScreenIntersect.ToString() != "NaN")
                        {
                            var x = ( int )(xScreenIntersect * screen.WidthPixels);
                            var y = ( int )(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels));

                            Console.WriteLine("Screen intersect X: " + xScreenIntersect.ToString());
                            Console.WriteLine("Screen intersect Y: " + yScreenIntersect.ToString());
                            Console.WriteLine("Width pixels: " + screen.WidthPixels.ToString());
                            Console.WriteLine("Height pixels: " + screen.HeightPixels.ToString());

                            Console.WriteLine("\n");

                            Console.WriteLine("x: " + x.ToString());
                            Console.WriteLine("y: " + y.ToString());

                            Console.WriteLine("\n");

                            Console.WriteLine("Tip velocity: " + tipVelocity.ToString());

                            var message = new SharpOSC.OscMessage("/mouse", x, y, tipVelocity);
                            var sender  = new SharpOSC.UDPSender("127.0.0.1", 55555);
                            sender.Send(message);
                            //MouseCursor.MoveCursor( x, y );
                            Console.WriteLine("\n" + new String('=', 40) + "\n");
                        }
                        //}
                    }
                }
            }

            previousTime = currentTime;
        }
Ejemplo n.º 11
0
        public void SendOscControlMessage(string address, params object[] values)
        {
            Console.WriteLine("Sending {0}", address);
            var oscMsg = new OscMessage(address, values);

            lock (sendMessages)
            {
                sendMessages[oscMsg.Address] = oscMsg;
            }
        }
Ejemplo n.º 12
0
        public void SendOscMessage(string address, double value)
        {
            Console.WriteLine("Sending {0} - {1}", address, value);
            var oscMsg = new OscMessage(address, (float)value);

            lock (sendMessages)
            {
                sendMessages[oscMsg.Address] = oscMsg;
            }
        }
    // send a message to our listener
    public bool SendMessage(string address, params object[] args)
    {
        if (mySender == null)
        {
            return(false);
        }

        SharpOSC.OscMessage newMessage = new SharpOSC.OscMessage(address, args);
        mySender.Send(newMessage);

        return(true);
    }
Ejemplo n.º 14
0
    // send a message to all our listeners
    public bool SendMessage(string address, params object[] args)
    {
        if (mySenders.Count == 0)
        {
            return(false);
        }

        SharpOSC.OscMessage newMessage = new SharpOSC.OscMessage(address, args);
        foreach (SharpOSC.UDPSender sender in mySenders.Values)
        {
            sender.Send(newMessage);
        }

        return(true);
    }
    void InitiateConnection()
    {
        // initialize the sender: easy!
        mySender = new SharpOSC.UDPSender(myAddress.Address.ToString(), myAddress.Port);

        // initialize the listener: create a callback to route messages
        SharpOSC.HandleOscPacket listenerCallback = delegate(SharpOSC.OscPacket packet)
        {
            // get message
            SharpOSC.OscMessage messageReceived = (SharpOSC.OscMessage)packet;

            // send message along to be processed on the main thread in Update()
            myOSCIncomingMessages.Enqueue(Tuple.Create(messageReceived.Address, messageReceived.Arguments));
        };

        // initialize the listener
        myListener = new SharpOSC.UDPListener(myAddress.Port, listenerCallback);


        // tell the other side we exist
        SendMessage("/___broadcastToMePlease___", GetMyIP());
    }
Ejemplo n.º 16
0
        public positionMessages(indivJoint myJoint)
        {
            register = myJoint.posReg;
            //sender = msend;
            StringBuilder addressRoot = new StringBuilder();
            addressRoot.Append("/");
            addressRoot.Append(myJoint.type.ToString());
            addressRoot.Append("/");
            String root = addressRoot.ToString();

            StringBuilder xAddress = new StringBuilder(root);
            StringBuilder yAddress = new StringBuilder(root);
            StringBuilder zAddress = new StringBuilder(root);

            xAddress.Append("x");
            yAddress.Append("y");
            zAddress.Append("z");

            x_OSC = new OscMessage(xAddress.ToString(), (float)myJoint.loc.X);
            y_OSC = new OscMessage(yAddress.ToString(), (float)myJoint.loc.Y);
            z_OSC = new OscMessage(zAddress.ToString(), (float)myJoint.loc.Z);
        }
Ejemplo n.º 17
0
        public distanceMessages(jPair myJPair)
        {
            register = myJPair.distReg;
            //messageSender = mSend;
            StringBuilder addressRoot = new StringBuilder();
            addressRoot.Append("/");
            addressRoot.Append(myJPair.jointType0.ToString());
            addressRoot.Append("_");
            addressRoot.Append(myJPair.jointType1.ToString());
            addressRoot.Append("/");
            String root = addressRoot.ToString();

            StringBuilder xAddress = new StringBuilder(root);
            StringBuilder yAddress = new StringBuilder(root);
            StringBuilder zAddress = new StringBuilder(root);
            StringBuilder xyAddress = new StringBuilder(root);
            StringBuilder xzAddress = new StringBuilder(root);
            StringBuilder yzAddress = new StringBuilder(root);
            StringBuilder xyzAddress = new StringBuilder(root);
            StringBuilder angle = new StringBuilder(root);

            xAddress.Append("x");
            yAddress.Append("y");
            zAddress.Append("z");
            xyAddress.Append("xy");
            xzAddress.Append("xz");
            yzAddress.Append("yz");
            xyzAddress.Append("xyz");
            angle.Append("theta");

            xdistOSC = new OscMessage(xAddress.ToString(), (float)myJPair.pair.xdist);
            ydistOSC = new OscMessage(yAddress.ToString(), (float)myJPair.pair.ydist);
            zdistOSC = new OscMessage(zAddress.ToString(), (float)myJPair.pair.zdist);
            xydistOSC = new OscMessage(xyAddress.ToString(), (float)myJPair.pair.xydist);
            xzdistOSC = new OscMessage(xzAddress.ToString(), (float)myJPair.pair.xzdist);
            yzdistOSC = new OscMessage(yzAddress.ToString(), (float)myJPair.pair.yzdist);
            xyzdistOSC = new OscMessage(xyzAddress.ToString(), (float)myJPair.pair.xyzdist);
            angleOSC = new OscMessage(angle.ToString(), (float)myJPair.pair.theta);
        }
Ejemplo n.º 18
0
    // Function to send OSC messages to Linux
    void sendPos_polar(float pos_x, float pos_y, float pos_z, float scale)
    {
        // Calculate polar coordinates
        float vol = scale;
        float rad = Mathf.Sqrt(pos_x * pos_x + pos_z * pos_z + pos_y * pos_y);
        float azi = Mathf.Atan2(pos_x, pos_z) * 180 / Mathf.PI;
        float ele = Mathf.Atan2(pos_y, Mathf.Sqrt(pos_x * pos_x + pos_z * pos_z)) * 180 / Mathf.PI;

        // Include distance for volume
        if (rad != 0f)
        {
            vol = vol / rad;
        }
        // Create messages
        var msg_azi = new SharpOSC.OscMessage("/0x00/azi", azi);
        var msg_ele = new SharpOSC.OscMessage("/0x00/ele", ele);
        var msg_vol = new SharpOSC.OscMessage("/0x00/gain", vol);

        // Send to Linux
        sender.Send(msg_azi);
        sender.Send(msg_ele);
        sender.Send(msg_vol);
    }
Ejemplo n.º 19
0
    // Function to send Msg to Linux
    void sendPos(GameObject pos_arr)
    {
        // x and z for plane, y is height
        float pos_x = pos_arr.GetComponent <Transform> ().position.x;
        float pos_y = pos_arr.GetComponent <Transform> ().position.y;
        float pos_z = pos_arr.GetComponent <Transform> ().position.z;

        float azi;
        float ele;

        //Debug.Log(pos_x);
        //Debug.Log(pos_y);
        //Debug.Log(pos_z);

        azi = Mathf.Atan2(pos_x, pos_z) * 180 / Mathf.PI;
        ele = Mathf.Atan2(pos_y - 1.6f, Mathf.Sqrt(pos_x * pos_x + pos_z * pos_z)) * 180 / Mathf.PI;

        var msg_azi = new SharpOSC.OscMessage("/0x00/azi", azi);
        var msg_ele = new SharpOSC.OscMessage("/0x00/ele", ele);
        var sender  = new SharpOSC.UDPSender(IP_add, port);

        sender.Send(msg_azi);
        sender.Send(msg_ele);
    }
Ejemplo n.º 20
0
    void Start()
    {
        // start discoverability, telling people who know discoveryIdentifier about OSCPort
        myBeacon            = new BeaconLib.Beacon(discoveryIdentifier, OSCPort);
        myBeacon.BeaconData = "";
        myBeacon.Start();

        // start OSC listener on port OSCPort
        // define the callback
        SharpOSC.HandleOscPacket listenerCallback = delegate(SharpOSC.OscPacket packet)
        {
            // get message
            SharpOSC.OscMessage messageReceived = (SharpOSC.OscMessage)packet;

            // send message along to be processed on the main thread in Update()
            myOSCIncomingMessages.Enqueue(Tuple.Create(messageReceived.Address, messageReceived.Arguments));
        };

        // tell the callback our hidden action
        ListenForMessage("/___broadcastToMePlease___", RespondToNewListener);

        // set up the callback
        myListener = new SharpOSC.UDPListener(OSCPort, listenerCallback);
    }
Ejemplo n.º 21
0
        internal void ProcessControlMessage(OscMessage msg)
        {
            if (msg.Address == "/Control/PresetData")
            {
                var serializedData = msg.Arguments[0] as string;
                if (serializedData == null)
                    return;

                var data = serializedData
                    .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(x => x.Split('='))
                    .Where(x => x.Length == 2)
                    .Select(x => new { Key = x[0], Value = x[1] })
                    .ToDictionary(x => x.Key, x => x.Value);

                SelectedBank = data.GetValueOrDefault("BankName", "Unknown Bank");
                SelectedPreset = data.GetValueOrDefault("PresetName", "Unknown Preset");
            }
            else if(msg.Address == "/Control/ParameterData")
            {
                var module = (Module)(int)msg.Arguments[0];
                var parameter = (int)msg.Arguments[1];
                var floatVal = (float)msg.Arguments[2];
                var formattedString = (string)msg.Arguments[3];
                ProcessParameterUpdate(module, parameter, floatVal, formattedString.Trim());
                RequestVisual(module, parameter);
            }
            else if (msg.Address == "/Control/Waveforms")
            {
                for (int i = 0; i < msg.Arguments.Length - 1; i+=2)
                {
                    var id = (int)msg.Arguments[i];
                    var specifier = ((string)msg.Arguments[i + 1]).Replace("/Wavetables/", "");
                    waveforms[id] = specifier;
                }

                WaveformList = waveforms.ToDictionary(x => x.Key, x => x.Value);
            }
            else if (msg.Address == "/Control/Banks")
            {
                if (msg.Arguments.Length != 1 || !(msg.Arguments[0] is string))
                    return;

                var bankString = (string)msg.Arguments.First();
                var banks = bankString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (banks.Length == 0)
                    return;

                presetBanks.Clear();
                foreach (var bank in banks)
                    presetBanks[bank] = new List<string>();
                NotifyPropertyChanged(nameof(Banks));
            }
            else if (msg.Address == "/Control/Presets")
            {
                if (msg.Arguments.Length != 2 || !(msg.Arguments[0] is string) || !(msg.Arguments[1] is string))
                    return;

                var bankName = (string)msg.Arguments.First();
                var presets = ((string)msg.Arguments.Last()).Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                if (!presetBanks.ContainsKey(bankName) || presets.Length == 0)
                    return;

                presetBanks[bankName].Clear();
                foreach (var preset in presets)
                    presetBanks[bankName].Add(preset);

                NotifyPropertyChanged(nameof(Presets));
            }
            else if (msg.Address == "/Control/PresetsChanged")
            {
                if (msg.Arguments.Length != 1 || !(msg.Arguments[0] is string))
                    return;

                var bank = msg.Arguments.First() as string;
                controlManager.SendOscControlMessage("/Control/RequestPresets", bank);
            }
            else if (msg.Address.StartsWith("/Control/Visual"))
            {
                UpdateVisual((byte[])msg.Arguments[0], (int)msg.Arguments[1]);
            }
            else if (msg.Address == "/Control/VoiceState")
            {
                SetVoiceState((byte[])msg.Arguments[0]);
            }
        }
        /// <summary>
        /// Handles the body frame data arriving from the sensor
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            bool dataReceived = false;

            using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    if (this.bodies == null)
                    {
                        this.bodies = new Body[bodyFrame.BodyCount];
                    }

                    // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
                    // As long as those body objects are not disposed and not set to null in the array,
                    // those body objects will be re-used.
                    bodyFrame.GetAndRefreshBodyData(this.bodies);
                    dataReceived = true;
                }
            }

            if (dataReceived)
            {
                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    // Draw a transparent background to set the render size
                    dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));

                    int penIndex = 0;
                    foreach (Body body in this.bodies)
                    {
                        Pen drawPen = this.bodyColors[penIndex++];

                        if (body.IsTracked)
                        {
                            this.DrawClippedEdges(body, dc);

                            IReadOnlyDictionary <JointType, Joint> joints = body.Joints;

                            // log joints
                            StringBuilder builder = new StringBuilder();

                            // it's ugly and verbose, but it's clear and in guaranteed order
                            builder.Append(joints[JointType.AnkleLeft].Position.X + " " + joints[JointType.AnkleLeft].Position.Y + " " + joints[JointType.AnkleLeft].Position.Z + " ");
                            builder.Append(joints[JointType.AnkleRight].Position.X + " " + joints[JointType.AnkleRight].Position.Y + " " + joints[JointType.AnkleRight].Position.Z + " ");
                            builder.Append(joints[JointType.ElbowLeft].Position.X + " " + joints[JointType.ElbowLeft].Position.Y + " " + joints[JointType.ElbowLeft].Position.Z + " ");
                            builder.Append(joints[JointType.ElbowRight].Position.X + " " + joints[JointType.ElbowRight].Position.Y + " " + joints[JointType.ElbowRight].Position.Z + " ");
                            builder.Append(joints[JointType.FootLeft].Position.X + " " + joints[JointType.FootLeft].Position.Y + " " + joints[JointType.FootLeft].Position.Z + " ");
                            builder.Append(joints[JointType.FootRight].Position.X + " " + joints[JointType.FootRight].Position.Y + " " + joints[JointType.FootRight].Position.Z + " ");
                            builder.Append(joints[JointType.HandLeft].Position.X + " " + joints[JointType.HandLeft].Position.Y + " " + joints[JointType.HandLeft].Position.Z + " ");
                            builder.Append(joints[JointType.HandRight].Position.X + " " + joints[JointType.HandRight].Position.Y + " " + joints[JointType.HandRight].Position.Z + " ");
                            builder.Append(joints[JointType.HandTipLeft].Position.X + " " + joints[JointType.HandTipLeft].Position.Y + " " + joints[JointType.HandTipLeft].Position.Z + " ");
                            builder.Append(joints[JointType.HandTipRight].Position.X + " " + joints[JointType.HandTipRight].Position.Y + " " + joints[JointType.HandTipRight].Position.Z + " ");
                            builder.Append(joints[JointType.Head].Position.X + " " + joints[JointType.Head].Position.Y + " " + joints[JointType.Head].Position.Z + " ");
                            builder.Append(joints[JointType.HipLeft].Position.X + " " + joints[JointType.HipLeft].Position.Y + " " + joints[JointType.HipLeft].Position.Z + " ");
                            builder.Append(joints[JointType.HipRight].Position.X + " " + joints[JointType.HipRight].Position.Y + " " + joints[JointType.HipRight].Position.Z + " ");
                            builder.Append(joints[JointType.KneeLeft].Position.X + " " + joints[JointType.KneeLeft].Position.Y + " " + joints[JointType.KneeLeft].Position.Z + " ");
                            builder.Append(joints[JointType.KneeRight].Position.X + " " + joints[JointType.KneeRight].Position.Y + " " + joints[JointType.KneeRight].Position.Z + " ");
                            builder.Append(joints[JointType.Neck].Position.X + " " + joints[JointType.Neck].Position.Y + " " + joints[JointType.Neck].Position.Z + " ");
                            builder.Append(joints[JointType.ShoulderLeft].Position.X + " " + joints[JointType.ShoulderLeft].Position.Y + " " + joints[JointType.ShoulderLeft].Position.Z + " ");
                            builder.Append(joints[JointType.ShoulderRight].Position.X + " " + joints[JointType.ShoulderRight].Position.Y + " " + joints[JointType.ShoulderRight].Position.Z + " ");
                            builder.Append(joints[JointType.SpineBase].Position.X + " " + joints[JointType.SpineBase].Position.Y + " " + joints[JointType.SpineBase].Position.Z + " ");
                            builder.Append(joints[JointType.SpineMid].Position.X + " " + joints[JointType.SpineMid].Position.Y + " " + joints[JointType.SpineMid].Position.Z + " ");
                            builder.Append(joints[JointType.SpineShoulder].Position.X + " " + joints[JointType.SpineShoulder].Position.Y + " " + joints[JointType.SpineShoulder].Position.Z + " ");
                            builder.Append(joints[JointType.ThumbLeft].Position.X + " " + joints[JointType.ThumbLeft].Position.Y + " " + joints[JointType.ThumbLeft].Position.Z + " ");
                            builder.Append(joints[JointType.ThumbRight].Position.X + " " + joints[JointType.ThumbRight].Position.Y + " " + joints[JointType.ThumbRight].Position.Z + " ");
                            builder.Append(joints[JointType.WristLeft].Position.X + " " + joints[JointType.WristLeft].Position.Y + " " + joints[JointType.WristLeft].Position.Z + " ");
                            builder.Append(joints[JointType.WristRight].Position.X + " " + joints[JointType.WristRight].Position.Y + " " + joints[JointType.WristRight].Position.Z + " ");

                            string jointStr = builder.ToString();
                            log.Info(jointStr);
                            // convert the joint points to depth (display) space
                            Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>();

                            foreach (JointType jointType in joints.Keys)
                            {
                                // sometimes the depth(Z) of an inferred joint may show as negative
                                // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
                                CameraSpacePoint position = joints[jointType].Position;
                                if (position.Z < 0)
                                {
                                    position.Z = InferredZPositionClamp;
                                }

                                DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position);
                                jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                            }

                            this.DrawBody(joints, jointPoints, dc, drawPen);

                            this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
                            this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);

                            //by KO

                            // setting data set : the name of the element + x + y + z

                            //FOR MUSIC

                            var HandRight   = new SharpOSC.OscMessage(" /HandRight", " ", joints[JointType.HandRight].Position.X.ToString(), " ", joints[JointType.HandRight].Position.Y.ToString(), " ", joints[JointType.HandRight].Position.Z.ToString());
                            var HandTipLeft = new SharpOSC.OscMessage(" /HandTipLeft", " ", joints[JointType.HandTipLeft].Position.X.ToString(), " ", joints[JointType.HandTipLeft].Position.Y.ToString(), " ", joints[JointType.HandTipLeft].Position.Z.ToString());
                            var AnkleLeft   = new SharpOSC.OscMessage(" /AnkleLeft", " ", joints[JointType.AnkleLeft].Position.X.ToString(), " ", joints[JointType.AnkleLeft].Position.Y.ToString(), " ", joints[JointType.AnkleLeft].Position.Z.ToString());
                            var AnkleRight  = new SharpOSC.OscMessage(" /AnkleRight", " ", joints[JointType.AnkleRight].Position.X.ToString(), " ", joints[JointType.AnkleRight].Position.Y.ToString(), " ", joints[JointType.AnkleRight].Position.Z.ToString());


                            //PureData
                            //var HandRight = new SharpOSC.OscMessage("/HandRight/position", joints[JointType.HandRight].Position.X, joints[JointType.HandRight].Position.Y,  joints[JointType.HandRight].Position.Z);
                            //var HandTipLeft = new SharpOSC.OscMessage("/HandTipLeft/position", joints[JointType.HandTipLeft].Position.X, joints[JointType.HandTipLeft].Position.Y, joints[JointType.HandTipLeft].Position.Z);
                            //var AnkleLeft = new SharpOSC.OscMessage("/AnkleLeft", " ", joints[JointType.AnkleLeft].Position.X.ToString(), " ", joints[JointType.AnkleLeft].Position.Y.ToString(), " ", joints[JointType.AnkleLeft].Position.Z.ToString());
                            //var AnkleRight = new SharpOSC.OscMessage("/AnkleRight", " ", joints[JointType.AnkleRight].Position.X.ToString(), " ", joints[JointType.AnkleRight].Position.Y.ToString(), " ", joints[JointType.AnkleRight].Position.Z.ToString());



                            var ElbowLeft     = new SharpOSC.OscMessage(" /ElbowLeft", " ", joints[JointType.ElbowLeft].Position.X.ToString(), " ", joints[JointType.ElbowLeft].Position.Y.ToString(), " ", joints[JointType.ElbowLeft].Position.Z.ToString());
                            var ElbowRight    = new SharpOSC.OscMessage(" /ElbowRight", " ", joints[JointType.ElbowRight].Position.X.ToString(), " ", joints[JointType.ElbowRight].Position.Y.ToString(), " ", joints[JointType.ElbowRight].Position.Z.ToString());
                            var FootLeft      = new SharpOSC.OscMessage(" /FootLeft", joints[JointType.FootLeft].Position.X.ToString(), joints[JointType.FootLeft].Position.Y.ToString(), joints[JointType.FootLeft].Position.Z.ToString());
                            var FootRight     = new SharpOSC.OscMessage(" /FootRight", joints[JointType.FootRight].Position.X.ToString(), joints[JointType.FootRight].Position.Y.ToString(), joints[JointType.FootRight].Position.Z.ToString());
                            var HandLeft      = new SharpOSC.OscMessage(" /HandLeft", " ", joints[JointType.HandLeft].Position.X.ToString(), " ", joints[JointType.HandLeft].Position.Y.ToString(), " ", joints[JointType.HandLeft].Position.Z.ToString());
                            var HandTipRight  = new SharpOSC.OscMessage(" /HandTipRight", joints[JointType.HandTipRight].Position.X.ToString(), joints[JointType.HandTipRight].Position.Y.ToString(), joints[JointType.AnkleLeft].Position.Z.ToString());
                            var Head          = new SharpOSC.OscMessage(" /Head", joints[JointType.Head].Position.X.ToString(), joints[JointType.Head].Position.Y.ToString(), joints[JointType.Head].Position.Z.ToString());
                            var HipLeft       = new SharpOSC.OscMessage(" /HipLeft", joints[JointType.HipLeft].Position.X.ToString(), joints[JointType.HipLeft].Position.Y.ToString(), joints[JointType.HipLeft].Position.Z.ToString());
                            var HipRight      = new SharpOSC.OscMessage(" /HipRight", joints[JointType.HipRight].Position.X.ToString(), joints[JointType.HipRight].Position.Y.ToString(), joints[JointType.HipRight].Position.Z.ToString());
                            var KneeLeft      = new SharpOSC.OscMessage(" /KneeLeft", joints[JointType.KneeLeft].Position.X.ToString(), joints[JointType.KneeLeft].Position.Y.ToString(), joints[JointType.KneeLeft].Position.Z.ToString());
                            var KneeRight     = new SharpOSC.OscMessage(" /KneeRight", joints[JointType.KneeRight].Position.X.ToString(), joints[JointType.KneeRight].Position.Y.ToString(), joints[JointType.KneeRight].Position.Z.ToString());
                            var Neck          = new SharpOSC.OscMessage(" /Neck", joints[JointType.Neck].Position.X.ToString(), joints[JointType.Neck].Position.Y.ToString(), joints[JointType.Neck].Position.Z.ToString());
                            var ShoulderLeft  = new SharpOSC.OscMessage(" /ShoulderLeft", joints[JointType.ShoulderLeft].Position.X.ToString(), joints[JointType.ShoulderLeft].Position.Y.ToString(), joints[JointType.ShoulderLeft].Position.Z.ToString());
                            var ShoulderRight = new SharpOSC.OscMessage(" /ShoulderRight", joints[JointType.ShoulderRight].Position.X.ToString(), joints[JointType.ShoulderRight].Position.Y.ToString(), joints[JointType.ShoulderRight].Position.Z.ToString());
                            var SpineBase     = new SharpOSC.OscMessage(" /SpineBase", joints[JointType.SpineBase].Position.X.ToString(), joints[JointType.SpineBase].Position.Y.ToString(), joints[JointType.SpineBase].Position.Z.ToString());
                            var SpineMid      = new SharpOSC.OscMessage(" /SpineMid", joints[JointType.SpineMid].Position.X.ToString(), joints[JointType.SpineMid].Position.Y.ToString(), joints[JointType.SpineMid].Position.Z.ToString());
                            var SpineShoulder = new SharpOSC.OscMessage(" /SpineShoulder", joints[JointType.SpineShoulder].Position.X.ToString(), joints[JointType.SpineShoulder].Position.Y.ToString(), joints[JointType.SpineShoulder].Position.Z.ToString());
                            var ThumbLeft     = new SharpOSC.OscMessage(" /ThumbLeft", joints[JointType.ThumbLeft].Position.X.ToString(), joints[JointType.ThumbLeft].Position.Y.ToString(), joints[JointType.ThumbLeft].Position.Z.ToString());
                            var ThumbRight    = new SharpOSC.OscMessage(" /ThumbRight", joints[JointType.ThumbRight].Position.X.ToString(), joints[JointType.ThumbRight].Position.Y.ToString(), joints[JointType.ThumbRight].Position.Z.ToString());
                            var WristLeft     = new SharpOSC.OscMessage(" /WristLeft", joints[JointType.WristLeft].Position.X.ToString(), joints[JointType.WristLeft].Position.Y.ToString(), joints[JointType.WristLeft].Position.Z.ToString());
                            var WristRight    = new SharpOSC.OscMessage(" /WristRight", joints[JointType.WristRight].Position.X.ToString(), joints[JointType.WristRight].Position.Y.ToString(), joints[JointType.WristRight].Position.Z.ToString());

                            // OSC message for area
                            // var Area = new SharpOSC.OscMessage("/area", testV.ToString());

                            // Sending UDP
                            OscBundle oscBundle = new OscBundle(0, HandRight, HandLeft, AnkleRight, AnkleLeft);//FOR MUSIC
                            //OscBundle oscBundle = new OscBundle(0, HandRight);//FOR PureData
                            //OscBundle oscBundle = new OscBundle(0, HandLeft, HandRight, HandTipLeft, HandTipRight);

                            /*FootLeft, FootRight, HandLeft, HandRight, HandTipLeft,
                             * HandTipRight, Head, HipLeft, HipRight, KneeLeft, KneeRight, Neck, ShoulderLeft, ShoulderRight, SpineBase,
                             * SpineMid, SpineShoulder, ThumbLeft, ThumbRight, WristLeft, WristRight);
                             */

                            Console.WriteLine("TEST SENDING:");
                            Console.WriteLine(oscBundle.ToString());
                            //Send Method (message)
                            udpSender.Send(oscBundle);
                        }
                    }

                    // prevent drawing outside of our render area
                    this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
                }
            }
        }
Ejemplo n.º 23
0
    public static void SendLog(string content)
    {
        var message = new SharpOSC.OscMessage("/something/log", content);

        sender.Send(message);
    }
Ejemplo n.º 24
0
    public static void SendNoteOff(int noteNumber)
    {
        var message = new SharpOSC.OscMessage("/something/note_off", noteNumber);

        sender.Send(message);
    }
        /*
            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]);
            }
        }
        /*
            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);

            }
        }
        /*
            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);
               }
            }
        }
Ejemplo n.º 29
0
        /*
         * public void DoThisAllTheTime()
         * {
         *  var listener = new UDPListener(55555);
         *  //MessageBox.Show("Starting OSC Listener");
         *  label1.Text = "Starting OSC Listener";
         *  OscMessage messageReceived = null;
         *  while (messageReceived == null)
         *  {
         *      messageReceived = (OscMessage)listener.Receive();
         *      Thread.Sleep(1);
         *  }
         *  label1.Text = "Received a message!";
         *  MessageBox.Show("Received a message!");
         *
         * }
         */


        public void Form1_Load(object sender, EventArgs e)
        {
            Run = true;
            //t = new System.Threading.Thread(DoThisAllTheTime);
            //t.Start();

            //Clear labels.
            label1.Invoke((MethodInvoker)(() => label1.Text = ""));
            label_single.Invoke((MethodInvoker)(() => label_single.Text = ""));
            label_x.Invoke((MethodInvoker)(() => label_x.Text = ""));
            label_y.Invoke((MethodInvoker)(() => label_y.Text = ""));
            label_status.Invoke((MethodInvoker)(() => label_status.Text = ""));


            InitTimer();

            HandleOscPacket callback = delegate(OscPacket packet)
            {
                //Console.WriteLine("oscPacket");
                var messageReceived = (OscMessage)packet;
                if (messageReceived == null)
                {
                    return;
                }

                if (messageReceived.Address != null)
                {
                    Console.WriteLine(messageReceived.Address);
                    label1.Invoke((MethodInvoker)(() => label1.Text = messageReceived.Address));

                    string[] addressParts = messageReceived.Address.Split('/');

                    Dictionary <string, float> msgVars = new Dictionary <string, float>();



                    //Console.WriteLine(addressParts[1]);

                    if (messageReceived.Address.Contains("/z") || messageReceived.Address.Contains("nvm"))
                    {
                        //label_status.Invoke((MethodInvoker)(() => label_status.Text = "end string, no action"));
                        return;
                    }
                    else if (messageReceived.Address.Contains("keyboard"))//remote program calls
                    {
                        //Console.WriteLine("keyboard");
                        //Console.WriteLine(addressParts[2]);
                        SendKeys.SendWait(addressParts[2]);
                        return;
                    }
                    else if (messageReceived.Address.Contains("osc"))//remote program calls
                    {
                        //label_status.Invoke((MethodInvoker)(() => label_status.Text = "end string, no action"));
                        //Console.WriteLine("osc command");
                        switch (addressParts[2])
                        {
                        case "sync":
                            //Console.WriteLine("osc sync");
                            //Form1.invoke((MethodInvoker)(Sync()));
                            this.Invoke((MethodInvoker) delegate { Sync(); });
                            break;
                        }

                        return;
                    }
                    else if (addressParts.Count() < 4)
                    {
                        return;
                    }
                    else
                    {
                        //Console.WriteLine(addressParts[1]);
                        switch (addressParts[1])
                        {
                        case "Slider":
                            addressParts[1] = "Strip";
                            break;

                        case "keyboard":
                            Console.WriteLine("keyboard");
                            Console.WriteLine(addressParts[2]);
                            SendKeys.SendWait(addressParts[2]);
                            break;
                        }
                        //Console.WriteLine(messageReceived.Arguments.Count.ToString());
                        //label_status.Invoke((MethodInvoker)(() => label_status.Text = messageReceived.Arguments.Count.ToString()));

                        switch (addressParts[3])
                        {
                        case "fxy":
                            if (messageReceived.Arguments.Count == 2)
                            {
                                label_single.Invoke((MethodInvoker)(() => label_single.Text = ""));

                                msgVars.Add("fx_x", (float)messageReceived.Arguments[1]);
                                label_x.Invoke((MethodInvoker)(() => label_x.Text = ((float)messageReceived.Arguments[1] - (float)0.5).ToString()));

                                msgVars.Add("fx_y", ConvertRange((float)-0.5, (float)0.5, (float)0, (float)1, (float)messageReceived.Arguments[0]));
                                label_y.Invoke((MethodInvoker)(() => label_y.Text = messageReceived.Arguments[0].ToString()));
                            }
                            else
                            {
                                msgVars.Add("fx_x", (float)0);
                                msgVars.Add("fx_y", (float)0);
                            }
                            break;

                        case "Color": label_single.Invoke((MethodInvoker)(() => label_single.Text = ""));
                            if (messageReceived.Arguments.Count == 2)
                            {
                                label_single.Invoke((MethodInvoker)(() => label_single.Text = ""));

                                msgVars.Add(addressParts[3] + "_x", (float)messageReceived.Arguments[1]);
                                label_x.Invoke((MethodInvoker)(() => label_x.Text = ((float)messageReceived.Arguments[1]).ToString()));

                                if (Convert.ToInt32(addressParts[2]) > 4)
                                {
                                    msgVars.Add(addressParts[3] + "_y", (float)messageReceived.Arguments[0] - (float)1);
                                    label_y.Invoke((MethodInvoker)(() => label_y.Text = messageReceived.Arguments[0].ToString()));
                                }
                                else
                                {
                                    msgVars.Add(addressParts[3] + "_y", ConvertRange((float)-0.5, (float)0.5, (float)0, (float)1, (float)messageReceived.Arguments[0]));
                                    label_y.Invoke((MethodInvoker)(() => label_y.Text = ((float)messageReceived.Arguments[0]).ToString()));
                                }
                            }
                            else
                            {
                                msgVars.Add(addressParts[3] + "_x", (float)0);
                                msgVars.Add(addressParts[3] + "_y", (float)0);
                            }
                            break;

                        case "Pan":
                            if (messageReceived.Arguments.Count == 2)
                            {
                                label_single.Invoke((MethodInvoker)(() => label_single.Text = ""));


                                if (addressParts[2] == "5" || addressParts[2] == "6" || addressParts[2] == "7")
                                {
                                    //Console.WriteLine("5, 6, OR 7!!!!!!!! "+ ConvertRange((float)-1, (float)1, (float)-0.5, (float)0.5, (float)messageReceived.Arguments[1]).ToString() +" -- " + ConvertRange((float)-1, (float)1, (float)-0.5, (float)0.5, (float)messageReceived.Arguments[0]).ToString());
                                    msgVars.Add(addressParts[3] + "_x", ConvertRange((float)-1, (float)1, (float)-0.5, (float)0.5, (float)messageReceived.Arguments[1]));
                                    label_x.Invoke((MethodInvoker)(() => label_x.Text = ((float)messageReceived.Arguments[1]).ToString()));
                                    msgVars.Add(addressParts[3] + "_y", ConvertRange((float)-1, (float)1, (float)-0.5, (float)0.5, (float)messageReceived.Arguments[0]));
                                    label_y.Invoke((MethodInvoker)(() => label_y.Text = messageReceived.Arguments[0].ToString()));
                                }
                                else
                                {
                                    Console.WriteLine("pan");
                                    msgVars.Add(addressParts[3] + "_x", (float)messageReceived.Arguments[1]);
                                    //msgVars.Add(addressParts[3] + "_x", ConvertRange((float)-0.5, (float)0.5, (float)0, (float)1, (float)messageReceived.Arguments[1]));
                                    label_x.Invoke((MethodInvoker)(() => label_x.Text = ((float)messageReceived.Arguments[1] - (float)0.5).ToString()));
                                    //msgVars.Add(addressParts[3] + "_y", (float)messageReceived.Arguments[0] );
                                    msgVars.Add(addressParts[3] + "_y", ConvertRange((float)-0.5, (float)0.5, (float)0, (float)1, (float)messageReceived.Arguments[0]));
                                    label_y.Invoke((MethodInvoker)(() => label_y.Text = messageReceived.Arguments[0].ToString()));
                                }
                            }
                            else
                            {
                                msgVars.Add(addressParts[3] + "_x", (float)0);
                                msgVars.Add(addressParts[3] + "_y", (float)0);
                            }
                            break;

                        default:
                            msgVars.Add(addressParts[3], (float)messageReceived.Arguments[0]);
                            label_single.Invoke((MethodInvoker)(() => label_single.Text = messageReceived.Arguments[0].ToString()));

                            label_x.Invoke((MethodInvoker)(() => label_x.Text = ""));
                            label_y.Invoke((MethodInvoker)(() => label_y.Text = ""));

                            break;
                        }

                        if (messageReceived.Address.Contains("reset") || messageReceived.Address.Contains("Reset"))
                        {
                            //Console.WriteLine("RESET!");
                            foreach (KeyValuePair <string, float> entry in msgVars)
                            {
                                //Console.WriteLine(entry.Key.ToString() + " - " + entry.Value.ToString());
                                vm.SetParam(addressParts[1] + "[" + addressParts[2] + "]." + entry.Key, (float)0);
                            }

                            var message = new SharpOSC.OscMessage("/" + addressParts[1] + "/" + addressParts[2] + "/" + addressParts[3], (float)0, (float)0.5);

                            if (addressParts[2] == "5" || addressParts[2] == "6" || addressParts[2] == "7")
                            {
                                message = new SharpOSC.OscMessage("/" + addressParts[1] + "/" + addressParts[2] + "/" + addressParts[3], (float)0, (float)0);
                            }


                            oscSender.Send(message);

                            if (addressParts[1] == "Strip")
                            {
                                if (addressParts[2] == "5" || addressParts[2] == "6" || addressParts[2] == "7")
                                {
                                    message = new SharpOSC.OscMessage("/Slider/" + addressParts[2] + "/" + addressParts[3], (float)0, (float)0);
                                }
                                else
                                {
                                    message = new SharpOSC.OscMessage("/Slider/" + addressParts[2] + "/" + addressParts[3], (float)-0.5, (float)0);
                                }
                                oscSender.Send(message);
                            }
                        }
                        else
                        {
                            // float tmpFloat = 0;
                            foreach (KeyValuePair <string, float> entry in msgVars)
                            {
                                //Console.WriteLine(entry.Key.ToString() + " - " + entry.Value.ToString());
                                //   tmpFloat = (float)entry.Value;
                                vm.SetParam(addressParts[1] + "[" + addressParts[2] + "]." + entry.Key, (float)entry.Value);
                                //var message = new SharpOSC.OscMessage(messageReceived.Address, (float)entry.Value);
                                //oscSender.Send(new SharpOSC.OscMessage(messageReceived.Address, (float)entry.Value));
                                //message = new SharpOSC.OscMessage(messageReceived.Address + "/Text", (float)entry.Value);
                                //oscSender.Send(new SharpOSC.OscMessage(messageReceived.Address + "/Text", (float)entry.Value));
                            }
                        }
                    }

                    /*
                     * if (messageReceived.Address.Contains("nvm"))
                     * {
                     *   //don't do anything
                     * }
                     * else if (messageReceived.Address.Contains("Color"))
                     * {
                     *  vm.SetParam(addressParts[1] + "[" + addressParts[2] + "]." + addressParts[3] + "_y", (float)messageReceived.Arguments[0]);
                     *  vm.SetParam(addressParts[1] + "[" + addressParts[2] + "]." + addressParts[3] + "_x", (float)messageReceived.Arguments[1] - (float)0.5);
                     *  label_status.Invoke((MethodInvoker)(() => label_status.Text = messageReceived.Arguments[0].ToString() + " - " + messageReceived.Arguments[0].ToString()));
                     * }
                     * else
                     * {
                     *   if (messageReceived.Address.Contains("reset"))
                     *   {
                     *       vm.SetParam(addressParts[1]+"[" + addressParts[2] + "]." + addressParts[3] , 0);
                     *   }
                     *   else
                     *   {
                     *       foreach (float test in messageReceived.Arguments)
                     *       {
                     *           //label_status.Invoke((MethodInvoker)(() => label_status.Text = test.ToString()));
                     *           label_status.Invoke((MethodInvoker)(() => label_status.Text = addressParts[1] + "[" + addressParts[2] + "]." + addressParts[3]));
                     *           vm.SetParam(addressParts[1] + "[" + addressParts[2] + "]." + addressParts[3], test);
                     *       }
                     *   }
                     *
                     * }
                     */
                }

                return;
            };


            var listener = new UDPListener(Properties.Settings.Default.portIn, callback);
            //MessageBox.Show("Starting OSC Listener");
        }
Ejemplo n.º 30
0
        public static string receiveMsg(NetworkStream stream, TcpClient tcpClient, UDPSender sender)
        {
            string msgReceived = "";

            // Create a byte array for the available bytes
            byte[] arrayBytesRequest = new byte[tcpClient.Available];
            // Read the bytes from the stream
            int nRead = stream.Read(arrayBytesRequest, 0, arrayBytesRequest.Length);

            if (nRead > 0)
            {
                // Convert the byte array into a string
                string sMsgRequest = ASCIIEncoding.ASCII.GetString(arrayBytesRequest);
                Console.WriteLine("Msg from Robot: " + sMsgRequest);
                string sMsgAnswer = string.Empty;

                // set the key for the key/value pairs
                string key = "";
                if (sMsgRequest.StartsWith("world"))
                    key = "hello";
                else if (sMsgRequest.StartsWith("p"))
                    key = "target";
                else if (sMsgRequest.StartsWith("["))
                    key = "joints";
                else if (sMsgRequest.StartsWith("SET force"))
                    key = "force";
                else if (sMsgRequest.StartsWith("SET tcp force"))
                    key = "tcp force";

                // set the value for the key/value pairs
                if (key.Equals("hello"))
                {
                    Console.WriteLine("Going to home position: hello " + sMsgRequest + "!");
                    // go to home position

                    msgReceived = "going home";
                }
                else if (key.Equals("target"))
                {
                    int start = 2;
                    msgReceived = sMsgRequest.Substring(2, sMsgRequest.Length - 1 - start);

                    string[] coords = msgReceived.Split(',');
                    if (coords.Length == 6)
                    {
                        float x = float.Parse(coords[0]);
                        float y = float.Parse(coords[1]);
                        float z = float.Parse(coords[2]);
                        float rx = float.Parse(coords[3]);
                        float ry = float.Parse(coords[4]);
                        float rz = float.Parse(coords[5]);

                        pose[0] = x;
                        pose[1] = y;
                        pose[2] = z;
                        pose[3] = rx;
                        pose[4] = ry;
                        pose[5] = rz;

                        // send pose over OSC
                        String[] msg = new String[6];
                        msg[0] = "x: " + pose[0];
                        msg[1] = "y: " + pose[1];
                        msg[2] = "z: " + pose[2];
                        msg[3] = "rx: " + pose[3];
                        msg[4] = "ry: " + pose[4];
                        msg[5] = "rz: " + pose[5];
                        var message = new SharpOSC.OscMessage("/pose", msg);
                        sender.Send(message);

                        Console.WriteLine("Robot Pose:  [" + x + ", " + y + ", " + z + ", " + rx + ", " + ry + ", " + rz + "]");
                    }
                    else
                    {
                        msgReceived = "WTF: " + sMsgRequest;
                    }
                }
                else if (key.Equals("joints"))
                {
                    Console.WriteLine("Parsing joint pose: " + sMsgRequest);
                    int start = 1;
                    msgReceived = sMsgRequest.Substring(start, sMsgRequest.Length - 1 - start);

                    string[] coords = msgReceived.Split(',');
                    if (coords.Length == 6)
                    {
                        float x = float.Parse(coords[0]);
                        float y = float.Parse(coords[1]);
                        float z = float.Parse(coords[2]);
                        float rx = float.Parse(coords[3]);
                        float ry = float.Parse(coords[4]);
                        float rz = float.Parse(coords[5]);

                        joints[0] = x;
                        joints[1] = y;
                        joints[2] = z;
                        joints[3] = rx;
                        joints[4] = ry;
                        joints[5] = rz;

                        // send joints over OSC
                        String[] msg = new String[6];
                        msg[0] = "base: " + pose[0];
                        msg[1] = "shoulder: " + pose[1];
                        msg[2] = "elbow: " + pose[2];
                        msg[3] = "wrist 1: " + pose[3];
                        msg[4] = "wrist 2: " + pose[4];
                        msg[5] = "wrist 3: " + pose[5];
                        var message = new SharpOSC.OscMessage("/joints", msg);
                        sender.Send(message);

                        Console.WriteLine("Robot Joint Positions: [" + x + ", " + y + ", " + z + ", " + rx + ", " + ry + ", " + rz + "]");
                    }
                    else
                    {
                        msgReceived = "WTF: " + sMsgRequest;
                    }
                }
                else if (key.Equals("force"))
                {
                    Console.WriteLine("Parsing pose: " + sMsgRequest);
                    int start = key.Length + 5;
                    msgReceived = sMsgRequest.Substring(start, sMsgRequest.Length - 1 - start);

                    force = float.Parse(msgReceived);

                    // send force over OSC
                    var message = new SharpOSC.OscMessage("/force", force);
                    sender.Send(message);

                    Console.WriteLine("Robot Force: {" + force + "}");
                }
                else if (key.Equals("tcp force"))
                {
                    Console.WriteLine("Parsing pose: " + sMsgRequest);
                    int start = key.Length + 5;
                    msgReceived = sMsgRequest.Substring(start, sMsgRequest.Length - 1 - start);

                    tcpForce = float.Parse(msgReceived);

                    // send TCP force over OSC
                    var message = new SharpOSC.OscMessage("/TCPforce", tcpForce);
                    sender.Send(message);

                    Console.WriteLine("Robot TCP Force: {" + tcpForce + "}");
                }
                else
                {
                    // unkown command
                    msgReceived = sMsgRequest;
                    ///sendMsg(stream, "unknown command sent to robot: " + sMsgRequest);
                }

            }
            else if (tcpClient.Available == 0)
            {
                Console.WriteLine("Client closed the connection.");
                // No bytes read, and no bytes available, the client is closed.
                stream.Close();
            }

            return msgReceived;
        }
Ejemplo n.º 31
0
        static OscMessage buildMessageFromPoint(Point p)
        {
            OscMessage message = new SharpOSC.OscMessage("/wek/inputs", (float)p.x, (float)p.y);

            return(message);
        }
Ejemplo n.º 32
0
    public static void SendNoteOn(string noteNumber)
    {
        var message = new SharpOSC.OscMessage("/something/note_on", noteNumber);

        sender.Send(message);
    }
Ejemplo n.º 33
0
        /// <summary>
        /// Update the spreadsheet.  
        /// Note: This refresh is quite slow and provided here only as a complete example. 
        /// In a production setting this would be optimized.
        /// </summary>
        private static void UpdateData()
        {
            // update MarkerSet data
            for (int i = 0; i < m_FrameOfData.nMarkerSets; i++)
            {
                NatNetML.MarkerSetData ms = m_FrameOfData.MarkerSets[i];
                //for (int j = 0; j < ms.nMarkers; j++)
                //{

                //}
            }

            // update RigidBody data
            Console.WriteLine("RigidBody count: " + m_FrameOfData.nRigidBodies);
            for (int i = 0; i < m_FrameOfData.nRigidBodies; i++)
            {
                NatNetML.RigidBodyData rb = m_FrameOfData.RigidBodies[i];

                // update RigidBody data

                bool tracked = rb.Tracked;
                if (!tracked)
                {
                    //Console.WriteLine("RigidBody not tracked in this frame.");
                }

                ////////////////////////////////////////////////////////////
                // poop

                // send rigid body & markers over OSC
                // may not be fast enough?

                String[] msg = new String[8];
                msg[0] = "Rigid Body: " + rb.ID;
                msg[1] = "x: " + rb.x * 1000;
                msg[2] = "y: " + rb.y * 1000;
                msg[3] = "z: " + rb.z * 1000;
                msg[4] = "qx: " + rb.qx;
                msg[5] = "qy: " + rb.qy;
                msg[6] = "qz: " + rb.qz;
                msg[7] = "qz: " + rb.qw;

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

                // print out to console
                for (int j = 0; j < 8; j++)
                {
                    if (j == 0)
                        Console.WriteLine(msg[j]+":");
                    else
                        Console.WriteLine("     "+msg[j]);
                }

                int count = rb.nMarkers;
                msg = new String[count];
                for (int j = 0; j < count; j++)
                {
                    if (rb.Markers[j] != null)
                        msg[j] = "Rigid Body " + rb.ID + ", Marker " + rb.Markers[j].ID + ": {" + rb.Markers[j].x + "," + rb.Markers[j].y + "," + rb.Markers[j].z + "}";
                }

                sender.Send(new SharpOSC.OscMessage("/marker", msg));

                // print out to console
                for (int j = 0; j < count; j++)
                {
                    if (j == 0)
                        Console.WriteLine(msg[j] + ":");
                    else
                        Console.WriteLine("     " + msg[j]);
                }

                ////////////////////////////////////////////////////////////

                // update Marker data associated with this rigid body
                for (int j = 0; j < rb.nMarkers; j++)
                {
                    if (rb.Markers[j].ID != -1)
                    {
                        RigidBody rbDef = FindRB(rb.ID);
                        if (rbDef != null)
                        {
                            String strUniqueName = rbDef.Name + "-" + rb.Markers[j].ID.ToString();
                            int keyMarker = strUniqueName.GetHashCode();

                            NatNetML.Marker m = rb.Markers[j];

                        }
                    }
                }

            }

            // update Skeleton data
            //for (int i = 0; i < m_FrameOfData.nSkeletons; i++)
            //{
            //    NatNetML.SkeletonData sk = m_FrameOfData.Skeletons[i];
            //    for (int j = 0; j < sk.nRigidBodies; j++)
            //    {
            //        // note : skeleton rigid body ids are of the form:
            //        // parent skeleton ID   : high word (upper 16 bits of int)
            //        // rigid body id        : low word  (lower 16 bits of int)
            //        NatNetML.RigidBodyData rb = sk.RigidBodies[j];
            //        int skeletonID = HighWord(rb.ID);
            //        int rigidBodyID = LowWord(rb.ID);
            //        int uniqueID = skeletonID * 1000 + rigidBodyID;
            //        int key = uniqueID.GetHashCode();
            //        if (htRigidBodies.ContainsKey(key))
            //        {
            //            int rowIndex = (int)htRigidBodies[key];
            //            if (rowIndex >= 0)
            //            {
            //                dataGridView1.Rows[rowIndex].Cells[1].Value = rb.x;
            //                dataGridView1.Rows[rowIndex].Cells[2].Value = rb.y;
            //                dataGridView1.Rows[rowIndex].Cells[3].Value = rb.z;

            //                // Convert quaternion to eulers.  Motive coordinate conventions: X(Pitch), Y(Yaw), Z(Roll), Relative, RHS
            //                float[] quat = new float[4] { rb.qx, rb.qy, rb.qz, rb.qw };
            //                float[] eulers = new float[3];
            //                eulers = m_NatNet.QuatToEuler(quat, (int)NATEulerOrder.NAT_XYZr);
            //                double x = RadiansToDegrees(eulers[0]);     // convert to degrees
            //                double y = RadiansToDegrees(eulers[1]);
            //                double z = RadiansToDegrees(eulers[2]);

            //                dataGridView1.Rows[rowIndex].Cells[4].Value = x;
            //                dataGridView1.Rows[rowIndex].Cells[5].Value = y;
            //                dataGridView1.Rows[rowIndex].Cells[6].Value = z;

            //                // Marker data associated with this rigid body
            //                for (int k = 0; k < rb.nMarkers; k++)
            //                {

            //                }
            //            }
            //        }
            //    }
            //}   // end skeleton update

            //// update labeled markers data
            //// remove previous dynamic marker list
            //// for testing only - this simple approach to grid updating too slow for large marker count use
            //int labeledCount = 0;
            //if (false)
            //{

            //    for (int i = 0; i < m_FrameOfData.nMarkers; i++)
            //    {
            //        NatNetML.Marker m = m_FrameOfData.LabeledMarkers[i];

            //        int modelID, markerID;
            //        m_NatNet.DecodeID(m.ID, out modelID, out markerID);
            //        string name = "Labeled Marker (ModelID: " + modelID + "  MarkerID: " + markerID + ")";
            //        if (modelID == 0)
            //            name = "UnLabeled Marker ( ID: " + markerID + ")";

            //        labeledCount++;
            //    }
            //}
        }
Ejemplo n.º 34
0
    public static void SendPitchWheel(int value)
    {
        var message = new SharpOSC.OscMessage("/something/pitch_wheel", value);

        sender.Send(message);
    }
Ejemplo n.º 35
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        Debug.Log("Frame Id: " + frame.Id);
        frameCount++;

        HandList hands = frame.Hands;

        for (int i = 0; i < hands.Count; i++)
        {
            Hand        hand         = hands[i];
            Leap.Vector direction    = hand.Direction;
            Leap.Vector palmNormal   = hand.PalmNormal;
            Leap.Vector palmPosition = hand.PalmPosition;
            Leap.Vector handSpeed    = hand.PalmVelocity;


            if (i == 0)
            {
                fdistanceDirection    = direction.DistanceTo(fprevDirection);
                fdistancePalmPosition = palmPosition.DistanceTo(fprevPalmPosition);
                fdistancePalmNormal   = palmNormal.DistanceTo(fprevPalmNormal);
                fdistanceHandVelocity = handSpeed.DistanceTo(fprevHandVelocity);

                fprevDirection    = direction;
                fprevPalmNormal   = palmNormal;
                fprevPalmPosition = palmPosition;
                fprevHandVelocity = handSpeed;
            }
            else if (i == 1)
            {
                sdistanceDirection    = direction.DistanceTo(sprevDirection);
                sdistancePalmPosition = palmPosition.DistanceTo(sprevPalmPosition);
                sdistancePalmNormal   = palmNormal.DistanceTo(sprevPalmNormal);
                sdistanceHandVelocity = handSpeed.DistanceTo(sprevHandVelocity);

                sprevDirection    = direction;
                sprevPalmNormal   = palmNormal;
                sprevPalmPosition = palmPosition;
                sprevHandVelocity = handSpeed;

                Debug.Log("first direction " + fdistanceDirection);
                Debug.Log("second direction " + sdistanceDirection);

                Debug.Log("Direction change = " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("");
                directionFile.WriteLine("frame id: " + frame.Id);
                directionFile.WriteLine("Direction first: " + fdistanceDirection + " second: " + sdistanceDirection + " diff: " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("PalmPosition first: " + fdistancePalmPosition + " second: " + sdistancePalmPosition + " diff: " + (fdistancePalmPosition - sdistancePalmPosition));
                directionFile.WriteLine("PalmNormal first: " + fdistancePalmNormal + " second: " + sdistancePalmNormal + " diff: " + (fdistancePalmNormal - sdistancePalmNormal));
                directionFile.WriteLine("Velocity first: " + fdistanceHandVelocity + " second: " + sdistanceHandVelocity + " diff: " + (fdistanceHandVelocity - sdistanceHandVelocity));

                directionFile.WriteLine("");
                float directionChange    = (fdistanceDirection - sdistanceDirection);
                float palmPositionChange = fdistancePalmPosition - sdistancePalmPosition;
                float palmNormalChange   = fdistancePalmNormal - sdistancePalmNormal;
                float velocityChange     = fdistanceHandVelocity - sdistanceHandVelocity;

                if (directionChange < 0.0f)
                {
                    directionChange *= -1.0f;
                }
                if (palmPositionChange < 0.0f)
                {
                    palmPositionChange *= -1.0f;
                }
                if (palmNormalChange < 0.0f)
                {
                    palmNormalChange *= -1.0f;
                }
                if (velocityChange < 0.0f)
                {
                    velocityChange *= -1.0f;
                }

                totalDistance     += directionChange;
                totalPalmPosition += palmPositionChange;
                totalPalmNormal   += palmNormalChange;
                totalVelocity     += velocityChange;
                test_status        = "Status:\n";
                if (directionChange < 0.001)
                {
                    test_status += "Direction OK\n";
                }
                else
                {
                    test_status += "Fix Direction\n";
                }

                if (palmPositionChange < 1.0)
                {
                    test_status += "PalmPosition OK\n";
                }
                else
                {
                    test_status += "Fix PalmPosition\n";
                }

                if (palmNormalChange < 1.0)
                {
                    test_status += "PalmNormal OK\n";
                }
                else
                {
                    test_status += "Fix PalmNormal\n";
                }

                if (velocityChange < 1.0)
                {
                    test_status += "Velocity OK\n";
                }
                else
                {
                    test_status += "Fix Velocity\n";
                }

                float error = totalDistance * 2.0f + totalPalmNormal * 2.0f + totalVelocity + totalPalmPosition * 3.0f;
                error /= (4 * frameCount);

                var message = new SharpOSC.OscMessage("/hand/1", error);
                var sender  = new SharpOSC.UDPSender("127.0.0.1", 55555);
                sender.Send(message);

                if (error > 5.0)
                {
                    status_text.color = Color.red;
                    test_status      += "Not matching";
                    //source.PlayOneShot(buzzSound);
                }
                else
                {
                    status_text.color = Color.green;
                    test_status      += "Matching";
                    //source.PlayOneShot(matchSound);
                }


                status_text.text = test_status;
            }
        }
    }
Ejemplo n.º 36
0
 private void TransmitData(VideoPacket packet)
 {
     var message = new OscMessage("/test/1", ObjectToString(packet));
     var udpSender = new UDPSender("127.0.0.1", 55555);
     udpSender.Send(message);
 }
Ejemplo n.º 37
0
        private void CaptureProcess()
        {
            Sender = new UDPSender(CurrentIpAdress, Convert.ToInt32(currentPort));
            while (senseManager.AcquireFrame(true).IsSuccessful())
            {
                PXCMCapture.Sample  sample = senseManager.QuerySample();
                PXCMImage.ImageData colorImageData;
                Bitmap colorBitmap;

                sample.color.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out colorImageData);
                colorBitmap = colorImageData.ToBitmap(0, sample.color.info.width, sample.color.info.height);

                if (faceModule != null)
                {
                    PXCMFaceData faceData = faceModule.CreateOutput();
                    faceData.Update();
                    numberTrackedFace = faceData.QueryNumberOfDetectedFaces();

                    PXCMFaceData.Face faceDataFace = faceData.QueryFaceByIndex(0);

                    if (faceDataFace != null)
                    {
                        PXCMFaceData.DetectionData faceDetectionData = faceDataFace.QueryDetection();
                        PXCMFaceData.LandmarksData landMarksData     = faceDataFace.QueryLandmarks();


                        if (faceDetectionData != null) //Запись переменных нахождения фейса
                        {
                            PXCMRectI32 faceRectangle;
                            faceDetectionData.QueryFaceAverageDepth(out faceAverageDepth);
                            faceDetectionData.QueryBoundingRect(out faceRectangle);
                            faceRectangleHeight = faceRectangle.h;
                            faceRectangleWidth  = faceRectangle.w;
                            faceRectangleX      = faceRectangle.x;
                            faceRectangleY      = faceRectangle.y;

                            PXCMFaceData.LandmarkPoint[] points; //Херачим точки на фейс
                            if (landMarksData != null)
                            {
                                bool res = landMarksData.QueryPoints(out points);

                                Graphics graphics = Graphics.FromImage(colorBitmap);
                                Font     font     = new Font(System.Drawing.FontFamily.GenericMonospace, 12, System.Drawing.FontStyle.Bold);

                                foreach (PXCMFaceData.LandmarkPoint landmark in points)
                                {
                                    point.X = landmark.image.x + LandMarkAlingment;
                                    point.Y = landmark.image.y + LandMarkAlingment;
                                    //Console.WriteLine(point.X);

                                    if (landmark.confidenceImage == 0)
                                    {
                                        graphics.DrawString("X", font, System.Drawing.Brushes.Brown, point);
                                    }
                                    else
                                    {
                                        graphics.DrawString("*", font, System.Drawing.Brushes.CornflowerBlue, point);
                                    }
                                    Connect = Math.Min(landmark.confidenceImage, 1);
                                }
                            }
                        }

                        var connectMessage = new SharpOSC.OscMessage("/expressions/connectMessage", Connect);
                        Sender.Send(connectMessage);

                        PXCMFaceData.PoseData facePoseData = faceDataFace.QueryPose(); //переменные поворота для анимации головы
                        if (facePoseData != null)
                        {
                            PXCMFaceData.PoseEulerAngles headAngles;
                            facePoseData.QueryPoseAngles(out headAngles);
                            headRoll  = headAngles.roll;
                            headYaw   = headAngles.yaw;
                            headPitch = headAngles.pitch;
                        }

                        PXCMFaceData.ExpressionsData expressionData = faceDataFace.QueryExpressions();

                        if (expressionData != null)
                        {
                            PXCMFaceData.ExpressionsData.FaceExpressionResult score;

                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_KISS, out score);
                            Dispatcher.Invoke(() => kissExpression.Text = Convert.ToString(score.intensity));
                            var kissMessage = new SharpOSC.OscMessage("/expressions/kiss", score.intensity);
                            Sender.Send(kissMessage);

                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_MOUTH_OPEN, out score);
                            Dispatcher.Invoke(() => mouthExpression.Text = Convert.ToString(score.intensity));
                            var mouthMessage = new SharpOSC.OscMessage("/expressions/mouth", score.intensity);
                            Sender.Send(mouthMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_SMILE, out score);
                            Dispatcher.Invoke(() => smileExpression.Text = Convert.ToString(score.intensity));
                            var smileMessage = new SharpOSC.OscMessage("/expressions/smile", score.intensity);
                            Sender.Send(smileMessage);

                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_TONGUE_OUT, out score);
                            Dispatcher.Invoke(() => tongueExpression.Text = Convert.ToString(score.intensity));
                            var tongueOutMessage = new SharpOSC.OscMessage("/expressions/tongueout", score.intensity);
                            Sender.Send(tongueOutMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_BROW_LOWERER_LEFT, out score);
                            Dispatcher.Invoke(() => leftBrowLowExpression.Text = Convert.ToString(score.intensity));
                            var leftBrowLowMessage = new SharpOSC.OscMessage("/expressions/leftBrowLow", score.intensity);
                            Sender.Send(leftBrowLowMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_BROW_LOWERER_RIGHT, out score);
                            Dispatcher.Invoke(() => rightBrowLowExpression.Text = Convert.ToString(score.intensity));
                            var rightBrowLowMessage = new SharpOSC.OscMessage("/expressions/rightBrowLow", score.intensity);
                            Sender.Send(rightBrowLowMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_BROW_RAISER_LEFT, out score);
                            Dispatcher.Invoke(() => leftBrowRaiseExpression.Text = Convert.ToString(score.intensity));
                            var leftBrowRaiseMessage = new SharpOSC.OscMessage("/expressions/leftBrowRaise", score.intensity);
                            Sender.Send(leftBrowRaiseMessage);

                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_BROW_RAISER_RIGHT, out score);
                            Dispatcher.Invoke(() => rightBrowRaiseExpression.Text = Convert.ToString(score.intensity));
                            var rightBrowRaiseMessage = new SharpOSC.OscMessage("/expressions/rightBrowRaise", score.intensity);
                            Sender.Send(rightBrowRaiseMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_CLOSED_LEFT, out score);
                            Dispatcher.Invoke(() => leftEyeClosedExpression.Text = Convert.ToString(score.intensity));
                            var leftEyeClosedMessage = new SharpOSC.OscMessage("/expressions/leftEyeClosed", score.intensity);
                            Sender.Send(leftEyeClosedMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_CLOSED_RIGHT, out score);
                            Dispatcher.Invoke(() => rightEyeClosedExpression.Text = Convert.ToString(score.intensity));
                            var rightEyeClosedMessage = new SharpOSC.OscMessage("/expressions/rightEyeClosed", score.intensity);
                            Sender.Send(rightEyeClosedMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_TURN_LEFT, out score);
                            Dispatcher.Invoke(() => eyesTurnLeftExpression.Text = Convert.ToString(score.intensity));
                            var eyesTurnLeftMessage = new SharpOSC.OscMessage("/expressions/eyesTurnLeft", score.intensity);
                            Sender.Send(eyesTurnLeftMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_TURN_RIGHT, out score);
                            Dispatcher.Invoke(() => eyesTurnRightExpression.Text = Convert.ToString(score.intensity));
                            var eyesTurnRightMessage = new SharpOSC.OscMessage("/expressions/eyesTurnRight", score.intensity);
                            Sender.Send(eyesTurnRightMessage);



                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_DOWN, out score);
                            Dispatcher.Invoke(() => eyesDownExpression.Text = Convert.ToString(score.intensity));
                            var eyesDownMessage = new SharpOSC.OscMessage("/expressions/eyesDown", score.intensity);
                            Sender.Send(eyesDownMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_UP, out score);
                            Dispatcher.Invoke(() => eyesUpExpression.Text = Convert.ToString(score.intensity));
                            var eyesUpMessage = new SharpOSC.OscMessage("/expressions/eyesUp", score.intensity);
                            Sender.Send(eyesUpMessage);


                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_PUFF_LEFT, out score);
                            Dispatcher.Invoke(() => puffLeftExpression.Text = Convert.ToString(score.intensity));
                            var leftPuffMessage = new SharpOSC.OscMessage("/expressions/leftPuff", score.intensity);
                            Sender.Send(leftPuffMessage);



                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_PUFF_RIGHT, out score);
                            Dispatcher.Invoke(() => puffRightExpression.Text = Convert.ToString(score.intensity));
                            var rightPuffMessage = new SharpOSC.OscMessage("/expressions/rightPuff", score.intensity);
                            Sender.Send(rightPuffMessage);
                        }
                    }
                    faceData.Dispose();
                }
                UpdateUI(colorBitmap);

                colorBitmap.Dispose();
                sample.color.ReleaseAccess(colorImageData);
                senseManager.ReleaseFrame();
            }
        }