Beispiel #1
0
        private bool IsUniqueTitle(string title)
        {
            int count = ToolList.Count(tool => tool.Title == title);

            return(count <= 1);
        }
Beispiel #2
0
        public override void OnFrame(Controller controller)
        {
            //get screens
            screens = controller.CalibratedScreens;

            //calculate fps
            double fps = 1.0 * Stopwatch.Frequency / (stopWatch.ElapsedTicks - lasttime);

            lasttime = stopWatch.ElapsedTicks;

            timeaccum += 1.0 / fps;
            framesaccum++;
            if (timeaccum >= 0.5)
            {
                UpdateText(form.fps_label, "fps: " + Convert.ToString((int)(1.0 * framesaccum / timeaccum)));
                timeaccum  -= 0.5;
                framesaccum = 0;
            }

            bool  wasd = false;
            float scale, yoffset, ws, ad;
            bool  intersect;

            lock (thisLock) //get access to input data
            {
                scale     = (float)form.sens;
                yoffset   = (float)form.yoffset;
                ws        = (float)form.wsval;
                ad        = (float)form.adval;
                intersect = form.intersect;
                wasd      = form.wasd_check.Checked;
            }

            //move phase for keyboard simulation
            phase += par / fps * freq;
            if (phase > 1)
            {
                par   = -1;
                phase = 1;
            }
            if (phase < 0)
            {
                par   = 1;
                phase = 0;
            }

            Pointable point1    = null;
            bool      point1_ok = false;

            // Get the most recent frame
            Frame frame = controller.Frame();

            if (!frame.Tools.Empty)
            {
                //get the nearest tool
                int      nearest    = 0;
                double   nearestval = double.MaxValue;
                ToolList tools      = frame.Tools;
                for (int i = 0; i < tools.Count(); i++)
                {
                    if (tools[i].TipPosition.z < nearestval)
                    {
                        nearest    = i;
                        nearestval = tools[i].TipPosition.z;
                    }
                }
                point1    = tools[nearest];
                point1_ok = true;
            }
            else if (!frame.Hands.Empty)
            {
                // Get the first hand
                Hand hand = frame.Hands[0];

                // Check if the hand has any fingers
                FingerList fingers = hand.Fingers;
                if (!fingers.Empty)
                {
                    //get the finger closest to the screen (smallest z)
                    int    nearest    = 0;
                    double nearestval = double.MaxValue;
                    for (int i = 0; i < fingers.Count(); i++)
                    {
                        if (fingers[i].TipPosition.z < nearestval)
                        {
                            nearest    = i;
                            nearestval = fingers[i].TipPosition.z;
                        }
                    }
                    point1    = fingers[nearest];
                    point1_ok = true;
                }
            }

            if (point1_ok) //there is finger or tool
            {
                PointConverter pc = new PointConverter();
                Point          pt = new Point();

                //wasd not checked
                if (!wasd)
                {
                    //interset/project on screen
                    Vector intersection;
                    if (intersect)
                    {
                        intersection = screens[0].Intersect(point1, true, 4.0f / scale);
                    }
                    else
                    {
                        intersection = screens[0].Project(point1.TipPosition, true, 4.0f / scale);
                    }

                    //scale and offset screen position
                    double scx = (intersection.x - 0.5) * scale + 0.5;
                    double scy = (1 - intersection.y - 0.5) * scale + 0.5 + yoffset;
                    pt.X = (int)(scx * screens[0].WidthPixels);
                    pt.Y = (int)(scy * screens[0].HeightPixels);

                    Cursor.Position = pt;
                }
                //if wasd is checked
                else
                {
                    string str = "";

                    float x = point1.TipPosition.x;
                    float y = point1.TipPosition.y;
                    float z = point1.TipPosition.z;

                    var  hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
                    Hand hand = frame.Hands[0];

                    double xph = -hand.PalmNormal.Roll * ad * 8;                                    //steering using roll
                    double zph = (Math.Abs(hand.PalmPosition.z - 100) - ws * 200.0) / (200.0 * ws); //acceleration using z

                    //stroke or release given keys

                    if (xph > 0 && Math.Abs(xph) > phase)
                    {
                        str += "D";
                        if (!pD || Math.Abs(xph) > 1)
                        {
                            Stroke(0x20);
                        }
                        pD = true;
                    }
                    else
                    {
                        if (pD)
                        {
                            Release(0x20);
                        }
                        pD = false;
                    }
                    if (xph < 0 && Math.Abs(xph) > phase)
                    {
                        str += "A";
                        if (!pA || Math.Abs(xph) > 1)
                        {
                            Stroke(0x1E);
                        }
                        pA = true;
                    }
                    else
                    {
                        if (pA)
                        {
                            Release(0x1E);
                        }
                        pA = false;
                    }

                    if (z > 0 && zph > phase)
                    {
                        str += "S";
                        if (!pS || zph > 1)
                        {
                            Stroke(0x1F);
                        }
                        pS = true;
                    }
                    else
                    {
                        if (pS)
                        {
                            Release(0x1F);
                        }
                        pS = false;
                    }
                    if (z < 0 && zph > phase)
                    {
                        str += "W";
                        if (!pW || zph > 1)
                        {
                            Stroke(0x11);
                        }
                        pW = true;
                    }
                    else
                    {
                        if (pW)
                        {
                            Release(0x11);
                        }
                        pW = false;
                    }

                    UpdateText(form.debug_label, Convert.ToString(str));
                }
            }
            else
            {
                if (pW)
                {
                    Release(0x11);
                }
                if (pA)
                {
                    Release(0x1E);
                }
                if (pS)
                {
                    Release(0x1F);
                }
                if (pD)
                {
                    Release(0x20);
                }
                pW = false;
                pA = false;
                pS = false;
                pD = false;
            }
        }