Exemple #1
0
 public void ConsumeGesture(Gesture gesture)
 {
     //Console.WriteLine("gesture consumed!");
     SensorData sensor = null;
     foreach (SensorData s in gesture.DataSinceGestureStart.ReverseIterate())
     {
         sensor = s;
         break;
     }
     if (sensor == null)
         return;
     //Console.WriteLine(gesture.State);
     //Console.WriteLine(sensor.FingerCount());
     //if (gesture.State != GestureGenerator.State.FIVEFINGERS)
     //    return;
     if (sensor.FingerCount() != 4)
         return;
     Color color = sensor.getColorFromFingers();
     Console.WriteLine(color);
     Vector3 indexFinger = sensor.indexFinger();
     Console.WriteLine(indexFinger.Z);
     int x = (int)(indexFinger.X * bitmap.PixelWidth);
     if (x >= bitmap.PixelWidth)
         x = bitmap.PixelWidth - 1;
     int y = (int)(indexFinger.Y * bitmap.PixelHeight);
     if (y >= bitmap.PixelHeight)
         y = bitmap.PixelHeight - 1;
     y = (bitmap.PixelHeight - 1) - y;
     //Console.WriteLine(x + "," + y);
     bitmap.setPixel(x, y, color);
     //Console.WriteLine("sensor data received!");
     /*
     if (sensor.FingerCount() != 5)
     {
         return;
     }
     */
     /*
     foreach (Vector3 vector in sensor.TouchedFingers())
     {
         //Console.WriteLine(vector.X + "," + vector.Y);
         int x = (int)(vector.X * bitmap.PixelWidth);
         if (x >= bitmap.PixelWidth)
             x = bitmap.PixelWidth - 1;
         int y = (int)(vector.Y * bitmap.PixelHeight);
         if (y >= bitmap.PixelHeight)
             y = bitmap.PixelHeight - 1;
         y = (bitmap.PixelHeight - 1) - y;
         bitmap.setPixel(x, y, Colors.Black);
         Console.WriteLine(x + "," + y);
     }
     */
 }
Exemple #2
0
        public void ConsumeGesture(Gesture g)
        {
            float commitThreshold = .02f;
            SensorData s = g.DataSinceGestureStart.ReverseIterate().FirstOrDefault();
            if (s != null && s.FingerCount() > 0)
            {

                Vector3 fingerCenter = s.TouchedFingers().Aggregate((x, y) => x + y);
                fingerCenter = Vector3.Multiply(fingerCenter, 1.0f / (float)s.TouchedFingers().Length);

                Vector2 meshPointOfContact =
                        mesh.activeAreaStart
                            + Vector2.Multiply(mesh.activeAreaSize, fingerCenter.Xy);
                meshPointOfContact = Mesh.Wrap2D(meshPointOfContact);

                mesh.fingerPoint = meshPointOfContact;
                mesh.fingerDown = true;

                if (this.editMode.mode == ModeSwitcher.EditMode.Add || this.editMode.mode == ModeSwitcher.EditMode.Subtract)
                {
                    //Console.WriteLine(fingerCenter.Z);
                    bool newDrop = (pendingCommit > (fingerCenter.Z + .02) && !didCommit);
                    bool movement = (lastCommitChain - meshPointOfContact).Length > recommitDistance;
                    if (pendingCommit > commitThreshold
                        && (newDrop || movement))
                    {
                        didCommit = newDrop;
                        //Console.WriteLine("leftbottomcorner touched " + s.corners[0]);
                        mesh.Commit();
                        pendingCommit = 0.0f;
                        lastCommitChain = meshPointOfContact;
                        return;
                    }
                    if (fingerCenter.Z > commitThreshold)
                    {
                        //if (!didCommit)
                        {
                            pendingCommit = fingerCenter.Z;
                        }
                    }
                    if (fingerCenter.Z <= commitThreshold)
                    {
                        didCommit = false;
                        pendingCommit = 0.0f;
                        lastCommitChain = new Vector2(100, 100);
                    }
                    float narrowness = 8000;
                    if (s.FingerCount() >= 2)
                    {
                        narrowness = 800f / (float)s.NormedDistance();
                    }

                    updateParameters(meshPointOfContact, fingerCenter.Z, narrowness);
                }
            }
            if (g.EventType == GestureGenerator.EventType.VANISH)
            {
                mesh.ClearUncommitted();
                mesh.fingerDown = false;
            }
        }